Mercurial > pymonkey
comparison 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 |
comparison
equal
deleted
inserted
replaced
161:28d067082390 | 162:d1606a6cf1c0 |
---|---|
221 if (top) | 221 if (top) |
222 return top; | 222 return top; |
223 Py_RETURN_NONE; | 223 Py_RETURN_NONE; |
224 } | 224 } |
225 | 225 |
226 static int | |
227 PYM_maybeGetFunctionHolder(PYM_JSContextObject *context, | |
228 PYM_JSObject *object, | |
229 JSObject **result) | |
230 { | |
231 if (PyType_IsSubtype(object->ob_type, &PYM_JSFunctionType)) { | |
232 PYM_JSFunction *func = (PYM_JSFunction *) object; | |
233 if (func->isPython) { | |
234 jsval holder; | |
235 if (!JS_GetReservedSlot(context->cx, object->obj, 0, &holder)) { | |
236 PYM_jsExceptionToPython(context); | |
237 return -1; | |
238 } | |
239 *result = JSVAL_TO_OBJECT(holder); | |
240 return 0; | |
241 } | |
242 } | |
243 | |
244 return 0; | |
245 } | |
246 | |
226 static PyObject * | 247 static PyObject * |
227 PYM_getObjectPrivate(PYM_JSContextObject *self, PyObject *args) | 248 PYM_getObjectPrivate(PYM_JSContextObject *self, PyObject *args) |
228 { | 249 { |
229 PYM_SANITY_CHECK(self->runtime); | 250 PYM_SANITY_CHECK(self->runtime); |
230 PYM_JSObject *object; | 251 PYM_JSObject *object; |
234 | 255 |
235 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); | 256 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
236 | 257 |
237 JSObject *obj = object->obj; | 258 JSObject *obj = object->obj; |
238 | 259 |
239 if (JS_ObjectIsFunction(self->cx, obj)) { | 260 if (PYM_maybeGetFunctionHolder(self, object, &obj) != 0) |
240 jsval functionHolder; | 261 return NULL; |
241 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { | |
242 JS_ClearPendingException(self->cx); | |
243 Py_RETURN_NONE; | |
244 } | |
245 if (!JSVAL_IS_OBJECT(functionHolder)) | |
246 Py_RETURN_NONE; | |
247 obj = JSVAL_TO_OBJECT(functionHolder); | |
248 } | |
249 | 262 |
250 JSClass *klass = JS_GET_CLASS(self->cx, obj); | 263 JSClass *klass = JS_GET_CLASS(self->cx, obj); |
251 if (klass != &PYM_JS_ObjectClass) | 264 if (klass != &PYM_JS_ObjectClass) |
252 Py_RETURN_NONE; | 265 Py_RETURN_NONE; |
253 | 266 |
276 | 289 |
277 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); | 290 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
278 | 291 |
279 JSObject *obj = object->obj; | 292 JSObject *obj = object->obj; |
280 | 293 |
281 if (JS_ObjectIsFunction(self->cx, obj)) { | 294 if (PYM_maybeGetFunctionHolder(self, object, &obj) != 0) |
282 jsval functionHolder; | 295 return NULL; |
283 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { | |
284 JS_ClearPendingException(self->cx); | |
285 Py_RETURN_NONE; | |
286 } | |
287 if (!JSVAL_IS_OBJECT(functionHolder)) | |
288 Py_RETURN_NONE; | |
289 obj = JSVAL_TO_OBJECT(functionHolder); | |
290 } | |
291 | 296 |
292 JSClass *klass = JS_GET_CLASS(self->cx, obj); | 297 JSClass *klass = JS_GET_CLASS(self->cx, obj); |
293 if (klass != &PYM_JS_ObjectClass) | 298 if (klass != &PYM_JS_ObjectClass) |
294 Py_RETURN_NONE; | 299 Py_RETURN_NONE; |
295 | 300 |