weinig@apple.com | f157abf | 2008-07-05 05:35:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) |
| 3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
mark.lam@apple.com | 60c090d | 2019-03-07 10:16:58 +0000 | [diff] [blame] | 4 | * Copyright (C) 2003-2019 Apple Inc. All rights reserved. |
weinig@apple.com | f157abf | 2008-07-05 05:35:09 +0000 | [diff] [blame] | 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 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 23 | #pragma once |
weinig@apple.com | f157abf | 2008-07-05 05:35:09 +0000 | [diff] [blame] | 24 | |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 25 | #include "ErrorInstance.h" |
ysuzuki@apple.com | f4986c8 | 2019-01-26 09:07:25 +0000 | [diff] [blame] | 26 | #include "ErrorType.h" |
mark.lam@apple.com | 60c090d | 2019-03-07 10:16:58 +0000 | [diff] [blame] | 27 | #include "Exception.h" |
mhahnenberg@apple.com | 6fb47cf | 2011-10-10 22:32:00 +0000 | [diff] [blame] | 28 | #include "InternalFunction.h" |
barraclough@apple.com | 9c099f9 | 2010-06-06 23:34:36 +0000 | [diff] [blame] | 29 | #include "JSObject.h" |
mark.lam@apple.com | 284f456 | 2016-08-30 20:54:54 +0000 | [diff] [blame] | 30 | #include "ThrowScope.h" |
ggaren@apple.com | 306b0d5 | 2008-10-02 07:04:10 +0000 | [diff] [blame] | 31 | #include <stdint.h> |
| 32 | |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 33 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 34 | namespace JSC { |
weinig@apple.com | f157abf | 2008-07-05 05:35:09 +0000 | [diff] [blame] | 35 | |
ysuzuki@apple.com | 622e869 | 2019-10-07 23:13:45 +0000 | [diff] [blame] | 36 | class CallFrame; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 37 | class VM; |
| 38 | class JSGlobalObject; |
| 39 | class JSObject; |
| 40 | class SourceCode; |
| 41 | class Structure; |
weinig@apple.com | f157abf | 2008-07-05 05:35:09 +0000 | [diff] [blame] | 42 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 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); |
mmirman@apple.com | c35dac9 | 2015-04-07 21:34:05 +0000 | [diff] [blame] | 51 | |
| 52 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 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&); |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 64 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 65 | JS_EXPORT_PRIVATE JSObject* createError(JSGlobalObject*, ErrorType, const String&); |
utatane.tea@gmail.com | 0eb0f83 | 2016-10-06 07:44:23 +0000 | [diff] [blame] | 66 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 67 | JSObject* createGetterTypeError(JSGlobalObject*, const String&); |
drousso@apple.com | aad5608 | 2019-04-16 00:02:32 +0000 | [diff] [blame] | 68 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 69 | std::unique_ptr<Vector<StackFrame>> getStackTrace(JSGlobalObject*, VM&, JSObject*, bool useCurrentFrame); |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 70 | void getBytecodeIndex(VM&, CallFrame*, Vector<StackFrame>*, CallFrame*&, BytecodeIndex&); |
fpizlo@apple.com | a06a0d2 | 2017-09-10 19:00:03 +0000 | [diff] [blame] | 71 | bool getLineColumnAndSource(Vector<StackFrame>* stackTrace, unsigned& line, unsigned& column, String& sourceURL); |
| 72 | bool addErrorInfo(VM&, Vector<StackFrame>*, JSObject*); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 73 | JS_EXPORT_PRIVATE void addErrorInfo(JSGlobalObject*, JSObject*, bool); |
| 74 | JSObject* addErrorInfo(VM&, JSObject* error, int line, const SourceCode&); |
barraclough@apple.com | 9c099f9 | 2010-06-06 23:34:36 +0000 | [diff] [blame] | 75 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 76 | // Methods to throw Errors. |
weinig@apple.com | f157abf | 2008-07-05 05:35:09 +0000 | [diff] [blame] | 77 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 78 | // Convenience wrappers, create an throw an exception with a default message. |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 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)); } |
drousso@apple.com | aad5608 | 2019-04-16 00:02:32 +0000 | [diff] [blame] | 86 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 87 | JS_EXPORT_PRIVATE Exception* throwGetterTypeError(JSGlobalObject*, ThrowScope&, const String& errorMessage); |
| 88 | JS_EXPORT_PRIVATE JSValue throwDOMAttributeGetterTypeError(JSGlobalObject*, ThrowScope&, const ClassInfo*, PropertyName); |
barraclough@apple.com | 9c099f9 | 2010-06-06 23:34:36 +0000 | [diff] [blame] | 89 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 90 | // Convenience wrappers, wrap result as an EncodedJSValue. |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 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)); } |
mhahnenberg@apple.com | 6fb47cf | 2011-10-10 22:32:00 +0000 | [diff] [blame] | 100 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 101 | } // namespace JSC |