changeset 142:a2c1db5ece2b

Added a 'filename' member to script objects.
author Atul Varma <varmaa@toolness.com>
date Mon, 24 Aug 2009 22:32:43 -0700
parents 96dc1beefc00
children df97699fc104
files src/script.cpp src/script.h tests/test_pymonkey.py
diffstat 3 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/script.cpp	Mon Aug 24 21:54:20 2009 -0700
+++ b/src/script.cpp	Mon Aug 24 22:32:43 2009 -0700
@@ -37,12 +37,15 @@
 #include "script.h"
 #include "utils.h"
 
+#include "structmember.h"
+#include "jsdbgapi.h"
 #include "jsscript.h"
 
 static void
 PYM_JSScriptDealloc(PYM_JSScript *self)
 {
   self->script = NULL;
+  self->filename = NULL;
   PYM_JSObjectType.tp_dealloc((PyObject *) self);
 }
 
@@ -74,6 +77,12 @@
   (charbufferproc) PYM_charbuffer
 };
 
+static PyMemberDef PYM_members[] = {
+  {"filename", T_STRING, offsetof(PYM_JSScript, filename), READONLY,
+   "Filename of script."},
+  {NULL, NULL, NULL, NULL, NULL}
+};
+
 PyTypeObject PYM_JSScriptType = {
   PyObject_HEAD_INIT(NULL)
   0,                           /*ob_size*/
@@ -107,7 +116,7 @@
   0,                           /* tp_iter */
   0,                           /* tp_iternext */
   0,                           /* tp_methods */
-  0,                           /* tp_members */
+  PYM_members,                 /* tp_members */
   0,                           /* tp_getset */
   0,                           /* tp_base */
   0,                           /* tp_dict */
@@ -142,6 +151,7 @@
       return NULL;
 
     object->script = script;
+    object->filename = JS_GetScriptFilename(context->cx, script);
     return (PYM_JSScript *) PYM_newJSObject(context, scriptObj,
                                             (PYM_JSObject *) object);
   }
--- a/src/script.h	Mon Aug 24 21:54:20 2009 -0700
+++ b/src/script.h	Mon Aug 24 22:32:43 2009 -0700
@@ -46,6 +46,7 @@
 typedef struct {
   PYM_JSObject base;
   JSScript *script;
+  const char *filename;
 } PYM_JSScript;
 
 extern PyTypeObject PYM_JSScriptType;
--- a/tests/test_pymonkey.py	Mon Aug 24 21:54:20 2009 -0700
+++ b/tests/test_pymonkey.py	Mon Aug 24 22:32:43 2009 -0700
@@ -48,10 +48,14 @@
                 u'SyntaxError: missing ; before statement'
                 )
 
+    def testScriptHasFilenameMember(self):
+        cx = pymonkey.Runtime().new_context()
+        script = cx.compile_script('foo', '<string>', 1)
+        self.assertEqual(script.filename, '<string>')
+
     def testScriptIsExposedAsBuffer(self):
         rt = pymonkey.Runtime()
         cx = rt.new_context()
-        obj = cx.new_object()
         script = cx.compile_script('foo', '<string>', 1)
         self.assertTrue(len(buffer(script)) > 0)