mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
LibJS: Add the same Object::invoke() overloads as VM::call()
This commit is contained in:
parent
6cf8e3c980
commit
6d2d8d091f
2 changed files with 23 additions and 2 deletions
|
@ -883,7 +883,7 @@ Value Object::ordinary_to_primitive(Value::PreferredType preferred_type) const
|
|||
return {};
|
||||
}
|
||||
|
||||
Value Object::invoke(const StringOrSymbol& property_name, Optional<MarkedValueList> arguments)
|
||||
Value Object::invoke_internal(const StringOrSymbol& property_name, Optional<MarkedValueList> arguments)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto property = get(property_name).value_or(js_undefined());
|
||||
|
|
|
@ -133,7 +133,19 @@ public:
|
|||
IndexedProperties& indexed_properties() { return m_indexed_properties; }
|
||||
void set_indexed_property_elements(Vector<Value>&& values) { m_indexed_properties = IndexedProperties(move(values)); }
|
||||
|
||||
Value invoke(const StringOrSymbol& property_name, Optional<MarkedValueList> arguments = {});
|
||||
[[nodiscard]] Value invoke_internal(const StringOrSymbol& property_name, Optional<MarkedValueList> arguments);
|
||||
|
||||
template<typename... Args>
|
||||
[[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<MarkedValueList> arguments) { return invoke_internal(property_name, move(arguments)); }
|
||||
|
||||
template<>
|
||||
[[nodiscard]] ALWAYS_INLINE Value Object::invoke(const StringOrSymbol& property_name) { return invoke(property_name, Optional<MarkedValueList> {}); }
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue