Mercurial > pymonkey
diff context.c @ 84:10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 09 Aug 2009 15:18:33 -0700 |
parents | ac40f4e03e91 |
children | 345d4c0e3dd3 |
line wrap: on
line diff
--- a/context.c Sun Aug 09 14:47:35 2009 -0700 +++ b/context.c Sun Aug 09 15:18:33 2009 -0700 @@ -118,13 +118,26 @@ if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) return NULL; - JSClass *klass = JS_GET_CLASS(self->cx, object->obj); + 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); + } + + JSClass *klass = JS_GET_CLASS(self->cx, obj); if (klass != &PYM_JS_ObjectClass) Py_RETURN_NONE; PyObject *pyObject; - if (!PYM_JS_getPrivatePyObject(self->cx, object->obj, &pyObject)) { + if (!PYM_JS_getPrivatePyObject(self->cx, obj, &pyObject)) { PYM_jsExceptionToPython(self); return NULL; } @@ -144,11 +157,24 @@ if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) return NULL; - JSClass *klass = JS_GET_CLASS(self->cx, object->obj); + 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); + } + + JSClass *klass = JS_GET_CLASS(self->cx, obj); if (klass != &PYM_JS_ObjectClass) Py_RETURN_NONE; - if (!PYM_JS_setPrivatePyObject(self->cx, object->obj, Py_None)) { + if (!PYM_JS_setPrivatePyObject(self->cx, obj, Py_None)) { PYM_jsExceptionToPython(self); return NULL; }