/src/serenity/Userland/Libraries/LibJS/Runtime/FunctionConstructor.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibJS/Runtime/FunctionKind.h> |
10 | | #include <LibJS/Runtime/NativeFunction.h> |
11 | | |
12 | | namespace JS { |
13 | | |
14 | | struct ParameterArgumentsAndBody { |
15 | | Vector<String> parameters; |
16 | | String body; |
17 | | }; |
18 | | |
19 | | ThrowCompletionOr<ParameterArgumentsAndBody> extract_parameter_arguments_and_body(VM&, Span<Value> arguments); |
20 | | |
21 | | class FunctionConstructor final : public NativeFunction { |
22 | | JS_OBJECT(FunctionConstructor, NativeFunction); |
23 | | JS_DECLARE_ALLOCATOR(FunctionConstructor); |
24 | | |
25 | | public: |
26 | | static ThrowCompletionOr<NonnullGCPtr<ECMAScriptFunctionObject>> create_dynamic_function(VM&, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, ReadonlySpan<String> parameter_args, String const& body_string); |
27 | | |
28 | | virtual void initialize(Realm&) override; |
29 | | virtual ~FunctionConstructor() override = default; |
30 | | |
31 | | virtual ThrowCompletionOr<Value> call() override; |
32 | | virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override; |
33 | | |
34 | | private: |
35 | | explicit FunctionConstructor(Realm&); |
36 | | |
37 | 0 | virtual bool has_constructor() const override { return true; } |
38 | | }; |
39 | | |
40 | | } |