mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
Revert "LibJS: Get rid of unnecessary work from canonical_numeric_index_string"
This reverts commit 3a184f7841
.
This broke a number of test262 tests under "TypedArrayConstructors".
The issue is that the CanonicalNumericIndexString AO should not fail
for inputs like "1.1", despite them not being integral indices.
This commit is contained in:
parent
b193351a99
commit
4b412e8fee
9 changed files with 105 additions and 61 deletions
|
@ -17,25 +17,39 @@
|
|||
namespace Web::Bindings::IDL {
|
||||
|
||||
// https://webidl.spec.whatwg.org/#is-an-array-index
|
||||
bool is_an_array_index(JS::PropertyKey const& property_name)
|
||||
bool is_an_array_index(JS::GlobalObject& global_object, JS::PropertyKey const& property_name)
|
||||
{
|
||||
// 1. If Type(P) is not String, then return false.
|
||||
if (!property_name.is_number())
|
||||
return false;
|
||||
|
||||
// 2. Let index be ! CanonicalNumericIndexString(P).
|
||||
auto index = JS::canonical_numeric_index_string(property_name);
|
||||
auto index = JS::canonical_numeric_index_string(global_object, property_name);
|
||||
|
||||
if (!index.has_value()) {
|
||||
// All of these are handled by canonical_numeric_index_string
|
||||
// 3. If index is undefined, then return false.
|
||||
// 4. If IsInteger(index) is false, then return false.
|
||||
// 5. If index is −0, then return false.
|
||||
// 6. If index < 0, then return false.
|
||||
// 7. If index ≥ 2 ** 32 − 1, then return false.
|
||||
// Note: 2 ** 32 − 1 is the maximum array length allowed by ECMAScript.
|
||||
// 3. If index is undefined, then return false.
|
||||
if (index.is_undefined())
|
||||
return false;
|
||||
|
||||
// 4. If IsInteger(index) is false, then return false.
|
||||
// NOTE: IsInteger is the old name of IsIntegralNumber.
|
||||
if (!index.is_integral_number())
|
||||
return false;
|
||||
|
||||
// 5. If index is −0, then return false.
|
||||
if (index.is_negative_zero())
|
||||
return false;
|
||||
|
||||
// FIXME: I'm not sure if this is correct.
|
||||
auto index_as_double = index.as_double();
|
||||
|
||||
// 6. If index < 0, then return false.
|
||||
if (index_as_double < 0)
|
||||
return false;
|
||||
|
||||
// 7. If index ≥ 2 ** 32 − 1, then return false.
|
||||
// Note: 2 ** 32 − 1 is the maximum array length allowed by ECMAScript.
|
||||
if (index_as_double >= NumericLimits<u32>::max())
|
||||
return false;
|
||||
}
|
||||
|
||||
// 8. Return true.
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue