1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2008-2018 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 "Error.h"
24#include "InternalFunction.h"
25#include "NativeErrorPrototype.h"
26
27namespace JSC {
28
29class ErrorInstance;
30class FunctionPrototype;
31class NativeErrorPrototype;
32
33class NativeErrorConstructorBase : public InternalFunction {
34public:
35 using Base = InternalFunction;
36
37 DECLARE_INFO;
38
39 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
40 {
41 return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
42 }
43
44protected:
45 NativeErrorConstructorBase(VM& vm, Structure* structure, NativeFunction functionForCall, NativeFunction functionForConstruct)
46 : InternalFunction(vm, structure, functionForCall, functionForConstruct)
47 {
48 }
49
50 void finishCreation(VM&, NativeErrorPrototype*, ErrorType);
51};
52
53template<ErrorType errorType>
54class NativeErrorConstructor final : public NativeErrorConstructorBase {
55public:
56 static NativeErrorConstructor* create(VM& vm, Structure* structure, NativeErrorPrototype* prototype)
57 {
58 NativeErrorConstructor* constructor = new (NotNull, allocateCell<NativeErrorConstructor>(vm.heap)) NativeErrorConstructor(vm, structure);
59 constructor->finishCreation(vm, prototype, errorType);
60 return constructor;
61 }
62
63 Structure* errorStructure(VM& vm) { return globalObject(vm)->errorStructure(errorType); }
64private:
65 static EncodedJSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState*);
66 static EncodedJSValue JSC_HOST_CALL constructNativeErrorConstructor(ExecState*);
67
68 NativeErrorConstructor(VM&, Structure*);
69};
70
71using EvalErrorConstructor = NativeErrorConstructor<ErrorType::EvalError>;
72using RangeErrorConstructor = NativeErrorConstructor<ErrorType::RangeError>;
73using ReferenceErrorConstructor = NativeErrorConstructor<ErrorType::ReferenceError>;
74using SyntaxErrorConstructor = NativeErrorConstructor<ErrorType::SyntaxError>;
75using TypeErrorConstructor = NativeErrorConstructor<ErrorType::TypeError>;
76using URIErrorConstructor = NativeErrorConstructor<ErrorType::URIError>;
77
78static_assert(sizeof(EvalErrorConstructor) == sizeof(InternalFunction), "");
79static_assert(sizeof(RangeErrorConstructor) == sizeof(InternalFunction), "");
80static_assert(sizeof(ReferenceErrorConstructor) == sizeof(InternalFunction), "");
81static_assert(sizeof(SyntaxErrorConstructor) == sizeof(InternalFunction), "");
82static_assert(sizeof(TypeErrorConstructor) == sizeof(InternalFunction), "");
83static_assert(sizeof(URIErrorConstructor) == sizeof(InternalFunction), "");
84
85} // namespace JSC
86