diff test_pymonkey.py @ 64:fb7e11dec538

Added context.set_operation_callback() and trigger_operation_callback() methods.
author Atul Varma <varmaa@toolness.com>
date Sun, 26 Jul 2009 12:43:31 -0700
parents 2b5696b91b01
children b49180c39d0a
line wrap: on
line diff
--- a/test_pymonkey.py	Sat Jul 25 23:08:47 2009 -0700
+++ b/test_pymonkey.py	Sun Jul 26 12:43:31 2009 -0700
@@ -29,6 +29,30 @@
             was_raised = True
         self.assertTrue(was_raised)
 
+    def testOperationCallbackIsCalled(self):
+        def opcb(cx):
+            raise Exception("stop eet!")
+
+        cx = pymonkey.Runtime().new_context()
+        cx.set_operation_callback(opcb)
+        obj = cx.new_object()
+        cx.init_standard_classes(obj)
+
+        # TODO: This isn't a very good test; we need to actually
+        # set up a signal or launch a separate thread to call
+        # this method as though it were a watchdog to limit the
+        # amount of time the JS can run. However, Pymonkey doesn't
+        # yet handle the GIL properly so this isn't possible.
+        cx.trigger_operation_callback()
+
+        self.assertRaises(
+            pymonkey.error,
+            cx.evaluate_script,
+            obj, 'while (1) {}', '<string>', 1
+            )
+        self.assertEqual(self.last_exception.message,
+                         "stop eet!")
+
     def testUndefinedStrIsUndefined(self):
         self.assertEqual(str(pymonkey.undefined),
                          "pymonkey.undefined")