From 6d2d8d091fa33948599762fa15102ce4afc8ca74 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 14 Mar 2021 12:01:18 +0100 Subject: [PATCH] LibJS: Add the same Object::invoke() overloads as VM::call() --- Userland/Libraries/LibJS/Runtime/Object.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Object.h | 23 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 98f03237f1..8951de17b9 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -883,7 +883,7 @@ Value Object::ordinary_to_primitive(Value::PreferredType preferred_type) const return {}; } -Value Object::invoke(const StringOrSymbol& property_name, Optional arguments) +Value Object::invoke_internal(const StringOrSymbol& property_name, Optional arguments) { auto& vm = this->vm(); auto property = get(property_name).value_or(js_undefined()); diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index e869aee748..0e496fefb3 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -133,7 +133,19 @@ public: IndexedProperties& indexed_properties() { return m_indexed_properties; } void set_indexed_property_elements(Vector&& values) { m_indexed_properties = IndexedProperties(move(values)); } - Value invoke(const StringOrSymbol& property_name, Optional arguments = {}); + [[nodiscard]] Value invoke_internal(const StringOrSymbol& property_name, Optional arguments); + + template + [[nodiscard]] ALWAYS_INLINE Value invoke(const StringOrSymbol& property_name, Args... args) + { + if constexpr (sizeof...(Args) > 0) { + MarkedValueList arglist { heap() }; + (..., arglist.append(move(args))); + return invoke(property_name, move(arglist)); + } + + return invoke(property_name); + } void ensure_shape_is_unique(); @@ -165,4 +177,13 @@ private: IndexedProperties m_indexed_properties; }; +template<> +[[nodiscard]] ALWAYS_INLINE Value Object::invoke(const StringOrSymbol& 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)); } + +template<> +[[nodiscard]] ALWAYS_INLINE Value Object::invoke(const StringOrSymbol& property_name) { return invoke(property_name, Optional {}); } + }