mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
LibJS: Make AbstractOperations::canonical_num... take a PropertyName
This allows us to hide the fact that it could be a number and means we no longer need to check for this optimization in string and typedarray
This commit is contained in:
parent
9b7e48c6bd
commit
c52d515028
4 changed files with 31 additions and 64 deletions
|
@ -544,10 +544,19 @@ Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObje
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.1.21 CanonicalNumericIndexString ( argument ), https://tc39.es/ecma262/#sec-canonicalnumericindexstring
|
// 7.1.21 CanonicalNumericIndexString ( argument ), https://tc39.es/ecma262/#sec-canonicalnumericindexstring
|
||||||
Value canonical_numeric_index_string(GlobalObject& global_object, Value argument)
|
Value canonical_numeric_index_string(GlobalObject& global_object, PropertyName const& property_name)
|
||||||
{
|
{
|
||||||
|
// NOTE: If the property name is a number type (An implementation-defined optimized
|
||||||
|
// property key type), it can be treated as a string property that has already been
|
||||||
|
// converted successfully into a canonical numeric index.
|
||||||
|
|
||||||
|
VERIFY(property_name.is_string() || property_name.is_number());
|
||||||
|
|
||||||
|
if (property_name.is_number())
|
||||||
|
return Value(property_name.as_number());
|
||||||
|
|
||||||
// 1. Assert: Type(argument) is String.
|
// 1. Assert: Type(argument) is String.
|
||||||
VERIFY(argument.is_string());
|
auto argument = Value(js_string(global_object.vm(), property_name.as_string()));
|
||||||
|
|
||||||
// 2. If argument is "-0", return -0𝔽.
|
// 2. If argument is "-0", return -0𝔽.
|
||||||
if (argument.as_string().string() == "-0")
|
if (argument.as_string().string() == "-0")
|
||||||
|
|
|
@ -29,7 +29,7 @@ bool validate_and_apply_property_descriptor(Object*, PropertyName const&, bool e
|
||||||
Object* get_prototype_from_constructor(GlobalObject&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)());
|
Object* get_prototype_from_constructor(GlobalObject&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)());
|
||||||
Object* create_unmapped_arguments_object(GlobalObject&, Vector<Value> const& arguments);
|
Object* create_unmapped_arguments_object(GlobalObject&, Vector<Value> const& arguments);
|
||||||
Object* create_mapped_arguments_object(GlobalObject&, FunctionObject&, Vector<FunctionNode::Parameter> const&, Vector<Value> const& arguments, Environment&);
|
Object* create_mapped_arguments_object(GlobalObject&, FunctionObject&, Vector<FunctionNode::Parameter> const&, Vector<Value> const& arguments, Environment&);
|
||||||
Value canonical_numeric_index_string(GlobalObject&, Value);
|
Value canonical_numeric_index_string(GlobalObject&, PropertyName const&);
|
||||||
|
|
||||||
enum class CallerMode {
|
enum class CallerMode {
|
||||||
Strict,
|
Strict,
|
||||||
|
|
|
@ -45,8 +45,6 @@ void StringObject::visit_edges(Cell::Visitor& visitor)
|
||||||
// 10.4.3.5 StringGetOwnProperty ( S, P ),https://tc39.es/ecma262/#sec-stringgetownproperty
|
// 10.4.3.5 StringGetOwnProperty ( S, P ),https://tc39.es/ecma262/#sec-stringgetownproperty
|
||||||
static Optional<PropertyDescriptor> string_get_own_property(GlobalObject& global_object, StringObject const& string, PropertyName const& property_name)
|
static Optional<PropertyDescriptor> string_get_own_property(GlobalObject& global_object, StringObject const& string, PropertyName const& property_name)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
// 1. Assert: S is an Object that has a [[StringData]] internal slot.
|
// 1. Assert: S is an Object that has a [[StringData]] internal slot.
|
||||||
// 2. Assert: IsPropertyKey(P) is true.
|
// 2. Assert: IsPropertyKey(P) is true.
|
||||||
VERIFY(property_name.is_valid());
|
VERIFY(property_name.is_valid());
|
||||||
|
@ -58,14 +56,7 @@ static Optional<PropertyDescriptor> string_get_own_property(GlobalObject& global
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 4. Let index be ! CanonicalNumericIndexString(P).
|
// 4. Let index be ! CanonicalNumericIndexString(P).
|
||||||
// NOTE: If the property name is a number type (An implementation-defined optimized
|
auto index = canonical_numeric_index_string(global_object, property_name);
|
||||||
// property key type), it can be treated as a string property that has already been
|
|
||||||
// converted successfully into a canonical numeric index.
|
|
||||||
Value index;
|
|
||||||
if (property_name.is_string())
|
|
||||||
index = canonical_numeric_index_string(global_object, property_name.to_value(vm));
|
|
||||||
else
|
|
||||||
index = Value(property_name.as_number());
|
|
||||||
// 5. If index is undefined, return undefined.
|
// 5. If index is undefined, return undefined.
|
||||||
if (index.is_undefined())
|
if (index.is_undefined())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -185,19 +185,14 @@ public:
|
||||||
// 2. Assert: O is an Integer-Indexed exotic object.
|
// 2. Assert: O is an Integer-Indexed exotic object.
|
||||||
|
|
||||||
// NOTE: If the property name is a number type (An implementation-defined optimized
|
// NOTE: If the property name is a number type (An implementation-defined optimized
|
||||||
// property key type), it can be treated as a string property that has already been
|
// property key type), it can be treated as a string property that will transparently be
|
||||||
// converted successfully into a canonical numeric index.
|
// converted into a canonical numeric index.
|
||||||
|
|
||||||
// 3. If Type(P) is String, then
|
// 3. If Type(P) is String, then
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
// NOTE: This includes an implementation-defined optimization, see note above!
|
||||||
if (property_name.is_string() || property_name.is_number()) {
|
if (property_name.is_string() || property_name.is_number()) {
|
||||||
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
auto numeric_index = canonical_numeric_index_string(global_object(), property_name);
|
||||||
Value numeric_index;
|
|
||||||
if (property_name.is_string())
|
|
||||||
numeric_index = canonical_numeric_index_string(global_object(), property_name.to_value(vm()));
|
|
||||||
else
|
|
||||||
numeric_index = Value(property_name.as_number());
|
|
||||||
// b. If numericIndex is not undefined, then
|
// b. If numericIndex is not undefined, then
|
||||||
if (!numeric_index.is_undefined()) {
|
if (!numeric_index.is_undefined()) {
|
||||||
// i. Let value be ! IntegerIndexedElementGet(O, numericIndex).
|
// i. Let value be ! IntegerIndexedElementGet(O, numericIndex).
|
||||||
|
@ -230,19 +225,14 @@ public:
|
||||||
// 2. Assert: O is an Integer-Indexed exotic object.
|
// 2. Assert: O is an Integer-Indexed exotic object.
|
||||||
|
|
||||||
// NOTE: If the property name is a number type (An implementation-defined optimized
|
// NOTE: If the property name is a number type (An implementation-defined optimized
|
||||||
// property key type), it can be treated as a string property that has already been
|
// property key type), it can be treated as a string property that will transparently be
|
||||||
// converted successfully into a canonical numeric index.
|
// converted into a canonical numeric index.
|
||||||
|
|
||||||
// 3. If Type(P) is String, then
|
// 3. If Type(P) is String, then
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
// NOTE: This includes an implementation-defined optimization, see note above!
|
||||||
if (property_name.is_string() || property_name.is_number()) {
|
if (property_name.is_string() || property_name.is_number()) {
|
||||||
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
auto numeric_index = canonical_numeric_index_string(global_object(), property_name);
|
||||||
Value numeric_index;
|
|
||||||
if (property_name.is_string())
|
|
||||||
numeric_index = canonical_numeric_index_string(global_object(), property_name.to_value(vm()));
|
|
||||||
else
|
|
||||||
numeric_index = Value(property_name.as_number());
|
|
||||||
// b. If numericIndex is not undefined, return ! IsValidIntegerIndex(O, numericIndex).
|
// b. If numericIndex is not undefined, return ! IsValidIntegerIndex(O, numericIndex).
|
||||||
if (!numeric_index.is_undefined())
|
if (!numeric_index.is_undefined())
|
||||||
return is_valid_integer_index(*this, numeric_index);
|
return is_valid_integer_index(*this, numeric_index);
|
||||||
|
@ -261,19 +251,14 @@ public:
|
||||||
// 2. Assert: O is an Integer-Indexed exotic object.
|
// 2. Assert: O is an Integer-Indexed exotic object.
|
||||||
|
|
||||||
// NOTE: If the property name is a number type (An implementation-defined optimized
|
// NOTE: If the property name is a number type (An implementation-defined optimized
|
||||||
// property key type), it can be treated as a string property that has already been
|
// property key type), it can be treated as a string property that will transparently be
|
||||||
// converted successfully into a canonical numeric index.
|
// converted into a canonical numeric index.
|
||||||
|
|
||||||
// 3. If Type(P) is String, then
|
// 3. If Type(P) is String, then
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
// NOTE: This includes an implementation-defined optimization, see note above!
|
||||||
if (property_name.is_string() || property_name.is_number()) {
|
if (property_name.is_string() || property_name.is_number()) {
|
||||||
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
auto numeric_index = canonical_numeric_index_string(global_object(), property_name);
|
||||||
Value numeric_index;
|
|
||||||
if (property_name.is_string())
|
|
||||||
numeric_index = canonical_numeric_index_string(global_object(), property_name.to_value(vm()));
|
|
||||||
else
|
|
||||||
numeric_index = Value(property_name.as_number());
|
|
||||||
// b. If numericIndex is not undefined, then
|
// b. If numericIndex is not undefined, then
|
||||||
if (!numeric_index.is_undefined()) {
|
if (!numeric_index.is_undefined()) {
|
||||||
// i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false.
|
// i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false.
|
||||||
|
@ -319,21 +304,15 @@ public:
|
||||||
|
|
||||||
// 1. Assert: IsPropertyKey(P) is true.
|
// 1. Assert: IsPropertyKey(P) is true.
|
||||||
VERIFY(property_name.is_valid());
|
VERIFY(property_name.is_valid());
|
||||||
|
|
||||||
// NOTE: If the property name is a number type (An implementation-defined optimized
|
// NOTE: If the property name is a number type (An implementation-defined optimized
|
||||||
// property key type), it can be treated as a string property that has already been
|
// property key type), it can be treated as a string property that will transparently be
|
||||||
// converted successfully into a canonical numeric index.
|
// converted into a canonical numeric index.
|
||||||
|
|
||||||
// 2. If Type(P) is String, then
|
// 2. If Type(P) is String, then
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
// NOTE: This includes an implementation-defined optimization, see note above!
|
||||||
if (property_name.is_string() || property_name.is_number()) {
|
if (property_name.is_string() || property_name.is_number()) {
|
||||||
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
auto numeric_index = canonical_numeric_index_string(global_object(), property_name);
|
||||||
Value numeric_index;
|
|
||||||
if (property_name.is_string())
|
|
||||||
numeric_index = canonical_numeric_index_string(global_object(), property_name.to_value(vm()));
|
|
||||||
else
|
|
||||||
numeric_index = Value(property_name.as_number());
|
|
||||||
// b. If numericIndex is not undefined, then
|
// b. If numericIndex is not undefined, then
|
||||||
if (!numeric_index.is_undefined()) {
|
if (!numeric_index.is_undefined()) {
|
||||||
// i. Return ! IntegerIndexedElementGet(O, numericIndex).
|
// i. Return ! IntegerIndexedElementGet(O, numericIndex).
|
||||||
|
@ -353,21 +332,15 @@ public:
|
||||||
|
|
||||||
// 1. Assert: IsPropertyKey(P) is true.
|
// 1. Assert: IsPropertyKey(P) is true.
|
||||||
VERIFY(property_name.is_valid());
|
VERIFY(property_name.is_valid());
|
||||||
|
|
||||||
// NOTE: If the property name is a number type (An implementation-defined optimized
|
// NOTE: If the property name is a number type (An implementation-defined optimized
|
||||||
// property key type), it can be treated as a string property that has already been
|
// property key type), it can be treated as a string property that will transparently be
|
||||||
// converted successfully into a canonical numeric index.
|
// converted into a canonical numeric index.
|
||||||
|
|
||||||
// 2. If Type(P) is String, then
|
// 2. If Type(P) is String, then
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
// NOTE: This includes an implementation-defined optimization, see note above!
|
||||||
if (property_name.is_string() || property_name.is_number()) {
|
if (property_name.is_string() || property_name.is_number()) {
|
||||||
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
auto numeric_index = canonical_numeric_index_string(global_object(), property_name);
|
||||||
Value numeric_index;
|
|
||||||
if (property_name.is_string())
|
|
||||||
numeric_index = canonical_numeric_index_string(global_object(), property_name.to_value(vm()));
|
|
||||||
else
|
|
||||||
numeric_index = Value(property_name.as_number());
|
|
||||||
// b. If numericIndex is not undefined, then
|
// b. If numericIndex is not undefined, then
|
||||||
if (!numeric_index.is_undefined()) {
|
if (!numeric_index.is_undefined()) {
|
||||||
// i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
|
// i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
|
||||||
|
@ -391,21 +364,15 @@ public:
|
||||||
VERIFY(property_name.is_valid());
|
VERIFY(property_name.is_valid());
|
||||||
|
|
||||||
// 2. Assert: O is an Integer-Indexed exotic object.
|
// 2. Assert: O is an Integer-Indexed exotic object.
|
||||||
|
|
||||||
// NOTE: If the property name is a number type (An implementation-defined optimized
|
// NOTE: If the property name is a number type (An implementation-defined optimized
|
||||||
// property key type), it can be treated as a string property that has already been
|
// property key type), it can be treated as a string property that will transparently be
|
||||||
// converted successfully into a canonical numeric index.
|
// converted into a canonical numeric index.
|
||||||
|
|
||||||
// 3. If Type(P) is String, then
|
// 3. If Type(P) is String, then
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
// NOTE: This includes an implementation-defined optimization, see note above!
|
||||||
if (property_name.is_string() || property_name.is_number()) {
|
if (property_name.is_string() || property_name.is_number()) {
|
||||||
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
// a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||||
// NOTE: This includes an implementation-defined optimization, see note above!
|
auto numeric_index = canonical_numeric_index_string(global_object(), property_name);
|
||||||
Value numeric_index;
|
|
||||||
if (property_name.is_string())
|
|
||||||
numeric_index = canonical_numeric_index_string(global_object(), property_name.to_value(vm()));
|
|
||||||
else
|
|
||||||
numeric_index = Value(property_name.as_number());
|
|
||||||
// b. If numericIndex is not undefined, then
|
// b. If numericIndex is not undefined, then
|
||||||
if (!numeric_index.is_undefined()) {
|
if (!numeric_index.is_undefined()) {
|
||||||
// i. If ! IsValidIntegerIndex(O, numericIndex) is false, return true; else return false.
|
// i. If ! IsValidIntegerIndex(O, numericIndex) is false, return true; else return false.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue