Bug 1326453 - Part 3: Don't throw a TypeError when SetPrototypeOf for module namespace objects is called with null

This commit is contained in:
janekptacijarabaci 2018-04-14 08:51:05 +02:00 committed by Roy Tam
commit 50765b944e
2 changed files with 5 additions and 1 deletions

View file

@ -345,6 +345,8 @@ bool
ModuleNamespaceObject::ProxyHandler::setPrototype(JSContext* cx, HandleObject proxy,
HandleObject proto, ObjectOpResult& result) const
{
if (!proto)
return result.succeed();
return result.failCantSetProto();
}

View file

@ -39,7 +39,9 @@ assertEq(getModuleEnvironmentValue(b, "x"), 3);
// Test module namespace internal methods as defined in 9.4.6
assertEq(Object.getPrototypeOf(ns), null);
assertThrowsInstanceOf(() => Object.setPrototypeOf(ns, null), TypeError);
assertEq(Reflect.setPrototypeOf(ns, null), true);
assertEq(Reflect.setPrototypeOf(ns, Object.prototype), false);
assertThrowsInstanceOf(() => Object.setPrototypeOf(ns, {}), TypeError);
assertThrowsInstanceOf(function() { ns.foo = 1; }, TypeError);
assertEq(Object.isExtensible(ns), false);
Object.preventExtensions(ns);