mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1055472 - Part 12: Mae the WeakSet constructor properly subclassable. (r=Waldo)
This commit is contained in:
parent
e967b9db61
commit
7fb0f6f830
@ -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());
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
@ -35,6 +35,7 @@ testBuiltin(RegExp, "String Argument");
|
||||
testBuiltin(Map);
|
||||
testBuiltin(Set);
|
||||
testBuiltin(WeakMap);
|
||||
testBuiltin(WeakSet);
|
||||
|
||||
`;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user