Bug 1055473 - Make WeakMap/Set.prototype a plain object. r=Waldo

This commit is contained in:
Tom Schuster 2015-05-08 23:27:50 +02:00
parent bb2e6d29aa
commit 5cfbfd9938
5 changed files with 14 additions and 16 deletions

View File

@ -3,5 +3,6 @@
"WeakMap.prototype.delete.length": true,
"WeakMap.prototype.get.length": true,
"WeakMap.prototype.has.length": true,
"WeakMap.prototype.set.length": true
"WeakMap.prototype.set.length": true,
"WeakMap.prototype.@@toStringTag": true
}

View File

@ -45,11 +45,9 @@ JSObject*
WeakSetObject::initClass(JSContext* cx, JSObject* obj)
{
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
// Todo: WeakSet.prototype should not be a WeakSet!
Rooted<WeakSetObject*> proto(cx, global->createBlankPrototype<WeakSetObject>(cx));
RootedPlainObject proto(cx, NewBuiltinClassInstance<PlainObject>(cx));
if (!proto)
return nullptr;
proto->setReservedSlot(WEAKSET_MAP_SLOT, UndefinedValue());
Rooted<JSFunction*> ctor(cx, global->createConstructor(cx, construct, ClassName(JSProto_WeakSet, cx), 0));
if (!ctor ||

View File

@ -11,12 +11,12 @@ assertEq(WeakMap.length, 0);
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(WeakMap.prototype), "[object Object]");
assertEq(Object.prototype.toString.call(new WeakMap()), "[object WeakMap]");
assertEq(Object.keys(WeakMap.prototype).join(), "");
assertEq(WeakMap.prototype.constructor, WeakMap);
function checkMethod(name, arity) {
function checkMethod(name, arity) {
var desc = Object.getOwnPropertyDescriptor(WeakMap.prototype, name);
assertEq(desc.enumerable, false);
assertEq(desc.configurable, true);
@ -26,8 +26,7 @@ function checkMethod(name, arity) {
assertEq(desc.value.length, arity);
}
// XXX: WeakMap#get implementation has an undocumented 2nd argument
//checkMethod("get", 1);
checkMethod("get", 1);
checkMethod("has", 1);
checkMethod("set", 2);
checkMethod("delete", 1);

View File

@ -11,7 +11,7 @@ assertEq(WeakSet.length, 0);
assertEq(WeakSet.name, "WeakSet");
assertEq(Object.getPrototypeOf(WeakSet.prototype), Object.prototype);
assertEq(Object.prototype.toString.call(WeakSet.prototype), "[object WeakSet]");
assertEq(Object.prototype.toString.call(WeakSet.prototype), "[object Object]");
assertEq(Object.prototype.toString.call(new WeakSet), "[object WeakSet]");
assertEq(Object.keys(WeakSet.prototype).length, 0);
assertEq(WeakSet.prototype.constructor, WeakSet);

View File

@ -627,7 +627,7 @@ const Class WeakMapObject::class_ = {
static const JSFunctionSpec weak_map_methods[] = {
JS_FN("has", WeakMap_has, 1, 0),
JS_FN("get", WeakMap_get, 2, 0),
JS_FN("get", WeakMap_get, 1, 0),
JS_FN("delete", WeakMap_delete, 1, 0),
JS_FN("set", WeakMap_set, 2, 0),
JS_FN("clear", WeakMap_clear, 0, 0),
@ -641,8 +641,8 @@ InitWeakMapClass(JSContext* cx, HandleObject obj, bool defineMembers)
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject weakMapProto(cx, global->createBlankPrototype(cx, &WeakMapObject::class_));
if (!weakMapProto)
RootedPlainObject proto(cx, NewBuiltinClassInstance<PlainObject>(cx));
if (!proto)
return nullptr;
RootedFunction ctor(cx, global->createConstructor(cx, WeakMap_construct,
@ -650,17 +650,17 @@ InitWeakMapClass(JSContext* cx, HandleObject obj, bool defineMembers)
if (!ctor)
return nullptr;
if (!LinkConstructorAndPrototype(cx, ctor, weakMapProto))
if (!LinkConstructorAndPrototype(cx, ctor, proto))
return nullptr;
if (defineMembers) {
if (!DefinePropertiesAndFunctions(cx, weakMapProto, nullptr, weak_map_methods))
if (!DefinePropertiesAndFunctions(cx, proto, nullptr, weak_map_methods))
return nullptr;
}
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_WeakMap, ctor, weakMapProto))
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_WeakMap, ctor, proto))
return nullptr;
return weakMapProto;
return proto;
}
JSObject*