# HG changeset patch # User Atul Varma # Date 1251178853 25200 # Node ID df97699fc1049777d3e6839bb1ccc62618d0ccd9 # Parent a2c1db5ece2b7e2f185806495e6a57bda7efbc54 Added base_lineno and line_extent members to the script object. diff -r a2c1db5ece2b -r df97699fc104 src/script.cpp --- a/src/script.cpp Mon Aug 24 22:32:43 2009 -0700 +++ b/src/script.cpp Mon Aug 24 22:40:53 2009 -0700 @@ -80,6 +80,10 @@ static PyMemberDef PYM_members[] = { {"filename", T_STRING, offsetof(PYM_JSScript, filename), READONLY, "Filename of script."}, + {"base_lineno", T_UINT, offsetof(PYM_JSScript, baseLineno), READONLY, + "Base line number of script."}, + {"line_extent", T_UINT, offsetof(PYM_JSScript, lineExtent), READONLY, + "Line extent of script."}, {NULL, NULL, NULL, NULL, NULL} }; @@ -152,6 +156,9 @@ object->script = script; object->filename = JS_GetScriptFilename(context->cx, script); + object->baseLineno = JS_GetScriptBaseLineNumber(context->cx, script); + object->lineExtent = JS_GetScriptLineExtent(context->cx, script); + return (PYM_JSScript *) PYM_newJSObject(context, scriptObj, (PYM_JSObject *) object); } diff -r a2c1db5ece2b -r df97699fc104 src/script.h --- a/src/script.h Mon Aug 24 22:32:43 2009 -0700 +++ b/src/script.h Mon Aug 24 22:40:53 2009 -0700 @@ -47,6 +47,8 @@ PYM_JSObject base; JSScript *script; const char *filename; + unsigned int baseLineno; + unsigned int lineExtent; } PYM_JSScript; extern PyTypeObject PYM_JSScriptType; diff -r a2c1db5ece2b -r df97699fc104 tests/test_pymonkey.py --- a/tests/test_pymonkey.py Mon Aug 24 22:32:43 2009 -0700 +++ b/tests/test_pymonkey.py Mon Aug 24 22:40:53 2009 -0700 @@ -53,6 +53,12 @@ script = cx.compile_script('foo', '', 1) self.assertEqual(script.filename, '') + def testScriptHasLineInfo(self): + cx = pymonkey.Runtime().new_context() + script = cx.compile_script('foo\nbar', '', 1) + self.assertEqual(script.base_lineno, 1) + self.assertEqual(script.line_extent, 2) + def testScriptIsExposedAsBuffer(self): rt = pymonkey.Runtime() cx = rt.new_context()