diff --git a/dom/base/RemoteOuterWindowProxy.cpp b/dom/base/RemoteOuterWindowProxy.cpp index 72562b72a93a..6c8738f2b39e 100644 --- a/dom/base/RemoteOuterWindowProxy.cpp +++ b/dom/base/RemoteOuterWindowProxy.cpp @@ -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; } diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 5e9f9d235c4b..416e34a05909 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -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; } } diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index f24744d34144..cc3e31abe381 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -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; } } diff --git a/js/public/Id.h b/js/public/Id.h index d633edd8e74e..0fb7a454673a 100644 --- a/js/public/Id.h +++ b/js/public/Id.h @@ -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(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(i) << 1) | JSID_TYPE_INT_BIT; - JSID_BITS(id) = static_cast(bits); - return id; -} - static MOZ_ALWAYS_INLINE jsid SYMBOL_TO_JSID(JS::Symbol* sym) { jsid id; MOZ_ASSERT(sym != nullptr); diff --git a/js/src/builtin/Array.cpp b/js/src/builtin/Array.cpp index 9034aa72fe1c..0b4adcf9f804 100644 --- a/js/src/builtin/Array.cpp +++ b/js/src/builtin/Array.cpp @@ -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); diff --git a/js/src/builtin/JSON.cpp b/js/src/builtin/JSON.cpp index 02aff9e66118..1499ad4d4d92 100644 --- a/js/src/builtin/JSON.cpp +++ b/js/src/builtin/JSON.cpp @@ -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)) { diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index ab79d961158d..0d59a228e37e 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -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"); diff --git a/js/src/debugger/Frame.cpp b/js/src/debugger/Frame.cpp index 85ecea1fcf76..469ebd0c2058 100644 --- a/js/src/debugger/Frame.cpp +++ b/js/src/debugger/Frame.cpp @@ -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; diff --git a/js/src/debugger/Script.cpp b/js/src/debugger/Script.cpp index 9c8764955c16..521baf7665aa 100644 --- a/js/src/debugger/Script.cpp +++ b/js/src/debugger/Script.cpp @@ -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)) { diff --git a/js/src/frontend/ObjLiteral.cpp b/js/src/frontend/ObjLiteral.cpp index c90492288669..165b852dcfaa 100644 --- a/js/src/frontend/ObjLiteral.cpp +++ b/js/src/frontend/ObjLiteral.cpp @@ -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()); diff --git a/js/src/gdb/tests/test-jsid.cpp b/js/src/gdb/tests/test-jsid.cpp index 0029b1a00d93..b0b8fc1b9852 100644 --- a/js/src/gdb/tests/test-jsid.cpp +++ b/js/src/gdb/tests/test-jsid.cpp @@ -8,7 +8,7 @@ FRAGMENT(jsid, simple) { JS::Rooted string(cx, JS_NewStringCopyZ(cx, chars)); JS::Rooted interned(cx, JS_AtomizeAndPinString(cx, chars)); JS::Rooted string_id(cx, JS::PropertyKey::fromPinnedString(interned)); - JS::Rooted int_id(cx, INT_TO_JSID(1729)); + JS::Rooted int_id(cx, JS::PropertyKey::Int(1729)); JS::Rooted unique_symbol_id( cx, SYMBOL_TO_JSID(JS::NewSymbol(cx, interned))); JS::Rooted registry_symbol_id( diff --git a/js/src/jit/VMFunctions.cpp b/js/src/jit/VMFunctions.cpp index 8c5864871729..448064bf61b1 100644 --- a/js/src/jit/VMFunctions.cpp +++ b/js/src/jit/VMFunctions.cpp @@ -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); diff --git a/js/src/vm/ArgumentsObject.cpp b/js/src/vm/ArgumentsObject.cpp index 4b8ff650854a..498a79e4455e 100644 --- a/js/src/vm/ArgumentsObject.cpp +++ b/js/src/vm/ArgumentsObject.cpp @@ -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; } diff --git a/js/src/vm/Iteration.cpp b/js/src/vm/Iteration.cpp index 1445dfff0135..24bcb9f34b6d 100644 --- a/js/src/vm/Iteration.cpp +++ b/js/src/vm/Iteration.cpp @@ -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(cx, pobj, INT_TO_JSID(i), + if (!Enumerate(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(cx, pobj, INT_TO_JSID(i), + if (!Enumerate(cx, pobj, PropertyKey::Int(i), /* enumerable = */ true, flags, visited, props)) { return false; diff --git a/js/src/vm/JSAtom-inl.h b/js/src/vm/JSAtom-inl.h index 322f616bd93a..956629eecd4c 100644 --- a/js/src/vm/JSAtom-inl.h +++ b/js/src/vm/JSAtom-inl.h @@ -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; } diff --git a/js/src/vm/NativeObject-inl.h b/js/src/vm/NativeObject-inl.h index 8a92b9d01ac2..f274192f3bc1 100644 --- a/js/src/vm/NativeObject-inl.h +++ b/js/src/vm/NativeObject-inl.h @@ -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); } diff --git a/js/src/vm/NativeObject.cpp b/js/src/vm/NativeObject.cpp index f2885d075e1e..1b36af8afd27 100644 --- a/js/src/vm/NativeObject.cpp +++ b/js/src/vm/NativeObject.cpp @@ -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); diff --git a/js/src/vm/ObjectOperations-inl.h b/js/src/vm/ObjectOperations-inl.h index 35d8407c74f4..02b789924f62 100644 --- a/js/src/vm/ObjectOperations-inl.h +++ b/js/src/vm/ObjectOperations-inl.h @@ -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, diff --git a/js/src/vm/Runtime.h b/js/src/vm/Runtime.h index bbc39efa3f5e..7e73165cefc0 100644 --- a/js/src/vm/Runtime.h +++ b/js/src/vm/Runtime.h @@ -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) { diff --git a/js/src/vm/StructuredClone.cpp b/js/src/vm/StructuredClone.cpp index 9d653d96dfd7..c4630de602b7 100644 --- a/js/src/vm/StructuredClone.cpp +++ b/js/src/vm/StructuredClone.cpp @@ -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; } diff --git a/js/src/wasm/TypedObject.cpp b/js/src/wasm/TypedObject.cpp index 06ae4d18c86b..019d58600e49 100644 --- a/js/src/wasm/TypedObject.cpp +++ b/js/src/wasm/TypedObject.cpp @@ -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); } diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index b99e50262df3..daa2081bb240 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -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))) {