1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21#pragma once
22
23#include "InternalFunction.h"
24
25namespace WTF {
26class TextPosition;
27}
28
29namespace JSC {
30
31class FunctionPrototype;
32
33class FunctionConstructor final : public InternalFunction {
34public:
35 typedef InternalFunction Base;
36
37 static FunctionConstructor* create(VM& vm, Structure* structure, FunctionPrototype* functionPrototype)
38 {
39 FunctionConstructor* constructor = new (NotNull, allocateCell<FunctionConstructor>(vm.heap)) FunctionConstructor(vm, structure);
40 constructor->finishCreation(vm, functionPrototype);
41 return constructor;
42 }
43
44 DECLARE_INFO;
45
46 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
47 {
48 return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
49 }
50
51private:
52 FunctionConstructor(VM&, Structure*);
53 void finishCreation(VM&, FunctionPrototype*);
54};
55
56enum class FunctionConstructionMode {
57 Function,
58 Generator,
59 Async,
60 AsyncGenerator,
61};
62
63JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&, const Identifier& functionName, const SourceOrigin&, const String& sourceURL, const WTF::TextPosition&, FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue());
64JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&, FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue());
65
66JS_EXPORT_PRIVATE JSObject* constructFunctionSkippingEvalEnabledCheck(
67 ExecState*, JSGlobalObject*, const ArgList&, const Identifier&, const SourceOrigin&,
68 const String&, const WTF::TextPosition&, int overrideLineNumber = -1,
69 FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue());
70
71} // namespace JSC
72