mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1055472 - Part 10: Make the Set constructor properly subclassable. (r=Waldo)
This commit is contained in:
parent
7b1dd4f0df
commit
5745b31e40
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -33,6 +33,7 @@ testBuiltin(RegExp);
|
||||
testBuiltin(RegExp, /Regexp Argument/);
|
||||
testBuiltin(RegExp, "String Argument");
|
||||
testBuiltin(Map);
|
||||
testBuiltin(Set);
|
||||
|
||||
`;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user