Mercurial > pymonkey
changeset 143:df97699fc104
Added base_lineno and line_extent members to the script object.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 24 Aug 2009 22:40:53 -0700 |
parents | a2c1db5ece2b |
children | ab612d2ad96a |
files | src/script.cpp src/script.h tests/test_pymonkey.py |
diffstat | 3 files changed, 15 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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); }
--- 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;
--- 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', '<string>', 1) self.assertEqual(script.filename, '<string>') + def testScriptHasLineInfo(self): + cx = pymonkey.Runtime().new_context() + script = cx.compile_script('foo\nbar', '<string>', 1) + self.assertEqual(script.base_lineno, 1) + self.assertEqual(script.line_extent, 2) + def testScriptIsExposedAsBuffer(self): rt = pymonkey.Runtime() cx = rt.new_context()