Mercurial > pymonkey
comparison test_pymonkey.py @ 61:1506350991d4
JS Wrapped python functions are now only GC'd by python once they've first been GC'd by JS.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sat, 25 Jul 2009 16:14:03 -0700 |
parents | fb97bed55789 |
children | 2b5696b91b01 |
comparison
equal
deleted
inserted
replaced
60:e557d84318a7 | 61:1506350991d4 |
---|---|
32 def testUndefinedStrIsUndefined(self): | 32 def testUndefinedStrIsUndefined(self): |
33 self.assertEqual(str(pymonkey.undefined), | 33 self.assertEqual(str(pymonkey.undefined), |
34 "pymonkey.undefined") | 34 "pymonkey.undefined") |
35 | 35 |
36 def testJsWrappedPythonFuncIsNotGCd(self): | 36 def testJsWrappedPythonFuncIsNotGCd(self): |
37 # TODO: Make this test pass. | |
38 def define(cx, obj): | 37 def define(cx, obj): |
39 def func(cx, this, args): | 38 def func(cx, this, args): |
40 return u'func was called' | 39 return u'func was called' |
41 jsfunc = cx.new_function(func, func.__name__) | 40 jsfunc = cx.new_function(func, func.__name__) |
42 cx.define_property(obj, func.__name__, jsfunc) | 41 cx.define_property(obj, func.__name__, jsfunc) |
43 return weakref.ref(func) | 42 return weakref.ref(func) |
44 cx = pymonkey.Runtime().new_context() | 43 rt = pymonkey.Runtime() |
44 cx = rt.new_context() | |
45 obj = cx.new_object() | 45 obj = cx.new_object() |
46 cx.init_standard_classes(obj) | 46 cx.init_standard_classes(obj) |
47 ref = define(cx, obj) | 47 ref = define(cx, obj) |
48 cx.gc() | |
48 self.assertNotEqual(ref(), None) | 49 self.assertNotEqual(ref(), None) |
49 result = cx.evaluate_script(obj, 'func()', '<string>', 1) | 50 result = cx.evaluate_script(obj, 'func()', '<string>', 1) |
50 self.assertEqual(result, u'func was called') | 51 self.assertEqual(result, u'func was called') |
52 | |
53 # Now ensure that the wrapped function is GC'd when it's | |
54 # no longer reachable from JS space. | |
55 cx.define_property(obj, 'func', 0) | |
56 cx.gc() | |
57 self.assertEqual(ref(), None) | |
51 | 58 |
52 def testJsWrappedPythonFuncPassesContext(self): | 59 def testJsWrappedPythonFuncPassesContext(self): |
53 contexts = [] | 60 contexts = [] |
54 | 61 |
55 def func(cx, this, args): | 62 def func(cx, this, args): |