changeset 18:f3223debd70b

Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
author Atul Varma <varmaa@toolness.com>
date Sun, 28 Jun 2009 20:00:48 -0700
parents 0812422ec99e
children fbb9a61fa030
files context.c object.c object.h
diffstat 3 files changed, 23 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/context.c	Sun Jun 28 19:44:13 2009 -0700
+++ b/context.c	Sun Jun 28 20:00:48 2009 -0700
@@ -26,25 +26,13 @@
 static PyObject *
 PYM_newObject(PYM_JSContextObject *self, PyObject *args)
 {
-  PYM_JSObject *object = PyObject_New(PYM_JSObject,
-                                      &PYM_JSObjectType);
-  if (object == NULL)
-    return NULL;
-
-  object->runtime = self->runtime;
-  Py_INCREF(object->runtime);
-
-  object->obj = JS_NewObject(self->cx, &PYM_JS_ObjectClass, NULL, NULL);
-  if (object->obj == NULL) {
+  JSObject *obj = JS_NewObject(self->cx, &PYM_JS_ObjectClass, NULL, NULL);
+  if (obj == NULL) {
     PyErr_SetString(PYM_error, "JS_NewObject() failed");
-    Py_DECREF(object);
     return NULL;
   }
 
-  JS_AddNamedRootRT(object->runtime->rt, &object->obj,
-                    "Pymonkey-Generated Object");
-
-  return (PyObject *) object;
+  return (PyObject *) PYM_newJSObject(self->runtime, obj);
 }
 
 static PyObject *
--- a/object.c	Sun Jun 28 19:44:13 2009 -0700
+++ b/object.c	Sun Jun 28 20:00:48 2009 -0700
@@ -65,3 +65,21 @@
   0,                           /* tp_alloc */
   0,                           /* tp_new */
 };
+
+PYM_JSObject *PYM_newJSObject(PYM_JSRuntimeObject *runtime,
+                              JSObject *obj) {
+  PYM_JSObject *object = PyObject_New(PYM_JSObject,
+                                      &PYM_JSObjectType);
+  if (object == NULL)
+    return NULL;
+
+  object->runtime = runtime;
+  Py_INCREF(object->runtime);
+
+  object->obj = obj;
+
+  JS_AddNamedRootRT(object->runtime->rt, &object->obj,
+                    "Pymonkey-Generated Object");
+
+  return object;
+}
--- a/object.h	Sun Jun 28 19:44:13 2009 -0700
+++ b/object.h	Sun Jun 28 20:00:48 2009 -0700
@@ -16,4 +16,6 @@
 
 extern PyTypeObject PYM_JSObjectType;
 
+extern PYM_JSObject *PYM_newJSObject(PYM_JSRuntimeObject *runtime,
+                                     JSObject *obj);
 #endif