# HG changeset patch # User Atul Varma # Date 1246238915 25200 # Node ID 9edcdb4ab12dd9df54f2b96e7d6e36d151f21155 # Parent ca17531e8c81b8c1e5ff865a079ea00f117ceecb added an init_standard_classes() method to context objects. diff -r ca17531e8c81 -r 9edcdb4ab12d context.c --- a/context.c Sun Jun 28 18:19:14 2009 -0700 +++ b/context.c Sun Jun 28 18:28:35 2009 -0700 @@ -41,11 +41,30 @@ return (PyObject *) object; } +static PyObject * +PYM_initStandardClasses(PYM_JSContextObject *self, PyObject *args) +{ + PYM_JSObject *object; + + if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) + return NULL; + + if (!JS_InitStandardClasses(self->cx, object->obj)) { + PyErr_SetString(PYM_error, "JS_InitStandardClasses() failed"); + return NULL; + } + + Py_RETURN_NONE; +} + 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."}, + {"init_standard_classes", + (PyCFunction) PYM_initStandardClasses, METH_VARARGS, + "Add standard classes and functions to the given object."}, {NULL, NULL, 0, NULL} }; diff -r ca17531e8c81 -r 9edcdb4ab12d test_pymonkey.py --- a/test_pymonkey.py Sun Jun 28 18:19:14 2009 -0700 +++ b/test_pymonkey.py Sun Jun 28 18:28:35 2009 -0700 @@ -13,6 +13,8 @@ self.assertRaises(TypeError, pymonkey.Object) self.assertTrue(isinstance(obj, pymonkey.Object)) + cx.init_standard_classes(obj) + def testUndefinedCannotBeInstantiated(self): self.assertRaises(TypeError, pymonkey.undefined)