1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:27:35 +00:00

LibJS: Add a way of constructing PropertyName with values above 2**32-1

This is often needed in ArrayPrototype when getting items with indices
above 2**32-1 is possible since length is at most 2**53-1.
This also fixes a number of these cases in ArrayPrototype where the type
was not big enough to hold the potential values.
This commit is contained in:
davidot 2021-07-07 14:17:51 +02:00 committed by Linus Groh
parent a70033481d
commit cb44fc528b
2 changed files with 25 additions and 17 deletions

View file

@ -43,14 +43,21 @@ public:
template<Integral T>
PropertyName(T index)
: m_type(Type::Number)
, m_number(index)
{
// FIXME: Replace this with requires(IsUnsigned<T>)?
// Needs changes in various places using `int` (but not actually being in the negative range)
VERIFY(index >= 0);
if constexpr (NumericLimits<T>::max() >= NumericLimits<u32>::max())
VERIFY(index < NumericLimits<u32>::max());
if constexpr (NumericLimits<T>::max() >= NumericLimits<u32>::max()) {
if (index >= NumericLimits<u32>::max()) {
m_string = String::number(index);
m_type = Type::String;
m_string_may_be_number = false;
return;
}
}
m_type = Type::Number;
m_number = index;
}
PropertyName(char const* chars)