Bug 1326453 - Part 3: Don't throw a TypeError when SetPrototypeOf for module namespace objects is called with null. r=jonco
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 30 Dec 2016 14:28:34 -0800
changeset 328029 5459a408763b5c569c87da171a68bd6813965fe0
parent 328028 3768e0fa8f4928f5735305e2f7c28afab637f898
child 328030 873a22cd1fe103ee6b18e570ab6be787bf5bcd6f
push id85352
push usercbook@mozilla.com
push dateThu, 05 Jan 2017 07:30:34 +0000
treeherdermozilla-inbound@07de2edd9c25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1326453
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1326453 - Part 3: Don't throw a TypeError when SetPrototypeOf for module namespace objects is called with null. r=jonco
js/src/builtin/ModuleObject.cpp
js/src/jit-test/tests/modules/import-namespace.js
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -340,16 +340,18 @@ ModuleNamespaceObject::ProxyHandler::get
     protop.set(nullptr);
     return true;
 }
 
 bool
 ModuleNamespaceObject::ProxyHandler::setPrototype(JSContext* cx, HandleObject proxy,
                                                   HandleObject proto, ObjectOpResult& result) const
 {
+    if (!proto)
+        return result.succeed();
     return result.failCantSetProto();
 }
 
 bool
 ModuleNamespaceObject::ProxyHandler::getPrototypeIfOrdinary(JSContext* cx, HandleObject proxy,
                                                             bool* isOrdinary,
                                                             MutableHandleObject protop) const
 {
--- a/js/src/jit-test/tests/modules/import-namespace.js
+++ b/js/src/jit-test/tests/modules/import-namespace.js
@@ -34,17 +34,19 @@ b.declarationInstantiation();
 b.evaluation();
 testHasNames(getModuleEnvironmentNames(b), ["ns", "x"]);
 let ns = getModuleEnvironmentValue(b, "ns");
 testHasNames(Object.keys(ns), ["a", "b"]);
 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);
 let desc = Object.getOwnPropertyDescriptor(ns, "a");
 assertEq(desc.value, 1);
 assertEq(desc.writable, true);
 assertEq(desc.enumerable, true);
 assertEq(desc.configurable, false);