Bug 1055472 - Part 10: Make the Set constructor properly subclassable. (r=Waldo)

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

View File

@ -1068,19 +1068,19 @@ SetObject::add(JSContext* cx, HandleObject obj, HandleValue k)
}
SetObject*
SetObject::create(JSContext* cx)
SetObject::create(JSContext* cx, HandleObject proto /* = nullptr */)
{
SetObject* obj = NewBuiltinClassInstance<SetObject>(cx);
if (!obj)
return nullptr;
ValueSet* set = cx->new_<ValueSet>(cx->runtime());
auto set = cx->make_unique<ValueSet>(cx->runtime());
if (!set || !set->init()) {
js_delete(set);
ReportOutOfMemory(cx);
return nullptr;
}
obj->setPrivate(set);
SetObject* obj = NewObjectWithClassProto<SetObject>(cx, proto);
if (!obj)
return nullptr;
obj->setPrivate(set.release());
return obj;
}
@ -1110,7 +1110,12 @@ SetObject::construct(JSContext* cx, unsigned argc, Value* vp)
if (!ThrowIfNotConstructing(cx, args, "Set"))
return false;
Rooted<SetObject*> obj(cx, SetObject::create(cx));
RootedObject proto(cx);
RootedObject newTarget(cx, &args.newTarget().toObject());
if (!GetPrototypeFromConstructor(cx, newTarget, &proto))
return false;
Rooted<SetObject*> obj(cx, SetObject::create(cx, proto));
if (!obj)
return false;

View File

@ -181,7 +181,7 @@ class SetObject : public NativeObject {
// Publicly exposed Set calls for JSAPI access (webidl maplike/setlike
// interfaces, etc.)
static SetObject* create(JSContext *cx);
static SetObject* create(JSContext *cx, HandleObject proto = nullptr);
static uint32_t size(JSContext *cx, HandleObject obj);
static bool has(JSContext *cx, HandleObject obj, HandleValue key, bool* rval);
static bool clear(JSContext *cx, HandleObject obj);

View File

@ -33,6 +33,7 @@ testBuiltin(RegExp);
testBuiltin(RegExp, /Regexp Argument/);
testBuiltin(RegExp, "String Argument");
testBuiltin(Map);
testBuiltin(Set);
`;