diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 29cf5f6f5e..42f8814cce 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -646,12 +646,12 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice) size_t index = 0; while (actual_start < final) { - bool present = this_object->has_property(actual_start); + bool present = this_object->has_property((u32)actual_start); if (vm.exception()) return {}; 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()) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/PropertyName.h b/Userland/Libraries/LibJS/Runtime/PropertyName.h index 7b62524184..107b6098ea 100644 --- a/Userland/Libraries/LibJS/Runtime/PropertyName.h +++ b/Userland/Libraries/LibJS/Runtime/PropertyName.h @@ -31,8 +31,8 @@ public: return {}; if (value.is_symbol()) return value.as_symbol(); - if (value.is_integral_number() && value.as_i32() >= 0) - return value.as_i32(); + if (value.is_integral_number() && value.as_double() >= 0 && value.as_double() <= NumericLimits::max()) + return value.as_u32(); auto string = value.to_string(global_object); if (string.is_null()) return {}; @@ -41,11 +41,16 @@ public: PropertyName() { } - PropertyName(i32 index) + template + PropertyName(T index) : m_type(Type::Number) , m_number(index) { + // FIXME: Replace this with requires(IsUnsigned)? + // Needs changes in various places using `int` (but not actually being in the negative range) VERIFY(index >= 0); + if constexpr (NumericLimits::max() > NumericLimits::max()) + VERIFY(index <= NumericLimits::max()); } PropertyName(char const* chars) @@ -125,13 +130,13 @@ public: return false; } - i32 property_index = m_string.to_int(TrimWhitespace::No).value_or(-1); - if (property_index < 0) { + auto property_index = m_string.to_uint(TrimWhitespace::No); + if (!property_index.has_value()) { m_string_may_be_number = false; return false; } m_type = Type::Number; - m_number = property_index; + m_number = *property_index; return true; }