changeset 20:abede8af8cf5

PYM_jsvalToPyObject() can now deal with JSObjects.
author Atul Varma <varmaa@toolness.com>
date Sun, 28 Jun 2009 20:19:39 -0700
parents fbb9a61fa030
children fc04e5f1c675
files context.c test_pymonkey.py utils.c utils.h
diffstat 4 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/context.c	Sun Jun 28 20:08:59 2009 -0700
+++ b/context.c	Sun Jun 28 20:19:39 2009 -0700
@@ -75,7 +75,7 @@
   }
 
   PyMem_Free(string);
-  return PYM_jsvalToPyObject(val);
+  return PYM_jsvalToPyObject(self->runtime, val);
 }
 
 static PyObject *
@@ -118,7 +118,7 @@
     return NULL;
   }
 
-  PyObject *pyRval = PYM_jsvalToPyObject(rval);
+  PyObject *pyRval = PYM_jsvalToPyObject(self->runtime, rval);
 
   JS_EndRequest(self->cx);
 
--- a/test_pymonkey.py	Sun Jun 28 20:08:59 2009 -0700
+++ b/test_pymonkey.py	Sun Jun 28 20:19:39 2009 -0700
@@ -51,6 +51,15 @@
         self.assertTrue(type(retval) == unicode)
         self.assertEqual(retval, u'o hai\u2026')
 
+    def testEvaluateReturnsObject(self):
+        rt = pymonkey.Runtime()
+        cx = rt.new_context()
+        obj = cx.new_object()
+        cx.init_standard_classes(obj)
+        obj = cx.evaluate_script(obj, '({boop: 1})', '<string>', 1)
+        self.assertTrue(isinstance(obj, pymonkey.Object))
+        self.assertEqual(cx.get_property(obj, "boop"), 1)
+
     def testEvaluateReturnsTrue(self):
         self.assertTrue(self._evaljs('true') is True)
 
--- a/utils.c	Sun Jun 28 20:08:59 2009 -0700
+++ b/utils.c	Sun Jun 28 20:19:39 2009 -0700
@@ -1,10 +1,12 @@
 #include "utils.h"
 #include "undefined.h"
+#include "object.h"
 
 PyObject *PYM_error;
 
 PyObject *
-PYM_jsvalToPyObject(jsval value) {
+PYM_jsvalToPyObject(PYM_JSRuntimeObject *runtime,
+                    jsval value) {
   if (JSVAL_IS_INT(value))
     return PyInt_FromLong(JSVAL_TO_INT(value));
 
@@ -38,6 +40,9 @@
     return PyUnicode_DecodeUTF8(bytes, strlen(bytes), errors);
   }
 
+  if (JSVAL_IS_OBJECT(value))
+    return (PyObject *) PYM_newJSObject(runtime, JSVAL_TO_OBJECT(value));
+
   // TODO: Support more types.
   PyErr_SetString(PyExc_NotImplementedError,
                   "Data type conversion not implemented.");
--- a/utils.h	Sun Jun 28 20:08:59 2009 -0700
+++ b/utils.h	Sun Jun 28 20:19:39 2009 -0700
@@ -1,12 +1,14 @@
 #ifndef PYM_UTILS_H
 #define PYM_UTILS_H
 
+#include "runtime.h"
+
 #include <jsapi.h>
 #include <Python/Python.h>
 
 extern PyObject *PYM_error;
 
 extern PyObject *
-PYM_jsvalToPyObject(jsval value);
+PYM_jsvalToPyObject(PYM_JSRuntimeObject *runtime, jsval value);
 
 #endif