]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) | |
4 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Library General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Library General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Library General Public License | |
17 | * along with this library; see the file COPYING.LIB. If not, write to | |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
19 | * Boston, MA 02110-1301, USA. | |
20 | * | |
21 | */ | |
22 | ||
23 | #ifndef Error_h | |
24 | #define Error_h | |
25 | ||
ed1e77d3 | 26 | #include "ErrorInstance.h" |
6fe7ccc8 A |
27 | #include "InternalFunction.h" |
28 | #include "Interpreter.h" | |
14957cd0 | 29 | #include "JSObject.h" |
9dae56ea A |
30 | #include <stdint.h> |
31 | ||
ed1e77d3 | 32 | |
9dae56ea A |
33 | namespace JSC { |
34 | ||
ed1e77d3 A |
35 | class ExecState; |
36 | class VM; | |
37 | class JSGlobalObject; | |
38 | class JSObject; | |
39 | class SourceCode; | |
40 | class Structure; | |
41 | ||
42 | // ExecState wrappers. | |
43 | JSObject* createError(ExecState*, const String&, ErrorInstance::SourceAppender); | |
44 | JSObject* createEvalError(ExecState*, const String&, ErrorInstance::SourceAppender); | |
45 | JSObject* createRangeError(ExecState*, const String&, ErrorInstance::SourceAppender); | |
46 | JSObject* createReferenceError(ExecState*, const String&, ErrorInstance::SourceAppender); | |
47 | JSObject* createSyntaxError(ExecState*, const String&, ErrorInstance::SourceAppender); | |
48 | JSObject* createTypeError(ExecState*, const String&, ErrorInstance::SourceAppender, RuntimeType); | |
49 | JSObject* createNotEnoughArgumentsError(ExecState*, ErrorInstance::SourceAppender); | |
50 | JSObject* createURIError(ExecState*, const String&, ErrorInstance::SourceAppender); | |
51 | JSObject* createOutOfMemoryError(ExecState*, ErrorInstance::SourceAppender); | |
52 | ||
53 | ||
54 | JS_EXPORT_PRIVATE JSObject* createError(ExecState*, const String&); | |
55 | JS_EXPORT_PRIVATE JSObject* createEvalError(ExecState*, const String&); | |
56 | JS_EXPORT_PRIVATE JSObject* createRangeError(ExecState*, const String&); | |
57 | JS_EXPORT_PRIVATE JSObject* createReferenceError(ExecState*, const String&); | |
58 | JS_EXPORT_PRIVATE JSObject* createSyntaxError(ExecState*, const String&); | |
59 | JS_EXPORT_PRIVATE JSObject* createTypeError(ExecState*); | |
60 | JS_EXPORT_PRIVATE JSObject* createTypeError(ExecState*, const String&); | |
61 | JS_EXPORT_PRIVATE JSObject* createNotEnoughArgumentsError(ExecState*); | |
62 | JS_EXPORT_PRIVATE JSObject* createURIError(ExecState*, const String&); | |
63 | JS_EXPORT_PRIVATE JSObject* createOutOfMemoryError(ExecState*); | |
64 | ||
65 | ||
66 | bool addErrorInfoAndGetBytecodeOffset(ExecState*, VM&, JSObject*, bool, CallFrame*&, unsigned&); | |
67 | ||
68 | bool hasErrorInfo(ExecState*, JSObject* error); | |
69 | JS_EXPORT_PRIVATE void addErrorInfo(ExecState*, JSObject*, bool); | |
70 | JSObject* addErrorInfo(ExecState*, JSObject* error, int line, const SourceCode&); | |
71 | ||
72 | // Methods to throw Errors. | |
73 | ||
74 | // Convenience wrappers, create an throw an exception with a default message. | |
75 | JS_EXPORT_PRIVATE JSObject* throwTypeError(ExecState*); | |
76 | JS_EXPORT_PRIVATE JSObject* throwSyntaxError(ExecState*); | |
77 | inline JSObject* throwRangeError(ExecState* state, const String& errorMessage) { return state->vm().throwException(state, createRangeError(state, errorMessage)); } | |
78 | ||
79 | // Convenience wrappers, wrap result as an EncodedJSValue. | |
80 | inline void throwVMError(ExecState* exec, Exception* exception) { exec->vm().throwException(exec, exception); } | |
81 | inline EncodedJSValue throwVMError(ExecState* exec, JSValue error) { return JSValue::encode(exec->vm().throwException(exec, error)); } | |
82 | inline EncodedJSValue throwVMTypeError(ExecState* exec) { return JSValue::encode(throwTypeError(exec)); } | |
83 | inline EncodedJSValue throwVMTypeError(ExecState* exec, const String& errorMessage) { return JSValue::encode(throwTypeError(exec, errorMessage)); } | |
84 | inline EncodedJSValue throwVMRangeError(ExecState* state, const String& errorMessage) { return JSValue::encode(throwRangeError(state, errorMessage)); } | |
85 | ||
86 | class StrictModeTypeErrorFunction : public InternalFunction { | |
87 | private: | |
88 | StrictModeTypeErrorFunction(VM& vm, Structure* structure, const String& message) | |
89 | : InternalFunction(vm, structure) | |
90 | , m_message(message) | |
91 | { | |
92 | } | |
93 | ||
94 | static void destroy(JSCell*); | |
95 | ||
96 | public: | |
97 | typedef InternalFunction Base; | |
98 | ||
99 | static StrictModeTypeErrorFunction* create(VM& vm, Structure* structure, const String& message) | |
100 | { | |
101 | StrictModeTypeErrorFunction* function = new (NotNull, allocateCell<StrictModeTypeErrorFunction>(vm.heap)) StrictModeTypeErrorFunction(vm, structure, message); | |
102 | function->finishCreation(vm, String()); | |
103 | return function; | |
104 | } | |
105 | ||
106 | static EncodedJSValue JSC_HOST_CALL constructThrowTypeError(ExecState* exec) | |
107 | { | |
108 | throwTypeError(exec, static_cast<StrictModeTypeErrorFunction*>(exec->callee())->m_message); | |
109 | return JSValue::encode(jsNull()); | |
110 | } | |
111 | ||
112 | static ConstructType getConstructData(JSCell*, ConstructData& constructData) | |
113 | { | |
114 | constructData.native.function = constructThrowTypeError; | |
115 | return ConstructTypeHost; | |
116 | } | |
117 | ||
118 | static EncodedJSValue JSC_HOST_CALL callThrowTypeError(ExecState* exec) | |
119 | { | |
120 | throwTypeError(exec, static_cast<StrictModeTypeErrorFunction*>(exec->callee())->m_message); | |
121 | return JSValue::encode(jsNull()); | |
122 | } | |
123 | ||
124 | static CallType getCallData(JSCell*, CallData& callData) | |
125 | { | |
126 | callData.native.function = callThrowTypeError; | |
127 | return CallTypeHost; | |
128 | } | |
129 | ||
130 | DECLARE_INFO; | |
131 | ||
132 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) | |
133 | { | |
134 | return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); | |
135 | } | |
136 | ||
137 | private: | |
138 | String m_message; | |
139 | }; | |
6fe7ccc8 | 140 | |
9dae56ea A |
141 | } // namespace JSC |
142 | ||
143 | #endif // Error_h |