Make sure proxy objects always have a parent (576714, r=jorendorff).

This commit is contained in:
Andreas Gal 2010-07-07 12:32:36 -07:00
Родитель f6de7ea61e
Коммит cbca95f74c
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

@ -1065,15 +1065,16 @@ proxy_create(JSContext *cx, uintN argc, jsval *vp)
JSObject *handler; JSObject *handler;
if (!(handler = NonNullObject(cx, vp[2]))) if (!(handler = NonNullObject(cx, vp[2])))
return false; return false;
JSObject *proto, *parent; JSObject *proto, *parent = NULL;
if (argc > 1 && !JSVAL_IS_PRIMITIVE(vp[3])) { if (argc > 1 && !JSVAL_IS_PRIMITIVE(vp[3])) {
proto = JSVAL_TO_OBJECT(vp[3]); proto = JSVAL_TO_OBJECT(vp[3]);
parent = proto->getParent(); parent = proto->getParent();
} else { } else {
JS_ASSERT(VALUE_IS_FUNCTION(cx, vp[0])); JS_ASSERT(VALUE_IS_FUNCTION(cx, vp[0]));
proto = NULL; proto = NULL;
parent = JSVAL_TO_OBJECT(vp[0])->getParent();
} }
if (!parent)
parent = JSVAL_TO_OBJECT(vp[0])->getParent();
JSObject *proxy = NewProxyObject(cx, &JSScriptedProxyHandler::singleton, OBJECT_TO_JSVAL(handler), JSObject *proxy = NewProxyObject(cx, &JSScriptedProxyHandler::singleton, OBJECT_TO_JSVAL(handler),
proto, parent); proto, parent);
if (!proxy) if (!proxy)