Bug 418515 - Better management of parent-finding, needed for new arrays implementation, r/a+=brendan

This commit is contained in:
crowder@fiverocks.com 2008-02-19 21:05:24 -08:00
parent aba72c6e99
commit f5bf4a5765
2 changed files with 9 additions and 10 deletions

View File

@ -2489,6 +2489,13 @@ js_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
*/
JS_PUSH_TEMP_ROOT_OBJECT(cx, obj, &tvr);
/*
* Default parent to the parent of the prototype, which was set from
* the parent of the prototype's constructor.
*/
if (!parent && proto)
STOBJ_SET_PARENT(obj, OBJ_GET_PARENT(cx, proto));
/*
* Share proto's map only if it has the same JSObjectOps, and only if
* proto's class has the same private and reserved slots as obj's map
@ -2505,17 +2512,9 @@ js_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
(JSCLASS_RESERVED_SLOTS_MASK << JSCLASS_RESERVED_SLOTS_SHIFT))) &&
protoclasp->reserveSlots == clasp->reserveSlots)))
{
/*
* Default parent to the parent of the prototype, which was set from
* the parent of the prototype's constructor.
*/
if (!parent)
STOBJ_SET_PARENT(obj, OBJ_GET_PARENT(cx, proto));
/* Share the given prototype's map. */
obj->map = js_HoldObjectMap(cx, map);
} else {
/* Leave parent alone. Allocate a new map for obj. */
map = ops->newObjectMap(cx, 1, ops, clasp, obj);
if (!map)
goto bad;

View File

@ -7997,7 +7997,7 @@ js_GetAnyName(JSContext *cx, jsval *vp)
break;
}
obj = js_NewObject(cx, &js_AnyNameClass, NULL, NULL);
obj = js_NewObjectWithGivenProto(cx, &js_AnyNameClass, NULL, NULL);
if (!obj || !JS_SetPrivate(cx, obj, qn)) {
cx->weakRoots.newborn[GCX_OBJECT] = NULL;
ok = JS_FALSE;
@ -8018,7 +8018,7 @@ js_GetAnyName(JSContext *cx, jsval *vp)
ok = JS_FALSE;
break;
}
OBJ_SET_PROTO(cx, obj, NULL);
JS_ASSERT(!OBJ_GET_PROTO(cx, obj));
JS_ASSERT(!OBJ_GET_PARENT(cx, obj));
} while (0);