mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibJS: Add templated overloads for the construct AO to create its MVL
Instead of requiring callers to construct a MarkedValueList, add a variadic templated overload to construct the MVL on the caller's behalf.
This commit is contained in:
parent
4661a0f228
commit
67e02f6ca6
Notes:
sideshowbarker
2024-07-17 20:13:29 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/67e02f6ca60 Pull-request: https://github.com/SerenityOS/serenity/pull/12136
2 changed files with 25 additions and 2 deletions
|
@ -74,7 +74,7 @@ ThrowCompletionOr<Value> call_impl(GlobalObject& global_object, FunctionObject&
|
|||
}
|
||||
|
||||
// 7.3.15 Construct ( F [ , argumentsList [ , newTarget ] ] ), https://tc39.es/ecma262/#sec-construct
|
||||
ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, Optional<MarkedValueList> arguments_list, FunctionObject* new_target)
|
||||
ThrowCompletionOr<Object*> construct_impl(GlobalObject& global_object, FunctionObject& function, Optional<MarkedValueList> arguments_list, FunctionObject* new_target)
|
||||
{
|
||||
// 1. If newTarget is not present, set newTarget to F.
|
||||
if (!new_target)
|
||||
|
|
|
@ -27,7 +27,7 @@ ThrowCompletionOr<Reference> make_super_property_reference(GlobalObject&, Value
|
|||
ThrowCompletionOr<Value> require_object_coercible(GlobalObject&, Value);
|
||||
ThrowCompletionOr<Value> call_impl(GlobalObject&, Value function, Value this_value, Optional<MarkedValueList> = {});
|
||||
ThrowCompletionOr<Value> call_impl(GlobalObject&, FunctionObject& function, Value this_value, Optional<MarkedValueList> = {});
|
||||
ThrowCompletionOr<Object*> construct(GlobalObject&, FunctionObject&, Optional<MarkedValueList> = {}, FunctionObject* new_target = nullptr);
|
||||
ThrowCompletionOr<Object*> construct_impl(GlobalObject&, FunctionObject&, Optional<MarkedValueList> = {}, FunctionObject* new_target = nullptr);
|
||||
ThrowCompletionOr<size_t> length_of_array_like(GlobalObject&, Object const&);
|
||||
ThrowCompletionOr<MarkedValueList> create_list_from_array_like(GlobalObject&, Value, Function<ThrowCompletionOr<void>(Value)> = {});
|
||||
ThrowCompletionOr<FunctionObject*> species_constructor(GlobalObject&, Object const&, FunctionObject& default_constructor);
|
||||
|
@ -98,6 +98,29 @@ ALWAYS_INLINE ThrowCompletionOr<Value> call(GlobalObject& global_object, Functio
|
|||
return call_impl(global_object, function, this_value);
|
||||
}
|
||||
|
||||
// 7.3.15 Construct ( F [ , argumentsList [ , newTarget ] ] ), https://tc39.es/ecma262/#sec-construct
|
||||
template<typename... Args>
|
||||
ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, Args&&... args)
|
||||
{
|
||||
if constexpr (sizeof...(Args) > 0) {
|
||||
MarkedValueList arguments_list { global_object.heap() };
|
||||
(..., arguments_list.append(forward<Args>(args)));
|
||||
return construct_impl(global_object, function, move(arguments_list));
|
||||
}
|
||||
|
||||
return construct_impl(global_object, function);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, MarkedValueList arguments_list, FunctionObject* new_target = nullptr)
|
||||
{
|
||||
return construct_impl(global_object, function, move(arguments_list), new_target);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object, FunctionObject& function, Optional<MarkedValueList> arguments_list, FunctionObject* new_target = nullptr)
|
||||
{
|
||||
return construct_impl(global_object, function, move(arguments_list), new_target);
|
||||
}
|
||||
|
||||
// 10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinarycreatefromconstructor
|
||||
template<typename T, typename... Args>
|
||||
ThrowCompletionOr<T*> ordinary_create_from_constructor(GlobalObject& global_object, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)(), Args&&... args)
|
||||
|
|
Loading…
Add table
Reference in a new issue