diff context.c @ 13:ca17531e8c81

Added an object class.
author Atul Varma <varmaa@toolness.com>
date Sun, 28 Jun 2009 18:19:14 -0700
parents 6d95cfaa1e0b
children 9edcdb4ab12d
line wrap: on
line diff
--- a/context.c	Sun Jun 28 17:43:42 2009 -0700
+++ b/context.c	Sun Jun 28 18:19:14 2009 -0700
@@ -1,4 +1,6 @@
 #include "context.h"
+#include "object.h"
+#include "utils.h"
 
 static void
 PYM_JSContextDealloc(PYM_JSContextObject *self)
@@ -21,9 +23,29 @@
   return (PyObject *) self->runtime;
 }
 
+static PyObject *
+PYM_newObject(PYM_JSContextObject *self, PyObject *args)
+{
+  PYM_JSObject *object = PyObject_New(PYM_JSObject,
+                                      &PYM_JSObjectType);
+  if (object == NULL)
+    return NULL;
+
+  object->obj = JS_NewObject(self->cx, &PYM_JS_ObjectClass, NULL, NULL);
+  if (object->obj == NULL) {
+    PyErr_SetString(PYM_error, "JS_NewObject() failed");
+    Py_DECREF(object);
+    return NULL;
+  }
+
+  return (PyObject *) object;
+}
+
 static PyMethodDef PYM_JSContextMethods[] = {
   {"get_runtime", (PyCFunction) PYM_getRuntime, METH_VARARGS,
    "Get the JavaScript runtime associated with this context."},
+  {"new_object", (PyCFunction) PYM_newObject, METH_VARARGS,
+   "Create a new JavaScript object."},
   {NULL, NULL, 0, NULL}
 };