Use Object as prototype if the prototype of the constructor is primitive (452960, r=mrbkap).

This commit is contained in:
Andreas Gal 2008-09-16 18:49:27 -07:00
parent b2cff5e791
commit 183ab27e9d
2 changed files with 23 additions and 7 deletions

View File

@ -624,11 +624,6 @@ js_FastNewObject(JSContext* cx, JSObject* ctor)
JSClass* clasp = FUN_INTERPRETED(fun) ? &js_ObjectClass : fun->u.n.clasp;
JS_ASSERT(clasp != &js_ArrayClass);
JS_ASSERT(JS_ON_TRACE(cx));
JSObject* obj = (JSObject*) js_NewGCThing(cx, GCX_OBJECT, sizeof(JSObject));
if (!obj)
return NULL;
JS_LOCK_OBJ(cx, ctor);
JSScope *scope = OBJ_SCOPE(ctor);
JS_ASSERT(scope->object == ctor);
@ -639,8 +634,20 @@ js_FastNewObject(JSContext* cx, JSObject* ctor)
jsval v = LOCKED_OBJ_GET_SLOT(ctor, sprop->slot);
JS_UNLOCK_SCOPE(cx, scope);
JS_ASSERT(!JSVAL_IS_PRIMITIVE(v));
JSObject* proto = JSVAL_TO_OBJECT(v);
JSObject* proto;
if (JSVAL_IS_PRIMITIVE(v)) {
if (!js_GetClassPrototype(cx, JSVAL_TO_OBJECT(ctor->fslots[JSSLOT_PARENT]),
INT_TO_JSID(JSProto_Object), &proto)) {
return NULL;
}
} else {
proto = JSVAL_TO_OBJECT(v);
}
JS_ASSERT(JS_ON_TRACE(cx));
JSObject* obj = (JSObject*) js_NewGCThing(cx, GCX_OBJECT, sizeof(JSObject));
if (!obj)
return NULL;
obj->classword = jsuword(clasp);
obj->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto);

View File

@ -1339,6 +1339,15 @@ function testSetPropNeitherMissNorHit() {
testSetPropNeitherMissNorHit.expected = "ok";
test(testSetPropNeitherMissNorHit);
function testPrimitiveConstructorPrototype() {
var f = function(){};
f.prototype = false;
for (let j=0;j<5;++j) { new f; }
return "ok";
}
testPrimitiveConstructorPrototype.expected = "ok";
test(testPrimitiveConstructorPrototype);
/* Keep these at the end so that we can see the summary after the trace-debug spew. */
print("\npassed:", passes.length && passes.join(","));
print("\nFAILED:", fails.length && fails.join(","));