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 CallFrame; |
37 | class VM; |
38 | class JSGlobalObject; |
39 | class JSObject; |
40 | class SourceCode; |
41 | class Structure; |
42 | |
43 | JSObject* createError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender); |
44 | JSObject* createEvalError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender); |
45 | JSObject* createRangeError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender); |
46 | JSObject* createReferenceError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender); |
47 | JSObject* createSyntaxError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender); |
48 | JSObject* createTypeError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender, RuntimeType); |
49 | JSObject* createNotEnoughArgumentsError(JSGlobalObject*, ErrorInstance::SourceAppender); |
50 | JSObject* createURIError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender); |
51 | |
52 | |
53 | JS_EXPORT_PRIVATE JSObject* createError(JSGlobalObject*, const String&); |
54 | JS_EXPORT_PRIVATE JSObject* createEvalError(JSGlobalObject*, const String&); |
55 | JS_EXPORT_PRIVATE JSObject* createRangeError(JSGlobalObject*, const String&); |
56 | JS_EXPORT_PRIVATE JSObject* createReferenceError(JSGlobalObject*, const String&); |
57 | JS_EXPORT_PRIVATE JSObject* createSyntaxError(JSGlobalObject*, const String&); |
58 | JS_EXPORT_PRIVATE JSObject* createTypeError(JSGlobalObject*); |
59 | JS_EXPORT_PRIVATE JSObject* createTypeError(JSGlobalObject*, const String&); |
60 | JS_EXPORT_PRIVATE JSObject* createNotEnoughArgumentsError(JSGlobalObject*); |
61 | JS_EXPORT_PRIVATE JSObject* createURIError(JSGlobalObject*, const String&); |
62 | JS_EXPORT_PRIVATE JSObject* createOutOfMemoryError(JSGlobalObject*); |
63 | JS_EXPORT_PRIVATE JSObject* createOutOfMemoryError(JSGlobalObject*, const String&); |
64 | |
65 | JS_EXPORT_PRIVATE JSObject* createError(JSGlobalObject*, ErrorType, const String&); |
66 | |
67 | JSObject* createGetterTypeError(JSGlobalObject*, const String&); |
68 | |
69 | std::unique_ptr<Vector<StackFrame>> getStackTrace(JSGlobalObject*, VM&, JSObject*, bool useCurrentFrame); |
70 | void getBytecodeIndex(VM&, CallFrame*, Vector<StackFrame>*, CallFrame*&, BytecodeIndex&); |
71 | bool getLineColumnAndSource(Vector<StackFrame>* stackTrace, unsigned& line, unsigned& column, String& sourceURL); |
72 | bool addErrorInfo(VM&, Vector<StackFrame>*, JSObject*); |
73 | JS_EXPORT_PRIVATE void addErrorInfo(JSGlobalObject*, JSObject*, bool); |
74 | JSObject* addErrorInfo(VM&, JSObject* error, int line, const SourceCode&); |
75 | |
76 | // Methods to throw Errors. |
77 | |
78 | // Convenience wrappers, create an throw an exception with a default message. |
79 | JS_EXPORT_PRIVATE Exception* throwConstructorCannotBeCalledAsFunctionTypeError(JSGlobalObject*, ThrowScope&, const char* constructorName); |
80 | JS_EXPORT_PRIVATE Exception* throwTypeError(JSGlobalObject*, ThrowScope&); |
81 | JS_EXPORT_PRIVATE Exception* throwTypeError(JSGlobalObject*, ThrowScope&, ASCIILiteral errorMessage); |
82 | JS_EXPORT_PRIVATE Exception* throwTypeError(JSGlobalObject*, ThrowScope&, const String& errorMessage); |
83 | JS_EXPORT_PRIVATE Exception* throwSyntaxError(JSGlobalObject*, ThrowScope&); |
84 | JS_EXPORT_PRIVATE Exception* throwSyntaxError(JSGlobalObject*, ThrowScope&, const String& errorMessage); |
85 | inline Exception* throwRangeError(JSGlobalObject* globalObject, ThrowScope& scope, const String& errorMessage) { return throwException(globalObject, scope, createRangeError(globalObject, errorMessage)); } |
86 | |
87 | JS_EXPORT_PRIVATE Exception* throwGetterTypeError(JSGlobalObject*, ThrowScope&, const String& errorMessage); |
88 | JS_EXPORT_PRIVATE JSValue throwDOMAttributeGetterTypeError(JSGlobalObject*, ThrowScope&, const ClassInfo*, PropertyName); |
89 | |
90 | // Convenience wrappers, wrap result as an EncodedJSValue. |
91 | inline void throwVMError(JSGlobalObject* globalObject, ThrowScope& scope, Exception* exception) { throwException(globalObject, scope, exception); } |
92 | inline EncodedJSValue throwVMError(JSGlobalObject* globalObject, ThrowScope& scope, JSValue error) { return JSValue::encode(throwException(globalObject, scope, error)); } |
93 | inline EncodedJSValue throwVMError(JSGlobalObject* globalObject, ThrowScope& scope, const char* errorMessage) { return JSValue::encode(throwException(globalObject, scope, createError(globalObject, errorMessage))); } |
94 | inline EncodedJSValue throwVMTypeError(JSGlobalObject* globalObject, ThrowScope& scope) { return JSValue::encode(throwTypeError(globalObject, scope)); } |
95 | inline EncodedJSValue throwVMTypeError(JSGlobalObject* globalObject, ThrowScope& scope, ASCIILiteral errorMessage) { return JSValue::encode(throwTypeError(globalObject, scope, errorMessage)); } |
96 | inline EncodedJSValue throwVMTypeError(JSGlobalObject* globalObject, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwTypeError(globalObject, scope, errorMessage)); } |
97 | inline EncodedJSValue throwVMRangeError(JSGlobalObject* globalObject, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwRangeError(globalObject, scope, errorMessage)); } |
98 | inline EncodedJSValue throwVMGetterTypeError(JSGlobalObject* globalObject, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwGetterTypeError(globalObject, scope, errorMessage)); } |
99 | inline EncodedJSValue throwVMDOMAttributeGetterTypeError(JSGlobalObject* globalObject, ThrowScope& scope, const ClassInfo* classInfo, PropertyName propertyName) { return JSValue::encode(throwDOMAttributeGetterTypeError(globalObject, scope, classInfo, propertyName)); } |
100 | |
101 | } // namespace JSC |
102 | |