Bug 1007285 - Length property of the (Weak){Map,Set} constructors should be 1; r=jorendorff
authorArpad Borsos <arpad.borsos@googlemail.com>
Fri, 09 May 2014 10:00:48 +0200
changeset 182824 e2e131ffc4379d3950c6bfc11dd5f7287039bf8e
parent 182823 b57bec9cf79fff0f6d5ff70e1f89ebbb0b395d93
child 182890 86a6a4a5862eaa41bae7ebfe91f3af9630fabbd6
push id43405
push userarpad.borsos@googlemail.com
push dateTue, 13 May 2014 10:08:06 +0000
treeherdermozilla-inbound@e2e131ffc437 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1007285
milestone32.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 1007285 - Length property of the (Weak){Map,Set} constructors should be 1; r=jorendorff
js/src/builtin/MapObject.cpp
js/src/jit-test/tests/collections/Map-surfaces-1.js
js/src/jit-test/tests/collections/Set-surfaces-1.js
js/src/jit-test/tests/collections/WeakMap-surfaces.js
js/src/jsweakmap.cpp
--- a/js/src/builtin/MapObject.cpp
+++ b/js/src/builtin/MapObject.cpp
@@ -1043,17 +1043,17 @@ static JSObject *
 InitClass(JSContext *cx, Handle<GlobalObject*> global, const Class *clasp, JSProtoKey key, Native construct,
           const JSPropertySpec *properties, const JSFunctionSpec *methods)
 {
     Rooted<JSObject*> proto(cx, global->createBlankPrototype(cx, clasp));
     if (!proto)
         return nullptr;
     proto->setPrivate(nullptr);
 
-    Rooted<JSFunction*> ctor(cx, global->createConstructor(cx, construct, ClassName(key, cx), 0));
+    Rooted<JSFunction*> ctor(cx, global->createConstructor(cx, construct, ClassName(key, cx), 1));
     if (!ctor ||
         !LinkConstructorAndPrototype(cx, ctor, proto) ||
         !DefinePropertiesAndBrand(cx, proto, properties, methods) ||
         !GlobalObject::initBuiltinConstructor(cx, global, key, ctor, proto))
     {
         return nullptr;
     }
     return proto;
--- a/js/src/jit-test/tests/collections/Map-surfaces-1.js
+++ b/js/src/jit-test/tests/collections/Map-surfaces-1.js
@@ -4,17 +4,17 @@ load(libdir + "iteration.js");
 
 var desc = Object.getOwnPropertyDescriptor(this, "Map");
 assertEq(desc.enumerable, false);
 assertEq(desc.configurable, true);
 assertEq(desc.writable, true);
 
 assertEq(typeof Map, 'function');
 assertEq(Object.keys(Map).length, 0);
-assertEq(Map.length, 0);
+assertEq(Map.length, 1);
 assertEq(Map.name, "Map");
 
 assertEq(Object.getPrototypeOf(Map.prototype), Object.prototype);
 assertEq(Object.prototype.toString.call(Map.prototype), "[object Map]");
 assertEq(Object.prototype.toString.call(new Map), "[object Map]");
 assertEq(Object.prototype.toString.call(Map()), "[object Map]");
 assertEq(Object.keys(Map.prototype).join(), "");
 assertEq(Map.prototype.constructor, Map);
--- a/js/src/jit-test/tests/collections/Set-surfaces-1.js
+++ b/js/src/jit-test/tests/collections/Set-surfaces-1.js
@@ -4,17 +4,17 @@ load(libdir + "iteration.js");
 
 var desc = Object.getOwnPropertyDescriptor(this, "Set");
 assertEq(desc.enumerable, false);
 assertEq(desc.configurable, true);
 assertEq(desc.writable, true);
 
 assertEq(typeof Set, 'function');
 assertEq(Object.keys(Set).length, 0);
-assertEq(Set.length, 0);
+assertEq(Set.length, 1);
 assertEq(Set.name, "Set");
 
 assertEq(Object.getPrototypeOf(Set.prototype), Object.prototype);
 assertEq(Object.prototype.toString.call(Set.prototype), "[object Set]");
 assertEq(Object.prototype.toString.call(new Set), "[object Set]");
 assertEq(Object.prototype.toString.call(Set()), "[object Set]");
 assertEq(Object.keys(Set.prototype).join(), "");
 assertEq(Set.prototype.constructor, Set);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/collections/WeakMap-surfaces.js
@@ -0,0 +1,35 @@
+// WeakMap surfaces
+
+var desc = Object.getOwnPropertyDescriptor(this, "WeakMap");
+assertEq(desc.enumerable, false);
+assertEq(desc.configurable, true);
+assertEq(desc.writable, true);
+
+assertEq(typeof WeakMap, 'function');
+assertEq(Object.keys(WeakMap).length, 0);
+assertEq(WeakMap.length, 1);
+assertEq(WeakMap.name, "WeakMap");
+
+assertEq(Object.getPrototypeOf(WeakMap.prototype), Object.prototype);
+assertEq(Object.prototype.toString.call(WeakMap.prototype), "[object WeakMap]");
+assertEq(Object.prototype.toString.call(new WeakMap), "[object WeakMap]");
+assertEq(Object.prototype.toString.call(WeakMap()), "[object WeakMap]");
+assertEq(Object.keys(WeakMap.prototype).join(), "");
+assertEq(WeakMap.prototype.constructor, WeakMap);
+
+function checkMethod(name, arity) { 
+    var desc = Object.getOwnPropertyDescriptor(WeakMap.prototype, name);
+    assertEq(desc.enumerable, false);
+    assertEq(desc.configurable, true);
+    assertEq(desc.writable, true);
+    assertEq(typeof desc.value, 'function');
+    assertEq(desc.value.name, name);
+    assertEq(desc.value.length, arity);
+}
+
+// XXX: WeakMap#get implementation has an undocumented 2nd argument
+//checkMethod("get", 1);
+checkMethod("has", 1);
+checkMethod("set", 2);
+checkMethod("delete", 1);
+checkMethod("clear", 0);
--- a/js/src/jsweakmap.cpp
+++ b/js/src/jsweakmap.cpp
@@ -495,17 +495,17 @@ js_InitWeakMapClass(JSContext *cx, Handl
 
     Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
 
     RootedObject weakMapProto(cx, global->createBlankPrototype(cx, &WeakMapObject::class_));
     if (!weakMapProto)
         return nullptr;
 
     RootedFunction ctor(cx, global->createConstructor(cx, WeakMap_construct,
-                                                      cx->names().WeakMap, 0));
+                                                      cx->names().WeakMap, 1));
     if (!ctor)
         return nullptr;
 
     if (!LinkConstructorAndPrototype(cx, ctor, weakMapProto))
         return nullptr;
 
     if (!DefinePropertiesAndBrand(cx, weakMapProto, nullptr, weak_map_methods))
         return nullptr;