summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/StringObject.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-02-13 15:35:15 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-13 16:01:32 +0100
commit4b412e8feeb4804f305aecec9695fb36c9acc0e4 (patch)
treed663f4a80838edec2a4b38abcffa71a4715b1920 /Userland/Libraries/LibJS/Runtime/StringObject.cpp
parentb193351a998dab06228bf6cb8c2b0828704839c1 (diff)
downloadserenity-4b412e8feeb4804f305aecec9695fb36c9acc0e4.zip
Revert "LibJS: Get rid of unnecessary work from canonical_numeric_index_string"
This reverts commit 3a184f784186ad1c5a9704b05ab0902d577d5748. 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.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/StringObject.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringObject.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.cpp b/Userland/Libraries/LibJS/Runtime/StringObject.cpp
index 5c6f452314..f92a65eb43 100644
--- a/Userland/Libraries/LibJS/Runtime/StringObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringObject.cpp
@@ -44,7 +44,7 @@ void StringObject::visit_edges(Cell::Visitor& visitor)
}
// 10.4.3.5 StringGetOwnProperty ( S, P ), https://tc39.es/ecma262/#sec-stringgetownproperty
-static Optional<PropertyDescriptor> string_get_own_property(StringObject const& string, PropertyKey const& property_key)
+static Optional<PropertyDescriptor> string_get_own_property(GlobalObject& global_object, StringObject const& string, PropertyKey const& property_key)
{
// 1. Assert: S is an Object that has a [[StringData]] internal slot.
// 2. Assert: IsPropertyKey(P) is true.
@@ -57,14 +57,17 @@ static Optional<PropertyDescriptor> string_get_own_property(StringObject const&
return {};
// 4. Let index be ! CanonicalNumericIndexString(P).
- auto index = canonical_numeric_index_string(property_key);
-
- if (!index.has_value()) {
- // 5. If index is undefined, return undefined.
- // 6. If IsIntegralNumber(index) is false, return undefined.
- // 7. If index is -0𝔽, return undefined.
+ auto index = canonical_numeric_index_string(global_object, property_key);
+ // 5. If index is undefined, return undefined.
+ if (index.is_undefined())
return {};
- }
+ // 6. If IsIntegralNumber(index) is false, return undefined.
+ if (!index.is_integral_number())
+ return {};
+ // 7. If index is -0𝔽, return undefined.
+ if (index.is_negative_zero())
+ return {};
+
// 8. Let str be S.[[StringData]].
// 9. Assert: Type(str) is String.
auto str = string.primitive_string().utf16_string_view();
@@ -73,11 +76,11 @@ static Optional<PropertyDescriptor> string_get_own_property(StringObject const&
auto length = str.length_in_code_units();
// 11. If ℝ(index) < 0 or len ≤ ℝ(index), return undefined.
- if (length <= static_cast<u64>(*index))
+ if (index.as_double() < 0 || length <= index.as_double())
return {};
// 12. Let resultStr be the String value of length 1, containing one code unit from str, specifically the code unit at index ℝ(index).
- auto result_str = js_string(string.vm(), str.substring_view(*index, 1));
+ auto result_str = js_string(string.vm(), str.substring_view(index.as_double(), 1));
// 13. Return the PropertyDescriptor { [[Value]]: resultStr, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false }.
return PropertyDescriptor {
@@ -101,7 +104,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> StringObject::internal_get_own_p
return descriptor;
// 4. Return ! StringGetOwnProperty(S, P).
- return string_get_own_property(*this, property_key);
+ return string_get_own_property(global_object(), *this, property_key);
}
// 10.4.3.2 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-string-exotic-objects-defineownproperty-p-desc
@@ -111,7 +114,7 @@ ThrowCompletionOr<bool> StringObject::internal_define_own_property(PropertyKey c
VERIFY(property_key.is_valid());
// 2. Let stringDesc be ! StringGetOwnProperty(S, P).
- auto string_descriptor = string_get_own_property(*this, property_key);
+ auto string_descriptor = string_get_own_property(global_object(), *this, property_key);
// 3. If stringDesc is not undefined, then
if (string_descriptor.has_value()) {