Skip to content

Commit 28d3cd5

Browse files
author
Paul Davis
committed
Change exception types for resource exhaustion.
Out of memory is now signaled by a MemoryError Too much CPU time is reported as a SystemError I'm going to punt on the issue with specifying memory usage limits on contexts when it really refernces the runtime. I don't see a good way to implement it without quite a bit of work. It'll never be specifiable per context, only the api might change to avoid confusion. [#12 state:resolved]
1 parent e203f17 commit 28d3cd5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

spidermonkey/context.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ branch_cb(JSContext* jscx, JSScript* script)
197197
JS_GC(jscx);
198198
if(jscx->runtime->gcBytes > pycx->max_heap)
199199
{
200+
PyErr_NoMemory();
200201
return JS_FALSE;
201202
}
202203
}
@@ -207,6 +208,7 @@ branch_cb(JSContext* jscx, JSScript* script)
207208
&& pycx->max_time < now - pycx->start_time
208209
)
209210
{
211+
PyErr_SetNone(PyExc_SystemError);
210212
return JS_FALSE;
211213
}
212214

tests/test-context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_get_set_limits(cx):
3939
@t.cx()
4040
def test_exceed_time(cx):
4141
cx.max_time(1)
42-
t.raises(RuntimeError, cx.execute, "while(true) {}")
42+
t.raises(SystemError, cx.execute, "while(true) {}")
4343

4444
@t.cx()
4545
def test_does_not_exceed_time(cx):
@@ -56,12 +56,12 @@ def test_does_not_exceed_time(cx):
5656
def test_exceed_memory(cx):
5757
cx.max_memory(10000)
5858
script = "var f = []; var b = 1000000; while(b-- > 0) f[f.length] = b*0.9;"
59-
t.raises(Exception, cx.execute, script)
59+
t.raises(MemoryError, cx.execute, script)
6060

6161
@t.cx()
6262
def test_small_limit(cx):
6363
cx.max_memory(1)
64-
t.raises(Exception, cx.execute, "far f = 0.3; f;");
64+
t.raises(MemoryError, cx.execute, "var f = []; while(true) f.push(2.3);");
6565

6666
@t.cx()
6767
def test_does_not_exceed_memory(cx):

0 commit comments

Comments
 (0)