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 | |
27 | namespace JSC { |
28 | |
29 | class ErrorInstance; |
30 | class FunctionPrototype; |
31 | class NativeErrorPrototype; |
32 | |
33 | class NativeErrorConstructorBase : public InternalFunction { |
34 | public: |
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 | |
44 | protected: |
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 | |
53 | template<ErrorType errorType> |
54 | class NativeErrorConstructor final : public NativeErrorConstructorBase { |
55 | public: |
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); } |
64 | private: |
65 | static EncodedJSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState*); |
66 | static EncodedJSValue JSC_HOST_CALL constructNativeErrorConstructor(ExecState*); |
67 | |
68 | NativeErrorConstructor(VM&, Structure*); |
69 | }; |
70 | |
71 | using EvalErrorConstructor = NativeErrorConstructor<ErrorType::EvalError>; |
72 | using RangeErrorConstructor = NativeErrorConstructor<ErrorType::RangeError>; |
73 | using ReferenceErrorConstructor = NativeErrorConstructor<ErrorType::ReferenceError>; |
74 | using SyntaxErrorConstructor = NativeErrorConstructor<ErrorType::SyntaxError>; |
75 | using TypeErrorConstructor = NativeErrorConstructor<ErrorType::TypeError>; |
76 | using URIErrorConstructor = NativeErrorConstructor<ErrorType::URIError>; |
77 | |
78 | static_assert(sizeof(EvalErrorConstructor) == sizeof(InternalFunction), "" ); |
79 | static_assert(sizeof(RangeErrorConstructor) == sizeof(InternalFunction), "" ); |
80 | static_assert(sizeof(ReferenceErrorConstructor) == sizeof(InternalFunction), "" ); |
81 | static_assert(sizeof(SyntaxErrorConstructor) == sizeof(InternalFunction), "" ); |
82 | static_assert(sizeof(TypeErrorConstructor) == sizeof(InternalFunction), "" ); |
83 | static_assert(sizeof(URIErrorConstructor) == sizeof(InternalFunction), "" ); |
84 | |
85 | } // namespace JSC |
86 | |