mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 04:41:11 +00:00
Bug 1932305 part 6 - Improve MapObject::has and SetObject::has. r=iain
Differential Revision: https://phabricator.services.mozilla.com/D229602
This commit is contained in:
parent
0fbf29217c
commit
188a1749b7
@ -843,26 +843,24 @@ bool MapObject::get(JSContext* cx, unsigned argc, Value* vp) {
|
||||
return CallNonGenericMethod<MapObject::is, MapObject::get_impl>(cx, args);
|
||||
}
|
||||
|
||||
bool MapObject::has(JSContext* cx, HandleObject obj, HandleValue key,
|
||||
bool* rval) {
|
||||
Rooted<HashableValue> k(cx);
|
||||
|
||||
bool MapObject::has(JSContext* cx, const Value& key, bool* rval) {
|
||||
HashableValue k;
|
||||
if (!k.setValue(cx, key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*rval = Table(&obj->as<MapObject>()).has(k);
|
||||
*rval = Table(this).has(k);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapObject::has_impl(JSContext* cx, const CallArgs& args) {
|
||||
auto* mapObj = &args.thisv().toObject().as<MapObject>();
|
||||
bool found;
|
||||
RootedObject obj(cx, &args.thisv().toObject());
|
||||
if (has(cx, obj, args.get(0), &found)) {
|
||||
args.rval().setBoolean(found);
|
||||
return true;
|
||||
if (!mapObj->has(cx, args.get(0), &found)) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
args.rval().setBoolean(found);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapObject::has(JSContext* cx, unsigned argc, Value* vp) {
|
||||
@ -1511,26 +1509,22 @@ bool SetObject::size(JSContext* cx, unsigned argc, Value* vp) {
|
||||
}
|
||||
|
||||
bool SetObject::has_impl(JSContext* cx, const CallArgs& args) {
|
||||
MOZ_ASSERT(is(args.thisv()));
|
||||
|
||||
ARG0_KEY(cx, args, key);
|
||||
SetObject* setObj = &args.thisv().toObject().as<SetObject>();
|
||||
args.rval().setBoolean(Table(setObj).has(key));
|
||||
auto* setObj = &args.thisv().toObject().as<SetObject>();
|
||||
bool found;
|
||||
if (!setObj->has(cx, args.get(0), &found)) {
|
||||
return false;
|
||||
}
|
||||
args.rval().setBoolean(found);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetObject::has(JSContext* cx, HandleObject obj, HandleValue key,
|
||||
bool* rval) {
|
||||
MOZ_ASSERT(SetObject::is(obj));
|
||||
|
||||
Rooted<HashableValue> k(cx);
|
||||
|
||||
bool SetObject::has(JSContext* cx, const Value& key, bool* rval) {
|
||||
HashableValue k;
|
||||
if (!k.setValue(cx, key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SetObject* setObj = &obj->as<SetObject>();
|
||||
*rval = Table(setObj).has(k);
|
||||
*rval = Table(this).has(k);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1769,7 +1763,7 @@ JS_PUBLIC_API bool JS::MapHas(JSContext* cx, HandleObject obj, HandleValue key,
|
||||
cx->check(obj, key);
|
||||
|
||||
if (obj->is<MapObject>()) {
|
||||
return MapObject::has(cx, obj.as<MapObject>(), key, rval);
|
||||
return obj.as<MapObject>()->has(cx, key, rval);
|
||||
}
|
||||
|
||||
AutoEnterTableRealm<MapObject> enter(cx, obj);
|
||||
@ -1777,7 +1771,7 @@ JS_PUBLIC_API bool JS::MapHas(JSContext* cx, HandleObject obj, HandleValue key,
|
||||
if (!JS_WrapValue(cx, &wrappedKey)) {
|
||||
return false;
|
||||
}
|
||||
return MapObject::has(cx, enter.unwrapped(), wrappedKey, rval);
|
||||
return enter.unwrapped()->has(cx, wrappedKey, rval);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API bool JS::MapDelete(JSContext* cx, HandleObject obj,
|
||||
@ -1893,7 +1887,7 @@ JS_PUBLIC_API bool JS::SetHas(JSContext* cx, HandleObject obj, HandleValue key,
|
||||
cx->check(obj, key);
|
||||
|
||||
if (obj->is<SetObject>()) {
|
||||
return SetObject::has(cx, obj.as<SetObject>(), key, rval);
|
||||
return obj.as<SetObject>()->has(cx, key, rval);
|
||||
}
|
||||
|
||||
AutoEnterTableRealm<SetObject> enter(cx, obj);
|
||||
@ -1901,7 +1895,7 @@ JS_PUBLIC_API bool JS::SetHas(JSContext* cx, HandleObject obj, HandleValue key,
|
||||
if (!JS_WrapValue(cx, &wrappedKey)) {
|
||||
return false;
|
||||
}
|
||||
return SetObject::has(cx, enter.unwrapped(), wrappedKey, rval);
|
||||
return enter.unwrapped()->has(cx, wrappedKey, rval);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API bool JS::SetDelete(JSContext* cx, HandleObject obj,
|
||||
|
@ -153,8 +153,7 @@ class MapObject : public OrderedHashMapObject {
|
||||
uint32_t size();
|
||||
[[nodiscard]] bool get(JSContext* cx, const Value& key,
|
||||
MutableHandleValue rval);
|
||||
[[nodiscard]] static bool has(JSContext* cx, HandleObject obj,
|
||||
HandleValue key, bool* rval);
|
||||
[[nodiscard]] bool has(JSContext* cx, const Value& key, bool* rval);
|
||||
[[nodiscard]] static bool delete_(JSContext* cx, HandleObject obj,
|
||||
HandleValue key, bool* rval);
|
||||
|
||||
@ -286,8 +285,7 @@ class SetObject : public OrderedHashSetObject {
|
||||
[[nodiscard]] static bool size(JSContext* cx, unsigned argc, Value* vp);
|
||||
[[nodiscard]] static bool add(JSContext* cx, unsigned argc, Value* vp);
|
||||
[[nodiscard]] static bool has(JSContext* cx, unsigned argc, Value* vp);
|
||||
[[nodiscard]] static bool has(JSContext* cx, HandleObject obj,
|
||||
HandleValue key, bool* rval);
|
||||
[[nodiscard]] bool has(JSContext* cx, const Value& key, bool* rval);
|
||||
void clear(JSContext* cx);
|
||||
[[nodiscard]] static bool iterator(JSContext* cx, IteratorKind kind,
|
||||
HandleObject obj, MutableHandleValue iter);
|
||||
|
@ -10475,7 +10475,7 @@ bool CacheIRCompiler::emitSetHasResult(ObjOperandId setId, ValOperandId valId) {
|
||||
masm.Push(val);
|
||||
masm.Push(set);
|
||||
|
||||
using Fn = bool (*)(JSContext*, HandleObject, HandleValue, bool*);
|
||||
using Fn = bool (*)(JSContext*, Handle<SetObject*>, HandleValue, bool*);
|
||||
callvm.call<Fn, jit::SetObjectHas>();
|
||||
return true;
|
||||
}
|
||||
@ -10608,7 +10608,7 @@ bool CacheIRCompiler::emitMapHasResult(ObjOperandId mapId, ValOperandId valId) {
|
||||
masm.Push(val);
|
||||
masm.Push(map);
|
||||
|
||||
using Fn = bool (*)(JSContext*, HandleObject, HandleValue, bool*);
|
||||
using Fn = bool (*)(JSContext*, Handle<MapObject*>, HandleValue, bool*);
|
||||
callvm.call<Fn, jit::MapObjectHas>();
|
||||
return true;
|
||||
}
|
||||
|
@ -21663,7 +21663,7 @@ void CodeGenerator::visitSetObjectHasValueVMCall(
|
||||
pushArg(ToValue(ins, LSetObjectHasValueVMCall::InputIndex));
|
||||
pushArg(ToRegister(ins->setObject()));
|
||||
|
||||
using Fn = bool (*)(JSContext*, HandleObject, HandleValue, bool*);
|
||||
using Fn = bool (*)(JSContext*, Handle<SetObject*>, HandleValue, bool*);
|
||||
callVM<Fn, jit::SetObjectHas>(ins);
|
||||
}
|
||||
|
||||
@ -21718,7 +21718,7 @@ void CodeGenerator::visitMapObjectHasValueVMCall(
|
||||
pushArg(ToValue(ins, LMapObjectHasValueVMCall::InputIndex));
|
||||
pushArg(ToRegister(ins->mapObject()));
|
||||
|
||||
using Fn = bool (*)(JSContext*, HandleObject, HandleValue, bool*);
|
||||
using Fn = bool (*)(JSContext*, Handle<MapObject*>, HandleValue, bool*);
|
||||
callVM<Fn, jit::MapObjectHas>(ins);
|
||||
}
|
||||
|
||||
|
@ -3110,14 +3110,14 @@ JSAtom* AtomizeStringNoGC(JSContext* cx, JSString* str) {
|
||||
return atom;
|
||||
}
|
||||
|
||||
bool SetObjectHas(JSContext* cx, HandleObject obj, HandleValue key,
|
||||
bool SetObjectHas(JSContext* cx, Handle<SetObject*> obj, HandleValue key,
|
||||
bool* rval) {
|
||||
return SetObject::has(cx, obj, key, rval);
|
||||
return obj->has(cx, key, rval);
|
||||
}
|
||||
|
||||
bool MapObjectHas(JSContext* cx, HandleObject obj, HandleValue key,
|
||||
bool MapObjectHas(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
|
||||
bool* rval) {
|
||||
return MapObject::has(cx, obj, key, rval);
|
||||
return obj->has(cx, key, rval);
|
||||
}
|
||||
|
||||
bool MapObjectGet(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
|
||||
|
@ -703,8 +703,10 @@ void DateFillLocalTimeSlots(DateObject* dateObj);
|
||||
|
||||
JSAtom* AtomizeStringNoGC(JSContext* cx, JSString* str);
|
||||
|
||||
bool SetObjectHas(JSContext* cx, HandleObject obj, HandleValue key, bool* rval);
|
||||
bool MapObjectHas(JSContext* cx, HandleObject obj, HandleValue key, bool* rval);
|
||||
bool SetObjectHas(JSContext* cx, Handle<SetObject*> obj, HandleValue key,
|
||||
bool* rval);
|
||||
bool MapObjectHas(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
|
||||
bool* rval);
|
||||
bool MapObjectGet(JSContext* cx, Handle<MapObject*> obj, HandleValue key,
|
||||
MutableHandleValue rval);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user