Mercurial > pymonkey
changeset 160:56181fb5fc7e
Added a function.is_python property indicating whether the js function is implemented in python.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 30 Aug 2009 15:47:23 -0700 |
parents | e57d8083fb3d |
children | 28d067082390 |
files | src/function.cpp src/function.h tests/test_pymonkey.py |
diffstat | 3 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/function.cpp Sun Aug 30 15:23:26 2009 -0700 +++ b/src/function.cpp Sun Aug 30 15:47:23 2009 -0700 @@ -144,6 +144,8 @@ "Base line number of function's source code."}, {"line_extent", T_UINT, offsetof(PYM_JSFunction, lineExtent), READONLY, "Line extent of function's source code."}, + {"is_python", T_BYTE, offsetof(PYM_JSFunction, isPython), READONLY, + "Whether or not the function is implemented in Python."}, {NULL, NULL, NULL, NULL, NULL} }; @@ -206,6 +208,7 @@ jsFunction->filename = NULL; jsFunction->baseLineno = 0; jsFunction->lineExtent = 0; + jsFunction->isPython = 0; JSString *name = JS_GetFunctionId(jsFunction->fun); if (name != NULL) { @@ -284,5 +287,7 @@ return NULL; } + object->isPython = 1; + return object; }
--- a/src/function.h Sun Aug 30 15:23:26 2009 -0700 +++ b/src/function.h Sun Aug 30 15:47:23 2009 -0700 @@ -50,6 +50,7 @@ const char *filename; unsigned int baseLineno; unsigned int lineExtent; + char isPython; } PYM_JSFunction; extern PyTypeObject PYM_JSFunctionType;
--- a/tests/test_pymonkey.py Sun Aug 30 15:23:26 2009 -0700 +++ b/tests/test_pymonkey.py Sun Aug 30 15:47:23 2009 -0700 @@ -204,6 +204,20 @@ self.assertEqual(str(pymonkey.undefined), "pymonkey.undefined") + def testScriptedJsFuncHasIsPythonFalse(self): + cx = pymonkey.Runtime().new_context() + jsfunc = cx.evaluate_script(cx.new_object(), + '(function(){})', '<string>', 1) + self.assertFalse(jsfunc.is_python) + + def testJsWrappedPythonFuncHasIsPythonTrue(self): + def foo(cx, this, args): + pass + + cx = pymonkey.Runtime().new_context() + jsfunc = cx.new_function(foo, foo.__name__) + self.assertTrue(jsfunc.is_python) + def testJsWrappedPythonFuncHasNoFilename(self): def foo(cx, this, args): pass