changeset 27:7f12db104246

Added evaluate, new_array, and new_object functions to JsSandbox class.
author Atul Varma <varmaa@toolness.com>
date Tue, 08 Sep 2009 09:38:46 -0700
parents b7037cd0f375
children f974d4a80473
files pydershell/pydershell.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pydershell/pydershell.py	Mon Sep 07 22:17:57 2009 -0700
+++ b/pydershell/pydershell.py	Tue Sep 08 09:38:46 2009 -0700
@@ -427,6 +427,22 @@
             # It's a primitive value.
             return jsvalue
 
+    def new_array(self, *contents):
+        array = self.wrap_jsobject(self.cx.new_array_object())
+        for item in contents:
+            array.push(self.wrap_pyobject(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])
+
+    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):
         """
         Runs the given JS script, returning 0 on success, -1 on failure.