mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1055472 - Part 9: Make the Map constructor properly subclassable. (r=Waldo)
This commit is contained in:
parent
4d1188e13f
commit
b9652b074b
@ -221,7 +221,7 @@ MapIteratorObject::next(JSContext* cx, Handle<MapIteratorObject*> mapIterator,
|
||||
|
||||
const Class MapObject::class_ = {
|
||||
"Map",
|
||||
JSCLASS_HAS_PRIVATE |
|
||||
JSCLASS_HAS_PRIVATE |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Map),
|
||||
nullptr, // addProperty
|
||||
nullptr, // delProperty
|
||||
@ -412,21 +412,20 @@ MapObject::set(JSContext* cx, HandleObject obj, HandleValue k, HandleValue v)
|
||||
}
|
||||
|
||||
MapObject*
|
||||
MapObject::create(JSContext* cx)
|
||||
MapObject::create(JSContext* cx, HandleObject proto /* = nullptr */)
|
||||
{
|
||||
Rooted<MapObject*> obj(cx, NewBuiltinClassInstance<MapObject>(cx));
|
||||
if (!obj)
|
||||
return nullptr;
|
||||
|
||||
ValueMap* map = cx->new_<ValueMap>(cx->runtime());
|
||||
auto map = cx->make_unique<ValueMap>(cx->runtime());
|
||||
if (!map || !map->init()) {
|
||||
js_delete(map);
|
||||
ReportOutOfMemory(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
obj->setPrivate(map);
|
||||
return obj;
|
||||
MapObject* mapObj = NewObjectWithClassProto<MapObject>(cx, proto);
|
||||
if (!mapObj)
|
||||
return nullptr;
|
||||
|
||||
mapObj->setPrivate(map.release());
|
||||
return mapObj;
|
||||
}
|
||||
|
||||
void
|
||||
@ -444,7 +443,12 @@ MapObject::construct(JSContext* cx, unsigned argc, Value* vp)
|
||||
if (!ThrowIfNotConstructing(cx, args, "Map"))
|
||||
return false;
|
||||
|
||||
Rooted<MapObject*> obj(cx, MapObject::create(cx));
|
||||
RootedObject proto(cx);
|
||||
RootedObject newTarget(cx, &args.newTarget().toObject());
|
||||
if (!GetPrototypeFromConstructor(cx, newTarget, &proto))
|
||||
return false;
|
||||
|
||||
Rooted<MapObject*> obj(cx, MapObject::create(cx, proto));
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
|
@ -92,7 +92,7 @@ class MapObject : public NativeObject {
|
||||
JS::AutoValueVector* entries);
|
||||
static bool entries(JSContext* cx, unsigned argc, Value* vp);
|
||||
static bool has(JSContext* cx, unsigned argc, Value* vp);
|
||||
static MapObject* create(JSContext* cx);
|
||||
static MapObject* create(JSContext* cx, HandleObject proto = nullptr);
|
||||
|
||||
// Publicly exposed Map calls for JSAPI access (webidl maplike/setlike
|
||||
// interfaces, etc.)
|
||||
|
@ -32,6 +32,7 @@ testBuiltin(Date, 5, 10);
|
||||
testBuiltin(RegExp);
|
||||
testBuiltin(RegExp, /Regexp Argument/);
|
||||
testBuiltin(RegExp, "String Argument");
|
||||
testBuiltin(Map);
|
||||
|
||||
`;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user