From a0657a3b82b352d9d9422a07d22e6b5ee36fde1d Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Sun, 13 Feb 2022 12:01:47 +0000 Subject: [PATCH] Bug 1754405 part 9 - Add PropertyKey::asRawBits. r=evilpie Differential Revision: https://phabricator.services.mozilla.com/D138280 --- dom/bindings/BindingUtils.cpp | 10 ++++++---- dom/bindings/DOMJSClass.h | 2 +- js/public/Id.h | 4 ++++ js/src/jit/CacheIRWriter.h | 2 +- js/src/jit/MacroAssembler.cpp | 2 +- js/src/vm/JSObject.cpp | 4 ++-- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 0fd6e855ceaa..81898b46f2a9 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -1260,9 +1260,11 @@ static int CompareIdsAtIndices(const void* aElement1, const void* aElement2, const uint16_t index2 = *static_cast(aElement2); const PropertyInfo* infos = static_cast(aClosure); - MOZ_ASSERT(JSID_BITS(infos[index1].Id()) != JSID_BITS(infos[index2].Id())); + uintptr_t rawBits1 = infos[index1].Id().asRawBits(); + uintptr_t rawBits2 = infos[index2].Id().asRawBits(); + MOZ_ASSERT(rawBits1 != rawBits2); - return JSID_BITS(infos[index1].Id()) < JSID_BITS(infos[index2].Id()) ? -1 : 1; + return rawBits1 < rawBits2 ? -1 : 1; } // {JSPropertySpec,JSFunctionSpec} use {JSPropertySpec,JSFunctionSpec}::Name @@ -1466,10 +1468,10 @@ struct IdToIndexComparator { explicit IdToIndexComparator(const jsid& aId, const PropertyInfo* aInfos) : mId(aId), mInfos(aInfos) {} int operator()(const uint16_t aIndex) const { - if (JSID_BITS(mId) == JSID_BITS(mInfos[aIndex].Id())) { + if (mId.asRawBits() == mInfos[aIndex].Id().asRawBits()) { return 0; } - return JSID_BITS(mId) < JSID_BITS(mInfos[aIndex].Id()) ? -1 : 1; + return mId.asRawBits() < mInfos[aIndex].Id().asRawBits() ? -1 : 1; } }; diff --git a/dom/bindings/DOMJSClass.h b/dom/bindings/DOMJSClass.h index 73cd36486fb3..8bb3df600d59 100644 --- a/dom/bindings/DOMJSClass.h +++ b/dom/bindings/DOMJSClass.h @@ -203,7 +203,7 @@ struct PropertyInfo { void SetId(jsid aId) { static_assert(sizeof(jsid) == sizeof(mIdBits), "jsid should fit in mIdBits"); - mIdBits = JSID_BITS(aId); + mIdBits = aId.asRawBits(); } MOZ_ALWAYS_INLINE jsid Id() const { return jsid::fromRawBits(mIdBits); } }; diff --git a/js/public/Id.h b/js/public/Id.h index cb15c0bc50f7..21d69b8c47b6 100644 --- a/js/public/Id.h +++ b/js/public/Id.h @@ -86,6 +86,8 @@ struct PropertyKey { MOZ_ALWAYS_INLINE bool isGCThing() const { return isString() || isSymbol(); } + constexpr uintptr_t asRawBits() const { return asBits; } + MOZ_ALWAYS_INLINE int32_t toInt() const { MOZ_ASSERT(isInt()); uint32_t bits = static_cast(asBits) >> 1; @@ -331,6 +333,8 @@ class WrappedPtrOperations { return id().isWellKnownSymbol(code); } + uintptr_t asRawBits() const { return id().asRawBits(); } + // Internal API bool isAtom() const { return id().isAtom(); } bool isAtom(JSAtom* atom) const { return id().isAtom(atom); } diff --git a/js/src/jit/CacheIRWriter.h b/js/src/jit/CacheIRWriter.h index c478afc9afa1..e5abfb9c3363 100644 --- a/js/src/jit/CacheIRWriter.h +++ b/js/src/jit/CacheIRWriter.h @@ -223,7 +223,7 @@ class MOZ_RAII CacheIRWriter : public JS::CustomAutoRooter { addStubField(uintptr_t(ptr), StubField::Type::RawPointer); } void writeIdField(jsid id) { - addStubField(uintptr_t(JSID_BITS(id)), StubField::Type::Id); + addStubField(id.asRawBits(), StubField::Type::Id); } void writeValueField(const Value& val) { addStubField(val.asRawBits(), StubField::Type::Value); diff --git a/js/src/jit/MacroAssembler.cpp b/js/src/jit/MacroAssembler.cpp index 3a76995d1c62..caa095be0a01 100644 --- a/js/src/jit/MacroAssembler.cpp +++ b/js/src/jit/MacroAssembler.cpp @@ -2976,7 +2976,7 @@ void MacroAssembler::PushEmptyRooted(VMFunctionData::RootType rootType) { Push(UndefinedValue()); break; case VMFunctionData::RootId: - Push(ImmWord(JSID_BITS(JS::PropertyKey::Void()))); + Push(ImmWord(JS::PropertyKey::Void().asRawBits())); break; } } diff --git a/js/src/vm/JSObject.cpp b/js/src/vm/JSObject.cpp index a697dc5a561c..99a3ce1bb52e 100644 --- a/js/src/vm/JSObject.cpp +++ b/js/src/vm/JSObject.cpp @@ -2829,7 +2829,7 @@ JS_PUBLIC_API void js::DumpValue(const Value& val, js::GenericPrinter& out) { } JS_PUBLIC_API void js::DumpId(jsid id, js::GenericPrinter& out) { - out.printf("jsid %p = ", (void*)JSID_BITS(id)); + out.printf("jsid %p = ", (void*)id.asRawBits()); dumpValue(IdToValue(id), out); out.putChar('\n'); } @@ -2845,7 +2845,7 @@ static void DumpProperty(const NativeObject* obj, PropMap* map, uint32_t index, } else if (id.isSymbol()) { id.toSymbol()->dump(out); } else { - out.printf("id %p", reinterpret_cast(JSID_BITS(id))); + out.printf("id %p", reinterpret_cast(id.asRawBits())); } if (prop.isDataProperty()) {