mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:58:12 +00:00
LibJS: Remove assertions that are now part of structured headers
This is an editorial change in the ECMA-262 spec.
See: 4fde514
This commit is contained in:
parent
86e3840202
commit
ce659e5eeb
6 changed files with 238 additions and 322 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -42,40 +42,38 @@ 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)
|
||||
{
|
||||
// 1. Assert: S is an Object that has a [[StringData]] internal slot.
|
||||
// 2. Assert: IsPropertyKey(P) is true.
|
||||
VERIFY(property_key.is_valid());
|
||||
|
||||
// 3. If Type(P) is not String, return undefined.
|
||||
// 1. If Type(P) is not String, return undefined.
|
||||
// NOTE: The spec only uses string and symbol keys, and later coerces to numbers -
|
||||
// this is not the case for PropertyKey, so '!property_key.is_string()' would be wrong.
|
||||
if (property_key.is_symbol())
|
||||
return {};
|
||||
|
||||
// 4. Let index be ! CanonicalNumericIndexString(P).
|
||||
// 2. Let index be ! CanonicalNumericIndexString(P).
|
||||
auto index = canonical_numeric_index_string(property_key, CanonicalIndexMode::IgnoreNumericRoundtrip);
|
||||
|
||||
// 5. If index is undefined, return undefined.
|
||||
// 6. If IsIntegralNumber(index) is false, return undefined.
|
||||
// 7. If index is -0𝔽, return undefined.
|
||||
// 3. If index is undefined, return undefined.
|
||||
// 4. If IsIntegralNumber(index) is false, return undefined.
|
||||
// 5. If index is -0𝔽, return undefined.
|
||||
if (!index.is_index())
|
||||
return {};
|
||||
|
||||
// 8. Let str be S.[[StringData]].
|
||||
// 9. Assert: Type(str) is String.
|
||||
// 6. Let str be S.[[StringData]].
|
||||
// 7. Assert: Type(str) is String.
|
||||
auto str = string.primitive_string().utf16_string_view();
|
||||
|
||||
// 10. Let len be the length of str.
|
||||
// 8. Let len be the length of str.
|
||||
auto length = str.length_in_code_units();
|
||||
|
||||
// 11. If ℝ(index) < 0 or len ≤ ℝ(index), return undefined.
|
||||
// 9. If ℝ(index) < 0 or len ≤ ℝ(index), return undefined.
|
||||
if (length <= index.as_index())
|
||||
return {};
|
||||
|
||||
// 12. Let resultStr be the String value of length 1, containing one code unit from str, specifically the code unit at index ℝ(index).
|
||||
// 10. 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.as_index(), 1));
|
||||
|
||||
// 13. Return the PropertyDescriptor { [[Value]]: resultStr, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false }.
|
||||
// 11. Return the PropertyDescriptor { [[Value]]: resultStr, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false }.
|
||||
return PropertyDescriptor {
|
||||
.value = result_str,
|
||||
.writable = false,
|
||||
|
@ -87,29 +85,28 @@ static Optional<PropertyDescriptor> string_get_own_property(StringObject const&
|
|||
// 10.4.3.1 [[GetOwnProperty]] ( P ), https://tc39.es/ecma262/#sec-string-exotic-objects-getownproperty-p
|
||||
ThrowCompletionOr<Optional<PropertyDescriptor>> StringObject::internal_get_own_property(PropertyKey const& property_key) const
|
||||
{
|
||||
// Assert: IsPropertyKey(P) is true.
|
||||
VERIFY(property_key.is_valid());
|
||||
|
||||
// 2. Let desc be OrdinaryGetOwnProperty(S, P).
|
||||
// 1. Let desc be OrdinaryGetOwnProperty(S, P).
|
||||
auto descriptor = MUST(Object::internal_get_own_property(property_key));
|
||||
|
||||
// 3. If desc is not undefined, return desc.
|
||||
// 2. If desc is not undefined, return desc.
|
||||
if (descriptor.has_value())
|
||||
return descriptor;
|
||||
|
||||
// 4. Return ! StringGetOwnProperty(S, P).
|
||||
// 3. Return ! StringGetOwnProperty(S, P).
|
||||
return string_get_own_property(*this, property_key);
|
||||
}
|
||||
|
||||
// 10.4.3.2 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-string-exotic-objects-defineownproperty-p-desc
|
||||
ThrowCompletionOr<bool> StringObject::internal_define_own_property(PropertyKey const& property_key, PropertyDescriptor const& property_descriptor)
|
||||
{
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
VERIFY(property_key.is_valid());
|
||||
|
||||
// 2. Let stringDesc be ! StringGetOwnProperty(S, P).
|
||||
// 1. Let stringDesc be ! StringGetOwnProperty(S, P).
|
||||
auto string_descriptor = string_get_own_property(*this, property_key);
|
||||
|
||||
// 3. If stringDesc is not undefined, then
|
||||
// 2. If stringDesc is not undefined, then
|
||||
if (string_descriptor.has_value()) {
|
||||
// a. Let extensible be S.[[Extensible]].
|
||||
auto extensible = m_is_extensible;
|
||||
|
@ -118,7 +115,7 @@ ThrowCompletionOr<bool> StringObject::internal_define_own_property(PropertyKey c
|
|||
return is_compatible_property_descriptor(extensible, property_descriptor, string_descriptor);
|
||||
}
|
||||
|
||||
// 4. Return ! OrdinaryDefineOwnProperty(S, P, Desc).
|
||||
// 3. Return ! OrdinaryDefineOwnProperty(S, P, Desc).
|
||||
return Object::internal_define_own_property(property_key, property_descriptor);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue