Bug 1007285 - Length property of the (Weak){Map,Set} constructors should be 1; r=jorendorff

--HG--
extra : rebase_source : 9616ff1999c37c4ec69026b709726a09d88b03f2
This commit is contained in:
Arpad Borsos 2014-05-09 10:00:48 +02:00
parent 821f406512
commit 7a75f61b66
5 changed files with 39 additions and 4 deletions

View File

@ -1048,7 +1048,7 @@ InitClass(JSContext *cx, Handle<GlobalObject*> global, const Class *clasp, JSPro
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) ||

View File

@ -9,7 +9,7 @@ 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);

View File

@ -9,7 +9,7 @@ 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);

View File

@ -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);

View File

@ -500,7 +500,7 @@ js_InitWeakMapClass(JSContext *cx, HandleObject obj)
return nullptr;
RootedFunction ctor(cx, global->createConstructor(cx, WeakMap_construct,
cx->names().WeakMap, 0));
cx->names().WeakMap, 1));
if (!ctor)
return nullptr;