Mercurial > pymonkey
diff test_pymonkey.py @ 84:10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 09 Aug 2009 15:18:33 -0700 |
parents | 99138265d4b9 |
children | 16a3e99e9b77 |
line wrap: on
line diff
--- a/test_pymonkey.py Sun Aug 09 14:47:35 2009 -0700 +++ b/test_pymonkey.py Sun Aug 09 15:18:33 2009 -0700 @@ -81,6 +81,14 @@ self.assertEqual(str(pymonkey.undefined), "pymonkey.undefined") + def testJsWrappedPythonFuncHasPrivate(self): + def foo(cx, this, args): + pass + + cx = pymonkey.Runtime().new_context() + jsfunc = cx.new_function(foo, foo.__name__) + self.assertEqual(cx.get_object_private(jsfunc), foo) + def testJsWrappedPythonFuncIsNotGCd(self): def define(cx, obj): def func(cx, this, args): @@ -104,6 +112,30 @@ cx.gc() self.assertEqual(ref(), None) + def testCircularJsWrappedPythonFuncIsGCdIfPrivateCleared(self): + def define(cx, obj): + rt = cx.get_runtime() + def func(cx, this, args): + # Oh noes, a circular reference is born! + rt + jsfunc = cx.new_function(func, func.__name__) + cx.define_property(obj, func.__name__, jsfunc) + return (jsfunc, weakref.ref(func)) + rt = pymonkey.Runtime() + cx = rt.new_context() + obj = cx.new_object() + cx.init_standard_classes(obj) + jsfunc, ref = define(cx, obj) + + # This will break the circular reference. + cx.clear_object_private(jsfunc) + + del jsfunc + del rt + del cx + del obj + self.assertEqual(ref(), None) + def testJsWrappedPythonFuncIsGCdAtRuntimeDestruction(self): def define(cx, obj): def func(cx, this, args):