зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1754405 part 13 - Move min/max int constants into PropertyKey. r=evilpie
Differential Revision: https://phabricator.services.mozilla.com/D138284
This commit is contained in:
Родитель
099623963c
Коммит
9f57c47f87
|
@ -55,6 +55,9 @@ class PropertyKey {
|
|||
// (0x6 is unused)
|
||||
static constexpr uintptr_t TypeMask = 0x7;
|
||||
|
||||
static constexpr uint32_t IntMin = 0;
|
||||
static constexpr uint32_t IntMax = INT32_MAX;
|
||||
|
||||
constexpr PropertyKey() : asBits_(VoidTypeTag) {}
|
||||
|
||||
static constexpr MOZ_ALWAYS_INLINE PropertyKey fromRawBits(uintptr_t bits) {
|
||||
|
@ -156,8 +159,8 @@ class PropertyKey {
|
|||
//
|
||||
// A PropertyName is an atom that does not contain an integer in the range
|
||||
// [0, UINT32_MAX]. However, PropertyKey can only hold an integer in the range
|
||||
// [0, JSID_INT_MAX] (where JSID_INT_MAX == 2^31-1). Thus, for the range of
|
||||
// integers (JSID_INT_MAX, UINT32_MAX], to represent as a 'id', it must be
|
||||
// [0, IntMax] (where IntMax == 2^31-1). Thus, for the range of integers
|
||||
// (IntMax, UINT32_MAX], to represent as a 'id', it must be
|
||||
// the case id.isString() and id.toString()->isIndex(). In most
|
||||
// cases when creating a PropertyKey, code does not have to care about
|
||||
// this corner case because:
|
||||
|
@ -210,9 +213,6 @@ class PropertyKey {
|
|||
|
||||
using jsid = JS::PropertyKey;
|
||||
|
||||
#define JSID_INT_MIN 0
|
||||
#define JSID_INT_MAX INT32_MAX
|
||||
|
||||
namespace JS {
|
||||
|
||||
// Handle<PropertyKey> version of PropertyKey::Void().
|
||||
|
|
|
@ -2730,7 +2730,7 @@ static bool CopyArrayElements(JSContext* cx, HandleObject obj, uint64_t begin,
|
|||
// Use dense storage for new indexed properties where possible.
|
||||
{
|
||||
uint32_t index = 0;
|
||||
uint32_t limit = std::min<uint32_t>(count, JSID_INT_MAX);
|
||||
uint32_t limit = std::min<uint32_t>(count, PropertyKey::IntMax);
|
||||
for (; index < limit; index++) {
|
||||
bool hole;
|
||||
if (!CheckForInterrupt(cx) ||
|
||||
|
|
|
@ -656,7 +656,7 @@ static bool JA(JSContext* cx, HandleObject obj, StringifyContext* scx) {
|
|||
MOZ_ASSERT(obj->is<ArrayObject>());
|
||||
MOZ_ASSERT(obj->is<NativeObject>());
|
||||
RootedNativeObject nativeObj(cx, &obj->as<NativeObject>());
|
||||
if (i <= JSID_INT_MAX) {
|
||||
if (i <= PropertyKey::IntMax) {
|
||||
MOZ_ASSERT(
|
||||
nativeObj->containsDenseElement(i) != nativeObj->isIndexed(),
|
||||
"the array must either be small enough to remain "
|
||||
|
|
|
@ -1489,8 +1489,9 @@ static bool TryEnumerableOwnPropertiesNative(JSContext* cx, HandleObject obj,
|
|||
|
||||
JSString* str;
|
||||
if (kind != EnumerableOwnPropertiesKind::Values) {
|
||||
static_assert(NativeObject::MAX_DENSE_ELEMENTS_COUNT <= JSID_INT_MAX,
|
||||
"dense elements don't exceed JSID_INT_MAX");
|
||||
static_assert(
|
||||
NativeObject::MAX_DENSE_ELEMENTS_COUNT <= PropertyKey::IntMax,
|
||||
"dense elements don't exceed PropertyKey::IntMax");
|
||||
str = Int32ToString<CanGC>(cx, i);
|
||||
if (!str) {
|
||||
return false;
|
||||
|
@ -1533,8 +1534,9 @@ static bool TryEnumerableOwnPropertiesNative(JSContext* cx, HandleObject obj,
|
|||
for (uint32_t i = 0; i < len; i++) {
|
||||
JSString* str;
|
||||
if (kind != EnumerableOwnPropertiesKind::Values) {
|
||||
static_assert(NativeObject::MAX_DENSE_ELEMENTS_COUNT <= JSID_INT_MAX,
|
||||
"dense elements don't exceed JSID_INT_MAX");
|
||||
static_assert(
|
||||
NativeObject::MAX_DENSE_ELEMENTS_COUNT <= PropertyKey::IntMax,
|
||||
"dense elements don't exceed PropertyKey::IntMax");
|
||||
str = Int32ToString<CanGC>(cx, i);
|
||||
if (!str) {
|
||||
return false;
|
||||
|
|
|
@ -1720,7 +1720,7 @@ static MOZ_ALWAYS_INLINE bool ValueToAtomOrSymbolPure(JSContext* cx,
|
|||
}
|
||||
|
||||
// Watch out for ids that may be stored in dense elements.
|
||||
static_assert(NativeObject::MAX_DENSE_ELEMENTS_COUNT < JSID_INT_MAX,
|
||||
static_assert(NativeObject::MAX_DENSE_ELEMENTS_COUNT < PropertyKey::IntMax,
|
||||
"All dense elements must have integer jsids");
|
||||
if (MOZ_UNLIKELY(id->isInt())) {
|
||||
return false;
|
||||
|
|
|
@ -41,8 +41,8 @@ bool JS::PropertyKey::isWellKnownSymbol(JS::SymbolCode code) const {
|
|||
if (!atom->isIndex(&index)) {
|
||||
return true;
|
||||
}
|
||||
static_assert(JSID_INT_MIN == 0);
|
||||
return index > JSID_INT_MAX;
|
||||
static_assert(PropertyKey::IntMin == 0);
|
||||
return index > PropertyKey::IntMax;
|
||||
}
|
||||
|
||||
/* static */ bool JS::PropertyKey::isNonIntAtom(JSString* str) {
|
||||
|
|
|
@ -236,8 +236,8 @@ static bool EnumerateNativeProperties(JSContext* cx, HandleNativeObject pobj,
|
|||
|
||||
// Fail early if the typed array is enormous, because this will be very
|
||||
// slow and will likely report OOM. This also means we don't need to
|
||||
// handle indices greater than JSID_INT_MAX in the loop below.
|
||||
static_assert(JSID_INT_MAX == INT32_MAX);
|
||||
// handle indices greater than PropertyKey::IntMax in the loop below.
|
||||
static_assert(PropertyKey::IntMax == INT32_MAX);
|
||||
if (len > INT32_MAX) {
|
||||
ReportOutOfMemory(cx);
|
||||
return false;
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
namespace js {
|
||||
|
||||
MOZ_ALWAYS_INLINE jsid AtomToId(JSAtom* atom) {
|
||||
static_assert(JSID_INT_MIN == 0);
|
||||
static_assert(JS::PropertyKey::IntMin == 0);
|
||||
|
||||
uint32_t index;
|
||||
if (atom->isIndex(&index) && index <= JSID_INT_MAX) {
|
||||
if (atom->isIndex(&index) && index <= JS::PropertyKey::IntMax) {
|
||||
return JS::PropertyKey::Int(int32_t(index));
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ inline mozilla::RangedPtr<T> BackfillIndexInCharBuffer(
|
|||
bool IndexToIdSlow(JSContext* cx, uint32_t index, MutableHandleId idp);
|
||||
|
||||
inline bool IndexToId(JSContext* cx, uint32_t index, MutableHandleId idp) {
|
||||
if (index <= JSID_INT_MAX) {
|
||||
if (index <= PropertyKey::IntMax) {
|
||||
idp.set(PropertyKey::Int(index));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -934,7 +934,7 @@ JSAtom* js::AtomizeUTF8Chars(JSContext* cx, const char* utf8Chars,
|
|||
}
|
||||
|
||||
bool js::IndexToIdSlow(JSContext* cx, uint32_t index, MutableHandleId idp) {
|
||||
MOZ_ASSERT(index > JSID_INT_MAX);
|
||||
MOZ_ASSERT(index > JS::PropertyKey::IntMax);
|
||||
|
||||
char16_t buf[UINT32_CHAR_BUFFER_LENGTH];
|
||||
RangedPtr<char16_t> end(std::end(buf), buf, std::end(buf));
|
||||
|
|
|
@ -203,7 +203,7 @@ inline bool GetElementNoGC(JSContext* cx, JSObject* obj,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (index > JSID_INT_MAX) {
|
||||
if (index > PropertyKey::IntMax) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -935,8 +935,8 @@ bool JSXrayTraits::enumerateNames(JSContext* cx, HandleObject wrapper,
|
|||
|
||||
// Fail early if the typed array is enormous, because this will be very
|
||||
// slow and will likely report OOM. This also means we don't need to
|
||||
// handle indices greater than JSID_INT_MAX in the loop below.
|
||||
static_assert(JSID_INT_MAX >= INT32_MAX);
|
||||
// handle indices greater than PropertyKey::IntMax in the loop below.
|
||||
static_assert(PropertyKey::IntMax >= INT32_MAX);
|
||||
if (length > INT32_MAX) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return false;
|
||||
|
|
Загрузка…
Ссылка в новой задаче