diff runtime.c @ 19:fbb9a61fa030

Moved context creation code into its own public function in context.c.
author Atul Varma <varmaa@toolness.com>
date Sun, 28 Jun 2009 20:08:59 -0700
parents ca17531e8c81
children 988a8998c75f
line wrap: on
line diff
--- a/runtime.c	Sun Jun 28 20:00:48 2009 -0700
+++ b/runtime.c	Sun Jun 28 20:08:59 2009 -0700
@@ -35,25 +35,21 @@
 static PyObject *
 PYM_newContext(PYM_JSRuntimeObject *self, PyObject *args)
 {
-  PYM_JSContextObject *context = PyObject_New(PYM_JSContextObject,
-                                              &PYM_JSContextType);
-  if (context == NULL)
-    return NULL;
-
-  context->runtime = self;
-  Py_INCREF(self);
-
-  context->cx = JS_NewContext(self->rt, 8192);
-  if (context->cx == NULL) {
+  JSContext *cx = JS_NewContext(self->rt, 8192);
+  if (cx == NULL) {
     PyErr_SetString(PYM_error, "JS_NewContext() failed");
-    Py_DECREF(context);
     return NULL;
   }
 
-  JS_SetOptions(context->cx, JSOPTION_VAROBJFIX);
-  JS_SetVersion(context->cx, JSVERSION_LATEST);
+  JS_SetOptions(cx, JSOPTION_VAROBJFIX);
+  JS_SetVersion(cx, JSVERSION_LATEST);
+
+  PyObject *retval = (PyObject *) PYM_newJSContextObject(self, cx);
 
-  return (PyObject *) context;
+  if (retval == NULL)
+    JS_DestroyContext(cx);
+
+  return retval;
 }
 
 static PyMethodDef PYM_JSRuntimeMethods[] = {