1 | /* |
2 | * Copyright (C) 1999-2001 Harri Porten ([email protected]) |
3 | * Copyright (C) 2001 Peter Kelly ([email protected]) |
4 | * Copyright (C) 2003-2019 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 | #pragma once |
24 | |
25 | #include "ErrorInstance.h" |
26 | #include "ErrorType.h" |
27 | #include "Exception.h" |
28 | #include "InternalFunction.h" |
29 | #include "JSObject.h" |
30 | #include "ThrowScope.h" |
31 | #include <stdint.h> |
32 | |
33 | |
34 | namespace JSC { |
35 | |
36 | class ExecState; |
37 | class VM; |
38 | class JSGlobalObject; |
39 | class JSObject; |
40 | class SourceCode; |
41 | class Structure; |
42 | |
43 | // ExecState wrappers. |
44 | JSObject* createError(ExecState*, const String&, ErrorInstance::SourceAppender); |
45 | JSObject* createEvalError(ExecState*, const String&, ErrorInstance::SourceAppender); |
46 | JSObject* createRangeError(ExecState*, const String&, ErrorInstance::SourceAppender); |
47 | JSObject* createRangeError(ExecState*, JSGlobalObject*, const String&, ErrorInstance::SourceAppender); |
48 | JSObject* createReferenceError(ExecState*, const String&, ErrorInstance::SourceAppender); |
49 | JSObject* createSyntaxError(ExecState*, const String&, ErrorInstance::SourceAppender); |
50 | JSObject* createTypeError(ExecState*, const String&, ErrorInstance::SourceAppender, RuntimeType); |
51 | JSObject* createNotEnoughArgumentsError(ExecState*, ErrorInstance::SourceAppender); |
52 | JSObject* createURIError(ExecState*, const String&, ErrorInstance::SourceAppender); |
53 | |
54 | |
55 | JS_EXPORT_PRIVATE JSObject* createError(ExecState*, const String&); |
56 | JS_EXPORT_PRIVATE JSObject* createEvalError(ExecState*, const String&); |
57 | JS_EXPORT_PRIVATE JSObject* createRangeError(ExecState*, const String&); |
58 | JS_EXPORT_PRIVATE JSObject* createRangeError(ExecState*, JSGlobalObject*, const String&); |
59 | JS_EXPORT_PRIVATE JSObject* createReferenceError(ExecState*, const String&); |
60 | JS_EXPORT_PRIVATE JSObject* createSyntaxError(ExecState*, const String&); |
61 | JS_EXPORT_PRIVATE JSObject* createTypeError(ExecState*); |
62 | JS_EXPORT_PRIVATE JSObject* createTypeError(ExecState*, const String&); |
63 | JS_EXPORT_PRIVATE JSObject* createNotEnoughArgumentsError(ExecState*); |
64 | JS_EXPORT_PRIVATE JSObject* createURIError(ExecState*, const String&); |
65 | JS_EXPORT_PRIVATE JSObject* createOutOfMemoryError(ExecState*); |
66 | JS_EXPORT_PRIVATE JSObject* createOutOfMemoryError(ExecState*, const String&); |
67 | |
68 | JS_EXPORT_PRIVATE JSObject* createError(ExecState*, ErrorType, const String&); |
69 | |
70 | JSObject* createGetterTypeError(ExecState*, const String&); |
71 | |
72 | std::unique_ptr<Vector<StackFrame>> getStackTrace(ExecState*, VM&, JSObject*, bool useCurrentFrame); |
73 | void getBytecodeOffset(ExecState*, VM&, Vector<StackFrame>*, CallFrame*&, unsigned& bytecodeOffset); |
74 | bool getLineColumnAndSource(Vector<StackFrame>* stackTrace, unsigned& line, unsigned& column, String& sourceURL); |
75 | bool addErrorInfo(VM&, Vector<StackFrame>*, JSObject*); |
76 | JS_EXPORT_PRIVATE void addErrorInfo(ExecState*, JSObject*, bool); |
77 | JSObject* addErrorInfo(ExecState*, JSObject* error, int line, const SourceCode&); |
78 | |
79 | // Methods to throw Errors. |
80 | |
81 | // Convenience wrappers, create an throw an exception with a default message. |
82 | JS_EXPORT_PRIVATE Exception* throwConstructorCannotBeCalledAsFunctionTypeError(ExecState*, ThrowScope&, const char* constructorName); |
83 | JS_EXPORT_PRIVATE Exception* throwTypeError(ExecState*, ThrowScope&); |
84 | JS_EXPORT_PRIVATE Exception* throwTypeError(ExecState*, ThrowScope&, ASCIILiteral errorMessage); |
85 | JS_EXPORT_PRIVATE Exception* throwTypeError(ExecState*, ThrowScope&, const String& errorMessage); |
86 | JS_EXPORT_PRIVATE Exception* throwSyntaxError(ExecState*, ThrowScope&); |
87 | JS_EXPORT_PRIVATE Exception* throwSyntaxError(ExecState*, ThrowScope&, const String& errorMessage); |
88 | inline Exception* throwRangeError(ExecState* state, ThrowScope& scope, const String& errorMessage) { return throwException(state, scope, createRangeError(state, errorMessage)); } |
89 | |
90 | JS_EXPORT_PRIVATE Exception* throwGetterTypeError(ExecState*, ThrowScope&, const String& errorMessage); |
91 | JS_EXPORT_PRIVATE JSValue throwDOMAttributeGetterTypeError(ExecState*, ThrowScope&, const ClassInfo*, PropertyName); |
92 | |
93 | // Convenience wrappers, wrap result as an EncodedJSValue. |
94 | inline void throwVMError(ExecState* exec, ThrowScope& scope, Exception* exception) { throwException(exec, scope, exception); } |
95 | inline EncodedJSValue throwVMError(ExecState* exec, ThrowScope& scope, JSValue error) { return JSValue::encode(throwException(exec, scope, error)); } |
96 | inline EncodedJSValue throwVMError(ExecState* exec, ThrowScope& scope, const char* errorMessage) { return JSValue::encode(throwException(exec, scope, createError(exec, errorMessage))); } |
97 | inline EncodedJSValue throwVMTypeError(ExecState* exec, ThrowScope& scope) { return JSValue::encode(throwTypeError(exec, scope)); } |
98 | inline EncodedJSValue throwVMTypeError(ExecState* exec, ThrowScope& scope, ASCIILiteral errorMessage) { return JSValue::encode(throwTypeError(exec, scope, errorMessage)); } |
99 | inline EncodedJSValue throwVMTypeError(ExecState* exec, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwTypeError(exec, scope, errorMessage)); } |
100 | inline EncodedJSValue throwVMRangeError(ExecState* state, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwRangeError(state, scope, errorMessage)); } |
101 | inline EncodedJSValue throwVMGetterTypeError(ExecState* exec, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwGetterTypeError(exec, scope, errorMessage)); } |
102 | inline EncodedJSValue throwVMDOMAttributeGetterTypeError(ExecState* state, ThrowScope& scope, const ClassInfo* classInfo, PropertyName propertyName) { return JSValue::encode(throwDOMAttributeGetterTypeError(state, scope, classInfo, propertyName)); } |
103 | |
104 | } // namespace JSC |
105 | |