Mercurial > pymonkey
diff context.c @ 71:9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 27 Jul 2009 21:44:08 -0700 |
parents | b0360c0ed546 |
children | cd545c03eeef |
line wrap: on
line diff
--- a/context.c Mon Jul 27 04:47:33 2009 -0700 +++ b/context.c Mon Jul 27 21:44:08 2009 -0700 @@ -111,9 +111,42 @@ } static PyObject * +PYM_getObjectPrivate(PYM_JSContextObject *self, PyObject *args) +{ + PYM_JSObject *object; + + if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) + return NULL; + + JSClass *klass = JS_GET_CLASS(cx, object->obj); + if (klass != &PYM_JS_ObjectClass) + Py_RETURN_NONE; + + PyObject *pyObject; + + if (!PYM_JS_getPrivatePyObject(self->cx, object->obj, &pyObject)) { + // TODO: Get the actual JS exception. Any exception that exists + // here will probably still be pending on the JS context. + PyErr_SetString(PYM_error, "Getting private failed."); + return NULL; + } + + if (pyObject == NULL) + pyObject = Py_None; + + Py_INCREF(pyObject); + return pyObject; +} + +static PyObject * PYM_newObject(PYM_JSContextObject *self, PyObject *args) { - JSObject *obj = PYM_JS_newObject(self->cx, NULL); + PyObject *privateObj = NULL; + + if (!PyArg_ParseTuple(args, "|O", &privateObj)) + return NULL; + + JSObject *obj = PYM_JS_newObject(self->cx, privateObj); if (obj == NULL) { PyErr_SetString(PYM_error, "PYM_JS_newObject() failed"); return NULL; @@ -370,6 +403,8 @@ {"trigger_operation_callback", (PyCFunction) PYM_triggerOperationCallback, METH_VARARGS, "Triggers the operation callback for the context."}, + {"get_object_private", (PyCFunction) PYM_getObjectPrivate, METH_VARARGS, + "Returns the private Python object stored in the JavaScript object."}, {NULL, NULL, 0, NULL} };