Mercurial > pymonkey
diff src/context.cpp @ 162:d1606a6cf1c0
Made get_object_private() and clear_object_private() more robust.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 30 Aug 2009 16:28:38 -0700 |
parents | 22d46b688ace |
children | 1f9a5982db9c |
line wrap: on
line diff
--- a/src/context.cpp Sun Aug 30 15:50:56 2009 -0700 +++ b/src/context.cpp Sun Aug 30 16:28:38 2009 -0700 @@ -223,6 +223,27 @@ Py_RETURN_NONE; } +static int +PYM_maybeGetFunctionHolder(PYM_JSContextObject *context, + PYM_JSObject *object, + JSObject **result) +{ + if (PyType_IsSubtype(object->ob_type, &PYM_JSFunctionType)) { + PYM_JSFunction *func = (PYM_JSFunction *) object; + if (func->isPython) { + jsval holder; + if (!JS_GetReservedSlot(context->cx, object->obj, 0, &holder)) { + PYM_jsExceptionToPython(context); + return -1; + } + *result = JSVAL_TO_OBJECT(holder); + return 0; + } + } + + return 0; +} + static PyObject * PYM_getObjectPrivate(PYM_JSContextObject *self, PyObject *args) { @@ -236,16 +257,8 @@ JSObject *obj = object->obj; - if (JS_ObjectIsFunction(self->cx, obj)) { - jsval functionHolder; - if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { - JS_ClearPendingException(self->cx); - Py_RETURN_NONE; - } - if (!JSVAL_IS_OBJECT(functionHolder)) - Py_RETURN_NONE; - obj = JSVAL_TO_OBJECT(functionHolder); - } + if (PYM_maybeGetFunctionHolder(self, object, &obj) != 0) + return NULL; JSClass *klass = JS_GET_CLASS(self->cx, obj); if (klass != &PYM_JS_ObjectClass) @@ -278,16 +291,8 @@ JSObject *obj = object->obj; - if (JS_ObjectIsFunction(self->cx, obj)) { - jsval functionHolder; - if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { - JS_ClearPendingException(self->cx); - Py_RETURN_NONE; - } - if (!JSVAL_IS_OBJECT(functionHolder)) - Py_RETURN_NONE; - obj = JSVAL_TO_OBJECT(functionHolder); - } + if (PYM_maybeGetFunctionHolder(self, object, &obj) != 0) + return NULL; JSClass *klass = JS_GET_CLASS(self->cx, obj); if (klass != &PYM_JS_ObjectClass)