Bug 1092538 - Ignore `null` iterable in Map, Set, WeakMap and WeakSet constructors. r=evilpie
authorTooru Fujisawa <arai_a@mac.com>
Sat, 29 Nov 2014 20:57:27 +0900
changeset 243916 187125e5da1021293bfa1b8d19022da2d40ff7d0
parent 243915 084bba95469cd9b3e57bc365a5d337e0273b35cc
child 243917 8bc6a1522933ac2c849b9d975f3b7667278dd9c7
child 243932 5c94f77346f3d873aa17b917254be049b571abbe
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1092538
milestone37.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 1092538 - Ignore `null` iterable in Map, Set, WeakMap and WeakSet constructors. r=evilpie
js/src/builtin/MapObject.cpp
js/src/builtin/WeakSetObject.cpp
js/src/jit-test/tests/collections/Map-constructor-1.js
js/src/jit-test/tests/collections/Map-constructor-4.js
js/src/jit-test/tests/collections/Set-constructor-1.js
js/src/jit-test/tests/collections/WeakMap-constructor-1.js
js/src/jit-test/tests/collections/WeakMap-constructor-4.js
js/src/jit-test/tests/collections/WeakSet-constructor-1.js
js/src/jit-test/tests/collections/constructor-errors.js
js/src/jsweakmap.cpp
--- a/js/src/builtin/MapObject.cpp
+++ b/js/src/builtin/MapObject.cpp
@@ -1231,17 +1231,17 @@ MapObject::finalize(FreeOp *fop, JSObjec
 bool
 MapObject::construct(JSContext *cx, unsigned argc, Value *vp)
 {
     Rooted<MapObject*> obj(cx, MapObject::create(cx));
     if (!obj)
         return false;
 
     CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.hasDefined(0)) {
+    if (!args.get(0).isNullOrUndefined()) {
         ForOfIterator iter(cx);
         if (!iter.init(args[0]))
             return false;
         RootedValue pairVal(cx);
         RootedObject pairObj(cx);
         ValueMap *map = obj->getData();
         while (true) {
             bool done;
@@ -1795,17 +1795,17 @@ SetObject::finalize(FreeOp *fop, JSObjec
 bool
 SetObject::construct(JSContext *cx, unsigned argc, Value *vp)
 {
     Rooted<SetObject*> obj(cx, SetObject::create(cx));
     if (!obj)
         return false;
 
     CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.hasDefined(0)) {
+    if (!args.get(0).isNullOrUndefined()) {
         RootedValue keyVal(cx);
         ForOfIterator iter(cx);
         if (!iter.init(args[0]))
             return false;
         AutoHashableValueRooter key(cx);
         ValueSet *set = obj->getData();
         while (true) {
             bool done;
--- a/js/src/builtin/WeakSetObject.cpp
+++ b/js/src/builtin/WeakSetObject.cpp
@@ -90,17 +90,17 @@ WeakSetObject::construct(JSContext *cx, 
     // Based on our "Set" implementation instead of the more general ES6 steps.
     CallArgs args = CallArgsFromVp(argc, vp);
 
     if (!args.isConstructing()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_FUNCTION, "WeakSet");
         return false;
     }
 
-    if (args.hasDefined(0)) {
+    if (!args.get(0).isNullOrUndefined()) {
         RootedObject map(cx, &obj->getReservedSlot(WEAKSET_MAP_SLOT).toObject());
 
         JS::ForOfIterator iter(cx);
         if (!iter.init(args[0]))
             return false;
 
         RootedValue keyVal(cx);
         RootedObject keyObject(cx);
--- a/js/src/jit-test/tests/collections/Map-constructor-1.js
+++ b/js/src/jit-test/tests/collections/Map-constructor-1.js
@@ -1,6 +1,7 @@
 // The Map constructor creates an empty Map by default.
 
 assertEq(Map().size, 0);
 assertEq((new Map).size, 0);
 assertEq(Map(undefined).size, 0);
 assertEq(new Map(undefined).size, 0);
+assertEq(new Map(null).size, 0);
--- a/js/src/jit-test/tests/collections/Map-constructor-4.js
+++ b/js/src/jit-test/tests/collections/Map-constructor-4.js
@@ -1,6 +1,6 @@
 // Map(x) throws if x is not iterable (unless x is undefined).
 
 load(libdir + "asserts.js");
-var nonIterables = [null, true, 1, -0, 3.14, NaN, {}, Math, this];
+var nonIterables = [true, 1, -0, 3.14, NaN, {}, Math, this];
 for (let k of nonIterables)
     assertThrowsInstanceOf(function () { Map(k); }, TypeError);
--- a/js/src/jit-test/tests/collections/Set-constructor-1.js
+++ b/js/src/jit-test/tests/collections/Set-constructor-1.js
@@ -1,6 +1,7 @@
 // The Set constructor creates an empty Set by default.
 
 assertEq(Set().size, 0);
 assertEq((new Set).size, 0);
 assertEq(Set(undefined).size, 0);
 assertEq(new Set(undefined).size, 0);
+assertEq(new Set(null).size, 0);
--- a/js/src/jit-test/tests/collections/WeakMap-constructor-1.js
+++ b/js/src/jit-test/tests/collections/WeakMap-constructor-1.js
@@ -1,15 +1,12 @@
 // The WeakMap constructor creates an empty WeakMap by default.
 
 load(libdir + "asserts.js");
 
 new WeakMap();
 new WeakMap(undefined);
-
-// FIXME: bug 1092538
-// new WeakMap(null);
+new WeakMap(null);
 
 // FIXME: bug 1062075
 // assertThrowsInstanceOf(() => WeakMap(), TypeError);
 // assertThrowsInstanceOf(() => WeakMap(undefined), TypeError);
-// WeakMap(null) throws TypeError, but it's because of bug 1092538.
 // assertThrowsInstanceOf(() => WeakMap(null), TypeError);
--- a/js/src/jit-test/tests/collections/WeakMap-constructor-4.js
+++ b/js/src/jit-test/tests/collections/WeakMap-constructor-4.js
@@ -1,8 +1,6 @@
 // WeakMap(x) throws if x is not iterable (unless x is undefined).
 
 load(libdir + "asserts.js");
-// FIXME: bug 1092538
-// `new WeapMap(null)` should not throw.
-var nonIterables = [null, true, 1, -0, 3.14, NaN, {}, Math, this];
+var nonIterables = [true, 1, -0, 3.14, NaN, {}, Math, this];
 for (let k of nonIterables)
     assertThrowsInstanceOf(function () { new WeakMap(k); }, TypeError);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/collections/WeakSet-constructor-1.js
@@ -0,0 +1,11 @@
+// The WeakSet constructor creates an empty WeakSet by default.
+
+load(libdir + "asserts.js");
+
+new WeakSet();
+new WeakSet(undefined);
+new WeakSet(null);
+
+assertThrowsInstanceOf(() => WeakSet(), TypeError);
+assertThrowsInstanceOf(() => WeakSet(undefined), TypeError);
+assertThrowsInstanceOf(() => WeakSet(null), TypeError);
--- a/js/src/jit-test/tests/collections/constructor-errors.js
+++ b/js/src/jit-test/tests/collections/constructor-errors.js
@@ -3,17 +3,16 @@
 load(libdir + "asserts.js");
 
 function argsobj() { return arguments; }
 
 var misc = [
     {}, {x: 1}, Math, isNaN,
     Object.create(null),
     argsobj(0, 1, 2),
-    null,
     true, 0, 3.1416,
     new Boolean(true), new Number(0),
     {iterator: function () { return undefined; }},
     {iterator: function () { return null; }},
     {iterator: function () { return true; }},
     {iterator: function () { return 17; }},
 ];
 
--- a/js/src/jsweakmap.cpp
+++ b/js/src/jsweakmap.cpp
@@ -522,17 +522,17 @@ static bool
 WeakMap_construct(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     RootedObject obj(cx, NewBuiltinClassInstance(cx, &WeakMapObject::class_));
     if (!obj)
         return false;
 
     // ES6 23.3.1.1 steps 5-6, 11.
-    if (args.hasDefined(0)) {
+    if (!args.get(0).isNullOrUndefined()) {
         // Steps 7d-e.
         JS::ForOfIterator iter(cx);
         if (!iter.init(args[0]))
             return false;
 
         RootedValue pairVal(cx);
         RootedObject pairObject(cx);
         RootedValue keyVal(cx);