Mercurial > pymonkey
changeset 14:9edcdb4ab12d
added an init_standard_classes() method to context objects.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 28 Jun 2009 18:28:35 -0700 |
parents | ca17531e8c81 |
children | baa4cb961330 |
files | context.c test_pymonkey.py |
diffstat | 2 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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} };
--- 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)