changeset 28:f974d4a80473 default tip

Some fixes.
author Atul Varma <varmaa@toolness.com>
date Tue, 08 Sep 2009 15:27:02 -0700
parents 7f12db104246
children
files pydershell/pydershell.py
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pydershell/pydershell.py	Tue Sep 08 09:38:46 2009 -0700
+++ b/pydershell/pydershell.py	Tue Sep 08 15:27:02 2009 -0700
@@ -396,7 +396,7 @@
         elif isinstance(value, JsExposedObject):
             return self.__wrap_pyinstance(value)
         else:
-            raise TypeError("Can't expose objects of type '' to JS." %
+            raise TypeError("Can't expose objects of type '%s' to JS." %
                             type(value).__name__)
 
     def wrap_jsobject(self, jsvalue, this=None):
@@ -430,20 +430,21 @@
     def new_array(self, *contents):
         array = self.wrap_jsobject(self.cx.new_array_object())
         for item in contents:
-            array.push(self.wrap_pyobject(item))
+            array.push(item)
         return array
 
     def new_object(self, **contents):
         obj = self.wrap_jsobject(self.cx.new_object())
         for name in contents:
-            obj[name] = self.wrap_pyobject(contents[name])
+            obj[name] = contents[name]
+        return obj
 
     def evaluate(self, code, filename='<string>', lineno=1):
         retval = self.cx.evaluate_script(self.root.wrapped_jsobject,
                                          code, filename, lineno)
         return self.wrap_jsobject(retval)
 
-    def run_script(self, filename):
+    def run_script(self, filename, callback=None):
         """
         Runs the given JS script, returning 0 on success, -1 on failure.
         """
@@ -452,8 +453,10 @@
         contents = open(filename).read()
         cx = self.cx
         try:
-            cx.evaluate_script(self.root.wrapped_jsobject, contents,
-                               filename, 1)
+            result = cx.evaluate_script(self.root.wrapped_jsobject,
+                                        contents, filename, 1)
+            if callback:
+                callback(self.wrap_jsobject(result))
             retval = 0
         except pydermonkey.error, e:
             print format_stack(self.js_stack)