Commits

Anonymous committed 4a359ee

Fix for time limit constraints.

The root bug I think has to do with conversions between integral types. I
changed the Context.max_time method to be a bit less clever which will hopefully
fix things. I also updated the test_exceeds_time to fail more gracefully as per
suggestion.

Thanks to Mike West

[#15 state:open]

  • Participants
  • Parent commits 229ccba

Comments (0)

Files changed (3)

 
 spahl
     * Heads up on the signal hack and fix for a compiler warning.
+
+Mike West
+    * Reported bug in Context.max_time
+    * Better test for test_exceeds_time
+

spidermonkey/context.c

 Context_max_time(Context* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* ret = NULL;
-    time_t curr_max = (time_t) -1;
-    time_t new_max = (time_t) -1;
+    int curr_max = -1;
+    int new_max = -1;
 
-    if(!PyArg_ParseTuple(args, "|I", &new_max)) goto done;
+    if(!PyArg_ParseTuple(args, "|i", &new_max)) goto done;
 
     curr_max = self->max_time;
-    if(new_max != ((time_t) -1)) self->max_time = new_max;
+    if(new_max > 0) self->max_time = (time_t) new_max;
 
     ret = PyLong_FromLong((long) curr_max);
 

tests/test-context.py

 
 @t.cx()
 def test_exceed_time(cx):
+    script = """
+        var time = function() {return (new Date()).getTime();};
+        var start = time();
+        while((time() - start) < 2000) {}
+    """
     cx.max_time(1)
-    t.raises(SystemError, cx.execute, "while(true) {}")
+    t.raises(SystemError, cx.execute, script)
 
 @t.cx()
 def test_does_not_exceed_time(cx):