mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 1932305 part 10 - Improve MapObject::getKeysAndValuesInterleaved and SetObject::keys. r=iain
Differential Revision: https://phabricator.services.mozilla.com/D229606
This commit is contained in:
parent
45cac65160
commit
83cdf0070b
@ -579,12 +579,11 @@ template <typename ObjectT>
|
||||
}
|
||||
|
||||
bool MapObject::getKeysAndValuesInterleaved(
|
||||
HandleObject obj, JS::MutableHandle<GCVector<JS::Value>> entries) {
|
||||
MapObject* mapObj = &obj->as<MapObject>();
|
||||
JS::MutableHandle<GCVector<JS::Value>> entries) {
|
||||
auto appendEntry = [&entries](auto& entry) {
|
||||
return entries.append(entry.key.get()) && entries.append(entry.value);
|
||||
};
|
||||
return Table(mapObj).forEachEntry(appendEntry);
|
||||
return Table(this).forEachEntry(appendEntry);
|
||||
}
|
||||
|
||||
bool MapObject::set(JSContext* cx, const Value& key, const Value& val) {
|
||||
@ -1242,11 +1241,9 @@ const JSPropertySpec SetObject::staticProperties[] = {
|
||||
return NativeDefineDataProperty(cx, nativeProto, iteratorId, valuesFn, 0);
|
||||
}
|
||||
|
||||
bool SetObject::keys(JSContext* cx, HandleObject obj,
|
||||
JS::MutableHandle<GCVector<JS::Value>> keys) {
|
||||
SetObject* setObj = &obj->as<SetObject>();
|
||||
bool SetObject::keys(JS::MutableHandle<GCVector<JS::Value>> keys) {
|
||||
auto appendEntry = [&keys](auto& entry) { return keys.append(entry.get()); };
|
||||
return Table(setObj).forEachEntry(appendEntry);
|
||||
return Table(this).forEachEntry(appendEntry);
|
||||
}
|
||||
|
||||
bool SetObject::add(JSContext* cx, const Value& key) {
|
||||
|
@ -141,8 +141,8 @@ class MapObject : public OrderedHashMapObject {
|
||||
static const JSClass class_;
|
||||
static const JSClass protoClass_;
|
||||
|
||||
[[nodiscard]] static bool getKeysAndValuesInterleaved(
|
||||
HandleObject obj, JS::MutableHandle<GCVector<JS::Value>> entries);
|
||||
[[nodiscard]] bool getKeysAndValuesInterleaved(
|
||||
JS::MutableHandle<GCVector<JS::Value>> entries);
|
||||
[[nodiscard]] static bool entries(JSContext* cx, unsigned argc, Value* vp);
|
||||
static MapObject* createWithProto(JSContext* cx, HandleObject proto,
|
||||
NewObjectKind newKind);
|
||||
@ -269,8 +269,7 @@ class SetObject : public OrderedHashSetObject {
|
||||
static const JSClass class_;
|
||||
static const JSClass protoClass_;
|
||||
|
||||
[[nodiscard]] static bool keys(JSContext* cx, HandleObject obj,
|
||||
JS::MutableHandle<GCVector<JS::Value>> keys);
|
||||
[[nodiscard]] bool keys(JS::MutableHandle<GCVector<JS::Value>> keys);
|
||||
[[nodiscard]] static bool values(JSContext* cx, unsigned argc, Value* vp);
|
||||
[[nodiscard]] bool add(JSContext* cx, const Value& key);
|
||||
|
||||
|
@ -1740,10 +1740,10 @@ bool JSStructuredCloneWriter::traverseMap(HandleObject obj) {
|
||||
Rooted<GCVector<Value>> newEntries(context(), GCVector<Value>(context()));
|
||||
{
|
||||
// If there is no wrapper, the compartment munging is a no-op.
|
||||
RootedObject unwrapped(context(), obj->maybeUnwrapAs<MapObject>());
|
||||
Rooted<MapObject*> unwrapped(context(), obj->maybeUnwrapAs<MapObject>());
|
||||
MOZ_ASSERT(unwrapped);
|
||||
JSAutoRealm ar(context(), unwrapped);
|
||||
if (!MapObject::getKeysAndValuesInterleaved(unwrapped, &newEntries)) {
|
||||
if (!unwrapped->getKeysAndValuesInterleaved(&newEntries)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1775,10 +1775,10 @@ bool JSStructuredCloneWriter::traverseSet(HandleObject obj) {
|
||||
Rooted<GCVector<Value>> keys(context(), GCVector<Value>(context()));
|
||||
{
|
||||
// If there is no wrapper, the compartment munging is a no-op.
|
||||
RootedObject unwrapped(context(), obj->maybeUnwrapAs<SetObject>());
|
||||
Rooted<SetObject*> unwrapped(context(), obj->maybeUnwrapAs<SetObject>());
|
||||
MOZ_ASSERT(unwrapped);
|
||||
JSAutoRealm ar(context(), unwrapped);
|
||||
if (!SetObject::keys(context(), unwrapped, &keys)) {
|
||||
if (!unwrapped->keys(&keys)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user