diff --git a/js/src/builtin/WeakSetObject.cpp b/js/src/builtin/WeakSetObject.cpp index 35fb216e144d..6ae866c236da 100644 --- a/js/src/builtin/WeakSetObject.cpp +++ b/js/src/builtin/WeakSetObject.cpp @@ -61,14 +61,14 @@ WeakSetObject::initClass(JSContext* cx, JSObject* obj) } WeakSetObject* -WeakSetObject::create(JSContext* cx) +WeakSetObject::create(JSContext* cx, HandleObject proto /* = nullptr */) { - Rooted obj(cx, NewBuiltinClassInstance(cx)); - if (!obj) + RootedObject map(cx, NewBuiltinClassInstance(cx)); + if (!map) return nullptr; - RootedObject map(cx, JS::NewWeakMapObject(cx)); - if (!map) + WeakSetObject* obj = NewObjectWithClassProto(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 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 obj(cx, WeakSetObject::create(cx, proto)); + if (!obj) + return false; + if (!args.get(0).isNullOrUndefined()) { RootedObject map(cx, &obj->getReservedSlot(WEAKSET_MAP_SLOT).toObject()); diff --git a/js/src/builtin/WeakSetObject.h b/js/src/builtin/WeakSetObject.h index 308b67e67fc4..9aa4fc51d63d 100644 --- a/js/src/builtin/WeakSetObject.h +++ b/js/src/builtin/WeakSetObject.h @@ -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); }; diff --git a/js/src/tests/ecma_6/Class/extendBuiltinConstructors.js b/js/src/tests/ecma_6/Class/extendBuiltinConstructors.js index 364dee0ca4e2..4c3e8ed7fbb5 100644 --- a/js/src/tests/ecma_6/Class/extendBuiltinConstructors.js +++ b/js/src/tests/ecma_6/Class/extendBuiltinConstructors.js @@ -35,6 +35,7 @@ testBuiltin(RegExp, "String Argument"); testBuiltin(Map); testBuiltin(Set); testBuiltin(WeakMap); +testBuiltin(WeakSet); `;