зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1296851 - Always allow SetPrototype with the same value as the current [[Prototype]]. r=Waldo
This commit is contained in:
Родитель
6df1030632
Коммит
c0468b53d1
|
@ -2432,6 +2432,13 @@ js::SetPrototype(JSContext* cx, HandleObject obj, HandleObject proto, JS::Object
|
|||
return Proxy::setPrototype(cx, obj, proto, result);
|
||||
}
|
||||
|
||||
/*
|
||||
* ES6 9.1.2 step 3-4 if |obj.[[Prototype]]| has SameValue as |proto| return true.
|
||||
* Since the values in question are objects, we can just compare pointers.
|
||||
*/
|
||||
if (proto == obj->staticPrototype())
|
||||
return result.succeed();
|
||||
|
||||
/* Disallow mutation of immutable [[Prototype]]s. */
|
||||
if (obj->staticPrototypeIsImmutable() && ImmutablePrototypesEnabled)
|
||||
return result.fail(JSMSG_CANT_SET_PROTO);
|
||||
|
@ -2466,13 +2473,6 @@ js::SetPrototype(JSContext* cx, HandleObject obj, HandleObject proto, JS::Object
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* ES6 9.1.2 step 3-4 if |obj.[[Prototype]]| has SameValue as |proto| return true.
|
||||
* Since the values in question are objects, we can just compare pointers.
|
||||
*/
|
||||
if (proto == obj->staticPrototype())
|
||||
return result.succeed();
|
||||
|
||||
/* ES6 9.1.2 step 5 forbids changing [[Prototype]] if not [[Extensible]]. */
|
||||
bool extensible;
|
||||
if (!IsExtensible(cx, obj, &extensible))
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// Setting a "new" prototype to the current [[Prototype]] value should never fail
|
||||
|
||||
var x = {}, t = Object.create(x);
|
||||
Object.preventExtensions(t);
|
||||
// Should not fail, because it is the same [[Prototype]] value
|
||||
Object.setPrototypeOf(t, x);
|
||||
|
||||
// Object.prototype's [[Prototype]] is immutable, make sure we can still set null
|
||||
Object.setPrototypeOf(Object.prototype, null);
|
||||
|
||||
reportCompare(true, true);
|
Загрузка…
Ссылка в новой задаче