Bug 1108930 - Part 7: Warn when Map/Set/WeakMap are called without new. r=evilpie
authorTooru Fujisawa <arai_a@mac.com>
Thu, 05 Feb 2015 00:59:16 +0900
changeset 227459 2c896a4f15ae37b72879bf1c022a87ccb85c5fcc
parent 227458 798dc45a56108aea24215de76990d5b406182e6e
child 227460 8c11a58bf243d0aa5bea99bdc65b6250be3d01cc
push id55126
push userarai_a@mac.com
push dateWed, 04 Feb 2015 16:00:49 +0000
treeherdermozilla-inbound@2c896a4f15ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1108930
milestone38.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 1108930 - Part 7: Warn when Map/Set/WeakMap are called without new. r=evilpie
js/src/builtin/MapObject.cpp
js/src/jit-test/tests/collections/Map-constructor-1.js
js/src/jit-test/tests/collections/Set-constructor-1.js
js/src/jit-test/tests/collections/WeakMap-constructor-1.js
js/src/jsweakmap.cpp
--- a/js/src/builtin/MapObject.cpp
+++ b/js/src/builtin/MapObject.cpp
@@ -1221,16 +1221,21 @@ 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);
+
+    // FIXME: bug 1083752
+    if (!WarnIfNotConstructing(cx, args, "Map"))
+        return false;
+
     if (!args.get(0).isNullOrUndefined()) {
         RootedValue adderVal(cx);
         if (!GetProperty(cx, obj, obj, cx->names().set, &adderVal))
             return false;
 
         if (!IsCallable(adderVal))
             return ReportIsNotFunction(cx, adderVal);
 
@@ -1865,16 +1870,21 @@ 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);
+
+    // FIXME: bug 1083752
+    if (!WarnIfNotConstructing(cx, args, "Set"))
+        return false;
+
     if (!args.get(0).isNullOrUndefined()) {
         RootedValue adderVal(cx);
         if (!GetProperty(cx, obj, obj, cx->names().add, &adderVal))
             return false;
 
         if (!IsCallable(adderVal))
             return ReportIsNotFunction(cx, adderVal);
 
--- a/js/src/jit-test/tests/collections/Map-constructor-1.js
+++ b/js/src/jit-test/tests/collections/Map-constructor-1.js
@@ -1,8 +1,17 @@
 // The Map constructor creates an empty Map by default.
 
+load(libdir + "asserts.js");
+
 var m = new Map();
 assertEq(m.size, 0);
 m = new Map(undefined);
 assertEq(m.size, 0);
 m = new Map(null);
 assertEq(m.size, 0);
+
+// FIXME: bug 1083752
+options("werror");
+assertEq(evaluate("Map()", {catchTermination: true}), "terminated");
+// assertThrowsInstanceOf(() => Map(), TypeError);
+// assertThrowsInstanceOf(() => Map(undefined), TypeError);
+// assertThrowsInstanceOf(() => Map(null), TypeError);
--- a/js/src/jit-test/tests/collections/Set-constructor-1.js
+++ b/js/src/jit-test/tests/collections/Set-constructor-1.js
@@ -1,8 +1,17 @@
 // The Set constructor creates an empty Set by default.
 
+load(libdir + "asserts.js");
+
 var s = new Set();
 assertEq(s.size, 0);
 s = new Set(undefined);
 assertEq(s.size, 0);
 s = new Set(null);
 assertEq(s.size, 0);
+
+// FIXME: bug 1083752
+options("werror");
+assertEq(evaluate("Set()", {catchTermination: true}), "terminated");
+// assertThrowsInstanceOf(() => Set(), TypeError);
+// assertThrowsInstanceOf(() => Set(undefined), TypeError);
+// assertThrowsInstanceOf(() => Set(null), TypeError);
--- a/js/src/jit-test/tests/collections/WeakMap-constructor-1.js
+++ b/js/src/jit-test/tests/collections/WeakMap-constructor-1.js
@@ -1,12 +1,14 @@
 // The WeakMap constructor creates an empty WeakMap by default.
 
 load(libdir + "asserts.js");
 
 new WeakMap();
 new WeakMap(undefined);
 new WeakMap(null);
 
-// FIXME: bug 1062075
+// FIXME: bug 1083752
+options("werror");
+assertEq(evaluate("WeakMap()", {catchTermination: true}), "terminated");
 // assertThrowsInstanceOf(() => WeakMap(), TypeError);
 // assertThrowsInstanceOf(() => WeakMap(undefined), TypeError);
 // assertThrowsInstanceOf(() => WeakMap(null), TypeError);
--- a/js/src/jsweakmap.cpp
+++ b/js/src/jsweakmap.cpp
@@ -15,16 +15,17 @@
 #include "jswrapper.h"
 
 #include "vm/GlobalObject.h"
 #include "vm/WeakMapObject.h"
 
 #include "jsobjinlines.h"
 
 #include "vm/Interpreter-inl.h"
+#include "vm/NativeObject-inl.h"
 
 using namespace js;
 using namespace js::gc;
 
 WeakMapBase::WeakMapBase(JSObject *memOf, JSCompartment *c)
   : memberOf(memOf),
     compartment(c),
     next(WeakMapNotInList),
@@ -521,17 +522,22 @@ JS::SetWeakMapEntry(JSContext *cx, Handl
 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.
+    // ES6 draft rev 31 (15 Jan 2015) 23.3.1.1 step 1.
+    // FIXME: bug 1083752
+    if (!WarnIfNotConstructing(cx, args, "WeakMap"))
+        return false;
+
+    // Steps 5-6, 11.
     if (!args.get(0).isNullOrUndefined()) {
         // Steps 7a-b.
         RootedValue adderVal(cx);
         if (!GetProperty(cx, obj, obj, cx->names().set, &adderVal))
             return false;
 
         // Step 7c.
         if (!IsCallable(adderVal))