Mercurial > pymonkey
comparison 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 |
comparison
equal
deleted
inserted
replaced
83:ac40f4e03e91 | 84:10205d88f6ff |
---|---|
116 PYM_JSObject *object; | 116 PYM_JSObject *object; |
117 | 117 |
118 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) | 118 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) |
119 return NULL; | 119 return NULL; |
120 | 120 |
121 JSClass *klass = JS_GET_CLASS(self->cx, object->obj); | 121 JSObject *obj = object->obj; |
122 | |
123 if (JS_ObjectIsFunction(self->cx, obj)) { | |
124 jsval functionHolder; | |
125 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { | |
126 JS_ClearPendingException(self->cx); | |
127 Py_RETURN_NONE; | |
128 } | |
129 if (!JSVAL_IS_OBJECT(functionHolder)) | |
130 Py_RETURN_NONE; | |
131 obj = JSVAL_TO_OBJECT(functionHolder); | |
132 } | |
133 | |
134 JSClass *klass = JS_GET_CLASS(self->cx, obj); | |
122 if (klass != &PYM_JS_ObjectClass) | 135 if (klass != &PYM_JS_ObjectClass) |
123 Py_RETURN_NONE; | 136 Py_RETURN_NONE; |
124 | 137 |
125 PyObject *pyObject; | 138 PyObject *pyObject; |
126 | 139 |
127 if (!PYM_JS_getPrivatePyObject(self->cx, object->obj, &pyObject)) { | 140 if (!PYM_JS_getPrivatePyObject(self->cx, obj, &pyObject)) { |
128 PYM_jsExceptionToPython(self); | 141 PYM_jsExceptionToPython(self); |
129 return NULL; | 142 return NULL; |
130 } | 143 } |
131 | 144 |
132 if (pyObject == NULL) | 145 if (pyObject == NULL) |
142 PYM_JSObject *object; | 155 PYM_JSObject *object; |
143 | 156 |
144 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) | 157 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) |
145 return NULL; | 158 return NULL; |
146 | 159 |
147 JSClass *klass = JS_GET_CLASS(self->cx, object->obj); | 160 JSObject *obj = object->obj; |
161 | |
162 if (JS_ObjectIsFunction(self->cx, obj)) { | |
163 jsval functionHolder; | |
164 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { | |
165 JS_ClearPendingException(self->cx); | |
166 Py_RETURN_NONE; | |
167 } | |
168 if (!JSVAL_IS_OBJECT(functionHolder)) | |
169 Py_RETURN_NONE; | |
170 obj = JSVAL_TO_OBJECT(functionHolder); | |
171 } | |
172 | |
173 JSClass *klass = JS_GET_CLASS(self->cx, obj); | |
148 if (klass != &PYM_JS_ObjectClass) | 174 if (klass != &PYM_JS_ObjectClass) |
149 Py_RETURN_NONE; | 175 Py_RETURN_NONE; |
150 | 176 |
151 if (!PYM_JS_setPrivatePyObject(self->cx, object->obj, Py_None)) { | 177 if (!PYM_JS_setPrivatePyObject(self->cx, obj, Py_None)) { |
152 PYM_jsExceptionToPython(self); | 178 PYM_jsExceptionToPython(self); |
153 return NULL; | 179 return NULL; |
154 } | 180 } |
155 | 181 |
156 Py_RETURN_NONE; | 182 Py_RETURN_NONE; |