Bug 1754405 part 9 - Add PropertyKey::asRawBits. r=evilpie

Differential Revision: https://phabricator.services.mozilla.com/D138280
This commit is contained in:
Jan de Mooij 2022-02-13 12:01:47 +00:00
parent 4249b631d8
commit a0657a3b82
6 changed files with 15 additions and 9 deletions

View File

@ -1260,9 +1260,11 @@ static int CompareIdsAtIndices(const void* aElement1, const void* aElement2,
const uint16_t index2 = *static_cast<const uint16_t*>(aElement2);
const PropertyInfo* infos = static_cast<PropertyInfo*>(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;
}
};

View File

@ -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); }
};

View File

@ -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<uint32_t>(asBits) >> 1;
@ -331,6 +333,8 @@ class WrappedPtrOperations<JS::PropertyKey, Wrapper> {
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); }

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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<void*>(JSID_BITS(id)));
out.printf("id %p", reinterpret_cast<void*>(id.asRawBits()));
}
if (prop.isDataProperty()) {