Bug 1055472 - Part 12: Mae the WeakSet constructor properly subclassable. (r=Waldo)

This commit is contained in:
Eric Faust 2015-11-13 18:22:21 -08:00
parent c2a28fcfcd
commit af73908e85
3 changed files with 16 additions and 10 deletions

View File

@ -61,14 +61,14 @@ WeakSetObject::initClass(JSContext* cx, JSObject* obj)
}
WeakSetObject*
WeakSetObject::create(JSContext* cx)
WeakSetObject::create(JSContext* cx, HandleObject proto /* = nullptr */)
{
Rooted<WeakSetObject*> obj(cx, NewBuiltinClassInstance<WeakSetObject>(cx));
if (!obj)
RootedObject map(cx, NewBuiltinClassInstance<WeakMapObject>(cx));
if (!map)
return nullptr;
RootedObject map(cx, JS::NewWeakMapObject(cx));
if (!map)
WeakSetObject* obj = NewObjectWithClassProto<WeakSetObject>(cx, proto);
if (!obj)
return nullptr;
obj->setReservedSlot(WEAKSET_MAP_SLOT, ObjectValue(*map));
@ -78,16 +78,21 @@ WeakSetObject::create(JSContext* cx)
bool
WeakSetObject::construct(JSContext* cx, unsigned argc, Value* vp)
{
Rooted<WeakSetObject*> obj(cx, WeakSetObject::create(cx));
if (!obj)
return false;
// Based on our "Set" implementation instead of the more general ES6 steps.
CallArgs args = CallArgsFromVp(argc, vp);
if (!ThrowIfNotConstructing(cx, args, "WeakSet"))
return false;
RootedObject proto(cx);
RootedObject newTarget(cx, &args.newTarget().toObject());
if (!GetPrototypeFromConstructor(cx, newTarget, &proto))
return false;
Rooted<WeakSetObject*> obj(cx, WeakSetObject::create(cx, proto));
if (!obj)
return false;
if (!args.get(0).isNullOrUndefined()) {
RootedObject map(cx, &obj->getReservedSlot(WEAKSET_MAP_SLOT).toObject());

View File

@ -23,7 +23,7 @@ class WeakSetObject : public NativeObject
static const JSPropertySpec properties[];
static const JSFunctionSpec methods[];
static WeakSetObject* create(JSContext* cx);
static WeakSetObject* create(JSContext* cx, HandleObject proto = nullptr);
static bool construct(JSContext* cx, unsigned argc, Value* vp);
};

View File

@ -35,6 +35,7 @@ testBuiltin(RegExp, "String Argument");
testBuiltin(Map);
testBuiltin(Set);
testBuiltin(WeakMap);
testBuiltin(WeakSet);
`;