From 56d8098d138463fa9c4e2730337daf7690f9c4d1 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Fri, 9 Jul 2021 23:45:01 +0300 Subject: [PATCH] LibJS: Use PropertyName instead of StringOrSymbol in Object::invoke() This prevents the unnecessary PropertyName -> StringOrSymbol -> PropertyName conversion. --- Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/DatePrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Object.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Object.h | 10 +++++----- Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp | 8 ++++---- Userland/Libraries/LibJS/Runtime/StringPrototype.cpp | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 5fe1fa7847..afb279b507 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -540,7 +540,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string) auto* value_object = value.to_object(global_object); if (!value_object) return {}; - auto locale_string_result = value_object->invoke(vm.names.toLocaleString.as_string()); + auto locale_string_result = value_object->invoke(vm.names.toLocaleString); if (vm.exception()) return {}; auto string = locale_string_result.to_string(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 4627d3ebb4..09e7ed8bbf 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -856,7 +856,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json) if (time_value.is_number() && !time_value.is_finite_number()) return js_null(); - return this_object->invoke(vm.names.toISOString.as_string()); + return this_object->invoke(vm.names.toISOString); } // 14.1.1 Date.prototype.toTemporalInstant ( ), https://tc39.es/proposal-temporal/#sec-date.prototype.totemporalinstant diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index b84aa73635..03ddeb6b12 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -1201,7 +1201,7 @@ Value Object::ordinary_to_primitive(Value::PreferredType preferred_type) const return {}; } -Value Object::invoke_internal(const StringOrSymbol& property_name, Optional arguments) +Value Object::invoke_internal(PropertyName const& property_name, Optional arguments) { auto& vm = this->vm(); auto property = get(property_name); diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 665c6312bf..1bd7428146 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -150,10 +150,10 @@ public: IndexedProperties& indexed_properties() { return m_indexed_properties; } void set_indexed_property_elements(Vector&& values) { m_indexed_properties = IndexedProperties(move(values)); } - [[nodiscard]] Value invoke_internal(const StringOrSymbol& property_name, Optional arguments); + [[nodiscard]] Value invoke_internal(PropertyName const&, Optional arguments); template - [[nodiscard]] ALWAYS_INLINE Value invoke(const StringOrSymbol& property_name, Args... args) + [[nodiscard]] ALWAYS_INLINE Value invoke(PropertyName const& property_name, Args... args) { if constexpr (sizeof...(Args) > 0) { MarkedValueList arglist { heap() }; @@ -202,12 +202,12 @@ private: }; template<> -[[nodiscard]] ALWAYS_INLINE Value Object::invoke(const StringOrSymbol& property_name, MarkedValueList arguments) { return invoke_internal(property_name, move(arguments)); } +[[nodiscard]] ALWAYS_INLINE Value Object::invoke(PropertyName const& property_name, MarkedValueList arguments) { return invoke_internal(property_name, move(arguments)); } template<> -[[nodiscard]] ALWAYS_INLINE Value Object::invoke(const StringOrSymbol& property_name, Optional arguments) { return invoke_internal(property_name, move(arguments)); } +[[nodiscard]] ALWAYS_INLINE Value Object::invoke(PropertyName const& property_name, Optional arguments) { return invoke_internal(property_name, move(arguments)); } template<> -[[nodiscard]] ALWAYS_INLINE Value Object::invoke(const StringOrSymbol& property_name) { return invoke(property_name, Optional {}); } +[[nodiscard]] ALWAYS_INLINE Value Object::invoke(PropertyName const& property_name) { return invoke(property_name, Optional {}); } } diff --git a/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp index 21a17bd9ce..10a70ca700 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp @@ -148,7 +148,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_locale_string) auto* this_object = vm.this_value(global_object).to_object(global_object); if (!this_object) return {}; - return this_object->invoke(vm.names.toString.as_string()); + return this_object->invoke(vm.names.toString); } // 20.1.3.7 Object.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-object.prototype.valueof diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp index f05f7a9e35..75f436ccb7 100644 --- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp @@ -71,7 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::catch_) if (!this_object) return {}; auto on_rejected = vm.argument(0); - return this_object->invoke(vm.names.then.as_string(), js_undefined(), on_rejected); + return this_object->invoke(vm.names.then, js_undefined(), on_rejected); } // 27.2.5.3 Promise.prototype.finally ( onFinally ), https://tc39.es/ecma262/#sec-promise.prototype.finally @@ -104,7 +104,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) auto* value_thunk = NativeFunction::create(global_object, "", [value](auto&, auto&) -> Value { return value; }); - return promise->invoke(vm.names.then.as_string(), value_thunk); + return promise->invoke(vm.names.then, value_thunk); }); then_finally_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable); @@ -123,14 +123,14 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) vm.throw_exception(global_object, reason); return {}; }); - return promise->invoke(vm.names.then.as_string(), thrower); + return promise->invoke(vm.names.then, thrower); }); catch_finally_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable); then_finally = Value(then_finally_function); catch_finally = Value(catch_finally_function); } - return promise->invoke(vm.names.then.as_string(), then_finally, catch_finally); + return promise->invoke(vm.names.then, then_finally, catch_finally); } } diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index e44bdc676e..715b118221 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -735,7 +735,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match) auto rx = regexp_create(global_object, regexp, js_undefined()); if (!rx) return {}; - return rx->invoke(vm.well_known_symbol_match(), js_string(vm, s)); + return rx->invoke(*vm.well_known_symbol_match(), js_string(vm, s)); } // 22.1.3.12 String.prototype.matchAll ( regexp ), https://tc39.es/ecma262/#sec-string.prototype.matchall @@ -775,7 +775,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all) auto rx = regexp_create(global_object, regexp, js_string(vm, "g")); if (!rx) return {}; - return rx->invoke(vm.well_known_symbol_match_all(), js_string(vm, s)); + return rx->invoke(*vm.well_known_symbol_match_all(), js_string(vm, s)); } // 22.1.3.17 String.prototype.replace ( searchValue, replaceValue ), https://tc39.es/ecma262/#sec-string.prototype.replace @@ -959,7 +959,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search) auto rx = regexp_create(global_object, regexp, js_undefined()); if (!rx) return {}; - return rx->invoke(vm.well_known_symbol_search(), js_string(vm, s)); + return rx->invoke(*vm.well_known_symbol_search(), js_string(vm, s)); } // B.2.3.2.1 CreateHTML ( string, tag, attribute, value ), https://tc39.es/ecma262/#sec-createhtml