# HG changeset patch # User Atul Varma # Date 1251672443 25200 # Node ID 56181fb5fc7e2a2e133c4d8e405d4bde2571e8d4 # Parent e57d8083fb3d75ddf9e84b69c7c44a57bc5bf31e Added a function.is_python property indicating whether the js function is implemented in python. diff -r e57d8083fb3d -r 56181fb5fc7e src/function.cpp --- 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; } diff -r e57d8083fb3d -r 56181fb5fc7e src/function.h --- 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; diff -r e57d8083fb3d -r 56181fb5fc7e tests/test_pymonkey.py --- 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(){})', '', 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