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