1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 16:05:06 +00:00
serenity/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp
Linus Groh a9a7d65099 LibWeb: Replace heycam.github.io/webidl URLs with webidl.spec.whatwg.org
Web IDL is now a WHATWG standard and the specification was moved
accordingly: https://twitter.com/annevk/status/1445311275026821120

The old URLs now redirect, but let's use canonical ones.
2021-10-11 13:15:16 +01:00

53 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/NumericLimits.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/PropertyName.h>
#include <LibWeb/Bindings/IDLAbstractOperations.h>
namespace Web::Bindings::IDL {
// https://webidl.spec.whatwg.org/#is-an-array-index
bool is_an_array_index(JS::GlobalObject& global_object, JS::PropertyName 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(global_object, property_name);
// 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;
}
}