mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
LibJS: Change PropertyName(i32) => template<Integral T> PropertyName(T)
Negative numeric properties are not a thing (and we even VERIFY()'d this in the constructor). It still allows using types with a negative range for now as we have various places using int for example (without actually needing the negative range, but that's a different story). u32 is the internal type of `m_number` already, so this now allows us to leverage the full u32 range for numeric properties.
This commit is contained in:
parent
f4867572b7
commit
a59ba0e21f
2 changed files with 13 additions and 8 deletions
|
@ -646,12 +646,12 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice)
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
while (actual_start < final) {
|
while (actual_start < final) {
|
||||||
bool present = this_object->has_property(actual_start);
|
bool present = this_object->has_property((u32)actual_start);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (present) {
|
if (present) {
|
||||||
auto value = this_object->get(actual_start).value_or(js_undefined());
|
auto value = this_object->get((u32)actual_start).value_or(js_undefined());
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@ public:
|
||||||
return {};
|
return {};
|
||||||
if (value.is_symbol())
|
if (value.is_symbol())
|
||||||
return value.as_symbol();
|
return value.as_symbol();
|
||||||
if (value.is_integral_number() && value.as_i32() >= 0)
|
if (value.is_integral_number() && value.as_double() >= 0 && value.as_double() <= NumericLimits<u32>::max())
|
||||||
return value.as_i32();
|
return value.as_u32();
|
||||||
auto string = value.to_string(global_object);
|
auto string = value.to_string(global_object);
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
return {};
|
return {};
|
||||||
|
@ -41,11 +41,16 @@ public:
|
||||||
|
|
||||||
PropertyName() { }
|
PropertyName() { }
|
||||||
|
|
||||||
PropertyName(i32 index)
|
template<Integral T>
|
||||||
|
PropertyName(T index)
|
||||||
: m_type(Type::Number)
|
: m_type(Type::Number)
|
||||||
, m_number(index)
|
, 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);
|
VERIFY(index >= 0);
|
||||||
|
if constexpr (NumericLimits<T>::max() > NumericLimits<u32>::max())
|
||||||
|
VERIFY(index <= NumericLimits<u32>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyName(char const* chars)
|
PropertyName(char const* chars)
|
||||||
|
@ -125,13 +130,13 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 property_index = m_string.to_int(TrimWhitespace::No).value_or(-1);
|
auto property_index = m_string.to_uint(TrimWhitespace::No);
|
||||||
if (property_index < 0) {
|
if (!property_index.has_value()) {
|
||||||
m_string_may_be_number = false;
|
m_string_may_be_number = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_type = Type::Number;
|
m_type = Type::Number;
|
||||||
m_number = property_index;
|
m_number = *property_index;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue