2020-04-04 13:34:31 +00:00
|
|
|
/*
|
2022-08-21 19:38:35 +00:00
|
|
|
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
2020-04-04 13:34:31 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-04 13:34:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-15 16:26:06 +00:00
|
|
|
#include <LibJS/Runtime/FunctionKind.h>
|
2020-04-04 13:34:31 +00:00
|
|
|
#include <LibJS/Runtime/NativeFunction.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2024-11-03 07:10:56 +00:00
|
|
|
struct ParameterArgumentsAndBody {
|
|
|
|
Vector<String> parameters;
|
|
|
|
String body;
|
|
|
|
};
|
|
|
|
|
|
|
|
ThrowCompletionOr<ParameterArgumentsAndBody> extract_parameter_arguments_and_body(VM&, Span<Value> arguments);
|
|
|
|
|
2020-04-04 13:34:31 +00:00
|
|
|
class FunctionConstructor final : public NativeFunction {
|
2020-06-21 13:14:02 +00:00
|
|
|
JS_OBJECT(FunctionConstructor, NativeFunction);
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_DECLARE_ALLOCATOR(FunctionConstructor);
|
2020-06-21 13:14:02 +00:00
|
|
|
|
2020-04-04 13:34:31 +00:00
|
|
|
public:
|
2024-11-14 15:01:23 +00:00
|
|
|
static ThrowCompletionOr<GC::Ref<ECMAScriptFunctionObject>> create_dynamic_function(VM&, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, ReadonlySpan<String> parameter_args, String const& body_string);
|
2021-06-16 17:52:48 +00:00
|
|
|
|
2023-08-07 06:41:28 +00:00
|
|
|
virtual void initialize(Realm&) override;
|
2022-03-14 16:25:06 +00:00
|
|
|
virtual ~FunctionConstructor() override = default;
|
2020-04-04 13:34:31 +00:00
|
|
|
|
2021-10-20 20:16:30 +00:00
|
|
|
virtual ThrowCompletionOr<Value> call() override;
|
2024-11-14 15:01:23 +00:00
|
|
|
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
|
2020-04-04 13:34:31 +00:00
|
|
|
|
|
|
|
private:
|
2022-08-28 21:51:28 +00:00
|
|
|
explicit FunctionConstructor(Realm&);
|
|
|
|
|
2020-04-04 13:34:31 +00:00
|
|
|
virtual bool has_constructor() const override { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|