Bug 1754405 part 5 - Remove INT_FITS_IN_JSID/INT_TO_JSID. r=evilpie

Differential Revision: https://phabricator.services.mozilla.com/D138276
This commit is contained in:
Jan de Mooij 2022-02-13 12:01:45 +00:00
Родитель fd4c2058d1
Коммит e508008806
22 изменённых файлов: 41 добавлений и 43 удалений

Просмотреть файл

@ -141,7 +141,7 @@ bool AppendIndexedPropertyNames(JSContext* aCx, BrowsingContext* aContext,
}
for (int32_t i = 0; i < length; ++i) {
aIndexedProps.infallibleAppend(INT_TO_JSID(i));
aIndexedProps.infallibleAppend(JS::PropertyKey::Int(i));
}
return true;
}

Просмотреть файл

@ -1081,7 +1081,7 @@ bool nsOuterWindowProxy::AppendIndexedPropertyNames(
return false;
}
for (int32_t i = 0; i < int32_t(length); ++i) {
if (!props.append(INT_TO_JSID(i))) {
if (!props.append(JS::PropertyKey::Int(i))) {
return false;
}
}

Просмотреть файл

@ -15064,7 +15064,7 @@ class CGDOMJSProxyHandler_ownPropNames(ClassMethod):
uint32_t length = UnwrapProxy(proxy)->Length(${callerType});
MOZ_ASSERT(int32_t(length) >= 0);
for (int32_t i = 0; i < int32_t(length); ++i) {
if (!props.append(INT_TO_JSID(i))) {
if (!props.append(JS::PropertyKey::Int(i))) {
return false;
}
}

Просмотреть файл

@ -118,6 +118,14 @@ struct PropertyKey {
bool isWellKnownSymbol(JS::SymbolCode code) const;
static constexpr bool fitsInInt(int32_t i) { return i >= 0; }
static constexpr PropertyKey Int(int32_t i) {
MOZ_ASSERT(fitsInInt(i));
uint32_t bits = (static_cast<uint32_t>(i) << 1) | JSID_TYPE_INT_BIT;
return PropertyKey::fromRawBits(bits);
}
// This API can be used by embedders to convert pinned (aka interned) strings,
// as created by JS_AtomizeAndPinString, into PropertyKeys. This means the
// string does not have to be explicitly rooted.
@ -189,16 +197,6 @@ using jsid = JS::PropertyKey;
#define JSID_INT_MIN 0
#define JSID_INT_MAX INT32_MAX
static MOZ_ALWAYS_INLINE bool INT_FITS_IN_JSID(int32_t i) { return i >= 0; }
static MOZ_ALWAYS_INLINE jsid INT_TO_JSID(int32_t i) {
jsid id;
MOZ_ASSERT(INT_FITS_IN_JSID(i));
uint32_t bits = (static_cast<uint32_t>(i) << 1) | JSID_TYPE_INT_BIT;
JSID_BITS(id) = static_cast<size_t>(bits);
return id;
}
static MOZ_ALWAYS_INLINE jsid SYMBOL_TO_JSID(JS::Symbol* sym) {
jsid id;
MOZ_ASSERT(sym != nullptr);

Просмотреть файл

@ -894,7 +894,7 @@ static inline bool ObjectMayHaveExtraIndexedOwnProperties(JSObject* obj) {
}
return ClassMayResolveId(*obj->runtimeFromAnyThread()->commonNames,
obj->getClass(), INT_TO_JSID(0), obj);
obj->getClass(), PropertyKey::Int(0), obj);
}
/*
@ -1529,7 +1529,7 @@ static DenseElementResult ArrayReverseDenseKernel(JSContext* cx,
}
obj->setDenseElementHole(index);
return SuppressDeletedProperty(cx, obj, INT_TO_JSID(index));
return SuppressDeletedProperty(cx, obj, PropertyKey::Int(index));
};
RootedValue origlo(cx), orighi(cx);

Просмотреть файл

@ -1199,7 +1199,7 @@ bool BuildImmutableProperty(JSContext* cx, HandleValue value, HandleId name,
// Step 1.b.iv
for (uint32_t i = 0; i < len; i++) {
// Step 1.b.iv.1
childName.set(INT_TO_JSID(i));
childName.set(PropertyKey::Int(i));
// Step 1.b.iv.2
if (!GetProperty(cx, arr, value, childName, &childValue)) {

Просмотреть файл

@ -4108,7 +4108,7 @@ static bool ReadGeckoProfilingStack(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
idx = INT_TO_JSID(inlineFrameNo);
idx = PropertyKey::Int(inlineFrameNo);
if (!JS_DefinePropertyById(cx, inlineStack, idx, inlineFrameInfo, 0)) {
return false;
}
@ -4117,7 +4117,7 @@ static bool ReadGeckoProfilingStack(JSContext* cx, unsigned argc, Value* vp) {
}
// Push inline array into main array.
idx = INT_TO_JSID(physicalFrameNo);
idx = PropertyKey::Int(physicalFrameNo);
if (!JS_DefinePropertyById(cx, stack, idx, inlineStack, 0)) {
return false;
}
@ -4210,7 +4210,7 @@ JSObject* ShellAllocationMetadataBuilder::build(
RootedValue callee(cx);
for (NonBuiltinScriptFrameIter iter(cx); !iter.done(); ++iter) {
if (iter.isFunctionFrame() && iter.compartment() == cx->compartment()) {
id = INT_TO_JSID(stackIndex);
id = PropertyKey::Int(stackIndex);
RootedObject callee(cx, iter.callee(cx));
if (!JS_DefinePropertyById(cx, stack, id, callee, JSPROP_ENUMERATE)) {
oomUnsafe.crash("ShellAllocationMetadataBuilder::build");

Просмотреть файл

@ -1670,7 +1670,7 @@ DebuggerArguments* DebuggerArguments::create(JSContext* cx, HandleObject proto,
if (!getobj) {
return nullptr;
}
id = INT_TO_JSID(i);
id = PropertyKey::Int(i);
if (!NativeDefineAccessorProperty(cx, obj, id, getobj, nullptr,
JSPROP_ENUMERATE)) {
return nullptr;

Просмотреть файл

@ -1664,7 +1664,7 @@ bool DebuggerScript::CallData::getAllOffsets() {
RootedObject offsets(cx);
RootedValue offsetsv(cx);
RootedId id(cx, INT_TO_JSID(lineno));
RootedId id(cx, PropertyKey::Int(lineno));
bool found;
if (!HasOwnProperty(cx, result, id, &found)) {

Просмотреть файл

@ -134,7 +134,7 @@ bool InterpretObjLiteralObj(JSContext* cx, HandlePlainObject obj,
!insn.getKey().isArrayIndex());
if (kind == PropertySetKind::Normal && insn.getKey().isArrayIndex()) {
propId = INT_TO_JSID(insn.getKey().getArrayIndex());
propId = PropertyKey::Int(insn.getKey().getArrayIndex());
} else {
JSAtom* jsatom =
atomCache.getExistingAtomAt(cx, insn.getKey().getAtomIndex());

Просмотреть файл

@ -8,7 +8,7 @@ FRAGMENT(jsid, simple) {
JS::Rooted<JSString*> string(cx, JS_NewStringCopyZ(cx, chars));
JS::Rooted<JSString*> interned(cx, JS_AtomizeAndPinString(cx, chars));
JS::Rooted<jsid> string_id(cx, JS::PropertyKey::fromPinnedString(interned));
JS::Rooted<jsid> int_id(cx, INT_TO_JSID(1729));
JS::Rooted<jsid> int_id(cx, JS::PropertyKey::Int(1729));
JS::Rooted<jsid> unique_symbol_id(
cx, SYMBOL_TO_JSID(JS::NewSymbol(cx, interned)));
JS::Rooted<jsid> registry_symbol_id(

Просмотреть файл

@ -1928,7 +1928,7 @@ bool HasNativeElementPure(JSContext* cx, NativeObject* obj, int32_t index,
return true;
}
jsid id = INT_TO_JSID(index);
jsid id = PropertyKey::Int(index);
uint32_t unused;
if (obj->shape()->lookup(cx, id, &unused)) {
vp[0].setBoolean(true);

Просмотреть файл

@ -719,7 +719,7 @@ bool MappedArgumentsObject::obj_enumerate(JSContext* cx, HandleObject obj) {
}
for (unsigned i = 0; i < argsobj->initialLength(); i++) {
id = INT_TO_JSID(i);
id = PropertyKey::Int(i);
if (!HasOwnProperty(cx, argsobj, id, &found)) {
return false;
}
@ -1006,7 +1006,7 @@ bool UnmappedArgumentsObject::obj_enumerate(JSContext* cx, HandleObject obj) {
}
for (unsigned i = 0; i < argsobj->initialLength(); i++) {
id = INT_TO_JSID(i);
id = PropertyKey::Int(i);
if (!HasOwnProperty(cx, argsobj, id, &found)) {
return false;
}

Просмотреть файл

@ -221,7 +221,7 @@ static bool EnumerateNativeProperties(JSContext* cx, HandleNativeObject pobj,
} else {
// Dense arrays never get so large that i would not fit into an
// integer id.
if (!Enumerate<CheckForDuplicates>(cx, pobj, INT_TO_JSID(i),
if (!Enumerate<CheckForDuplicates>(cx, pobj, PropertyKey::Int(i),
/* enumerable = */ true, flags,
visited, props)) {
return false;
@ -244,7 +244,7 @@ static bool EnumerateNativeProperties(JSContext* cx, HandleNativeObject pobj,
}
for (size_t i = 0; i < len; i++) {
if (!Enumerate<CheckForDuplicates>(cx, pobj, INT_TO_JSID(i),
if (!Enumerate<CheckForDuplicates>(cx, pobj, PropertyKey::Int(i),
/* enumerable = */ true, flags,
visited, props)) {
return false;

Просмотреть файл

@ -25,7 +25,7 @@ MOZ_ALWAYS_INLINE jsid AtomToId(JSAtom* atom) {
uint32_t index;
if (atom->isIndex(&index) && index <= JSID_INT_MAX) {
return INT_TO_JSID(int32_t(index));
return JS::PropertyKey::Int(int32_t(index));
}
return JS::PropertyKey::fromNonIntAtom(atom);
@ -42,11 +42,11 @@ MOZ_ALWAYS_INLINE bool ValueToIntId(const Value& v, jsid* id) {
return false;
}
if (!INT_FITS_IN_JSID(i)) {
if (!PropertyKey::fitsInInt(i)) {
return false;
}
*id = INT_TO_JSID(i);
*id = PropertyKey::Int(i);
return true;
}
@ -135,7 +135,7 @@ bool IndexToIdSlow(JSContext* cx, uint32_t index, MutableHandleId idp);
inline bool IndexToId(JSContext* cx, uint32_t index, MutableHandleId idp) {
if (index <= JSID_INT_MAX) {
idp.set(INT_TO_JSID(index));
idp.set(PropertyKey::Int(index));
return true;
}

Просмотреть файл

@ -60,7 +60,7 @@ inline void NativeObject::setDenseElementHole(uint32_t index) {
}
inline void NativeObject::removeDenseElementForSparseIndex(uint32_t index) {
MOZ_ASSERT(containsPure(INT_TO_JSID(index)));
MOZ_ASSERT(containsPure(PropertyKey::Int(index)));
if (containsDenseElement(index)) {
setDenseElementHole(index);
}

Просмотреть файл

@ -1071,7 +1071,7 @@ static MOZ_ALWAYS_INLINE bool CallAddPropertyHookDense(JSContext* cx,
if (MOZ_UNLIKELY(addProperty)) {
MOZ_ASSERT(!cx->isHelperThreadContext());
RootedId id(cx, INT_TO_JSID(index));
RootedId id(cx, PropertyKey::Int(index));
if (!CallJSAddPropertyOp(cx, addProperty, obj, id, value)) {
obj->setDenseElementHole(index);
return false;
@ -1807,8 +1807,8 @@ static bool DefineNonexistentProperty(JSContext* cx, HandleNativeObject obj,
bool js::AddOrUpdateSparseElementHelper(JSContext* cx, HandleArrayObject obj,
int32_t int_id, HandleValue v,
bool strict) {
MOZ_ASSERT(INT_FITS_IN_JSID(int_id));
RootedId id(cx, INT_TO_JSID(int_id));
MOZ_ASSERT(PropertyKey::fitsInInt(int_id));
RootedId id(cx, PropertyKey::Int(int_id));
// This helper doesn't handle the case where the index may be in the dense
// elements
@ -2095,8 +2095,8 @@ bool js::GetSparseElementHelper(JSContext* cx, HandleArrayObject obj,
MOZ_ASSERT_IF(obj->staticPrototype() != nullptr,
!ObjectMayHaveExtraIndexedProperties(obj->staticPrototype()));
MOZ_ASSERT(INT_FITS_IN_JSID(int_id));
RootedId id(cx, INT_TO_JSID(int_id));
MOZ_ASSERT(PropertyKey::fitsInInt(int_id));
RootedId id(cx, PropertyKey::Int(int_id));
uint32_t index;
PropMap* map = obj->shape()->lookup(cx, id, &index);

Просмотреть файл

@ -207,7 +207,7 @@ inline bool GetElementNoGC(JSContext* cx, JSObject* obj,
return false;
}
return GetPropertyNoGC(cx, obj, receiver, INT_TO_JSID(index), vp);
return GetPropertyNoGC(cx, obj, receiver, PropertyKey::Int(index), vp);
}
static MOZ_ALWAYS_INLINE bool ClassMayResolveId(const JSAtomState& names,

Просмотреть файл

@ -1102,7 +1102,7 @@ static MOZ_ALWAYS_INLINE void MakeRangeGCSafe(Value* beg, Value* end) {
}
static MOZ_ALWAYS_INLINE void MakeRangeGCSafe(jsid* beg, jsid* end) {
std::fill(beg, end, INT_TO_JSID(0));
std::fill(beg, end, PropertyKey::Int(0));
}
static MOZ_ALWAYS_INLINE void MakeRangeGCSafe(jsid* vec, size_t len) {

Просмотреть файл

@ -1469,7 +1469,7 @@ static bool TryAppendNativeProperties(JSContext* cx, HandleObject obj,
continue;
}
if (!entries.append(INT_TO_JSID(i - 1))) {
if (!entries.append(PropertyKey::Int(i - 1))) {
return false;
}

Просмотреть файл

@ -598,7 +598,7 @@ bool TypedObject::obj_newEnumerate(JSContext* cx, HandleObject obj,
}
RootedId id(cx);
for (size_t index = 0; index < indexCount; index++) {
id = INT_TO_JSID(index);
id = PropertyKey::Int(index);
properties.infallibleAppend(id);
}

Просмотреть файл

@ -946,7 +946,7 @@ bool JSXrayTraits::enumerateNames(JSContext* cx, HandleObject wrapper,
return false;
}
for (int32_t i = 0; i < int32_t(length); ++i) {
props.infallibleAppend(INT_TO_JSID(i));
props.infallibleAppend(PropertyKey::Int(i));
}
} else if (key == JSProto_Function) {
if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_LENGTH))) {