1 | /* |
2 | * Copyright (C) 1999-2001 Harri Porten ([email protected]) |
3 | * Copyright (C) 2003-2017 Apple Inc. All rights reserved. |
4 | * Copyright (C) 2007 Samuel Weinig <[email protected]> |
5 | * Copyright (C) 2009 Google, Inc. All rights reserved. |
6 | * Copyright (C) 2012 Ericsson AB. All rights reserved. |
7 | * Copyright (C) 2013 Michael Pruett <[email protected]> |
8 | * |
9 | * This library is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU Lesser General Public |
11 | * License as published by the Free Software Foundation; either |
12 | * version 2 of the License, or (at your option) any later version. |
13 | * |
14 | * This library is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | * Lesser General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU Lesser General Public |
20 | * License along with this library; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | */ |
23 | |
24 | #pragma once |
25 | |
26 | #include "ExceptionOr.h" |
27 | #include <JavaScriptCore/ThrowScope.h> |
28 | |
29 | namespace JSC { |
30 | class CatchScope; |
31 | } |
32 | |
33 | namespace WebCore { |
34 | |
35 | class CachedScript; |
36 | class DeferredPromise; |
37 | class JSDOMGlobalObject; |
38 | |
39 | struct ExceptionDetails { |
40 | String message; |
41 | int lineNumber { 0 }; |
42 | int columnNumber { 0 }; |
43 | String sourceURL; |
44 | }; |
45 | |
46 | void throwAttributeTypeError(JSC::ExecState&, JSC::ThrowScope&, const char* interfaceName, const char* attributeName, const char* expectedType); |
47 | WEBCORE_EXPORT bool throwSetterTypeError(JSC::ExecState&, JSC::ThrowScope&, const char* interfaceName, const char* attributeName); |
48 | |
49 | void throwDataCloneError(JSC::ExecState&, JSC::ThrowScope&); |
50 | void throwDOMSyntaxError(JSC::ExecState&, JSC::ThrowScope&, ASCIILiteral); // Not the same as a JavaScript syntax error. |
51 | void throwInvalidStateError(JSC::ExecState&, JSC::ThrowScope&, ASCIILiteral); |
52 | WEBCORE_EXPORT void throwNonFiniteTypeError(JSC::ExecState&, JSC::ThrowScope&); |
53 | void throwNotSupportedError(JSC::ExecState&, JSC::ThrowScope&, ASCIILiteral); |
54 | void throwSecurityError(JSC::ExecState&, JSC::ThrowScope&, const String& message); |
55 | WEBCORE_EXPORT void throwSequenceTypeError(JSC::ExecState&, JSC::ThrowScope&); |
56 | |
57 | WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentMustBeEnumError(JSC::ExecState&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName, const char* expectedValues); |
58 | WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentMustBeFunctionError(JSC::ExecState&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName); |
59 | WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentTypeError(JSC::ExecState&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName, const char* expectedType); |
60 | WEBCORE_EXPORT JSC::EncodedJSValue throwRequiredMemberTypeError(JSC::ExecState&, JSC::ThrowScope&, const char* memberName, const char* dictionaryName, const char* expectedType); |
61 | JSC::EncodedJSValue throwConstructorScriptExecutionContextUnavailableError(JSC::ExecState&, JSC::ThrowScope&, const char* interfaceName); |
62 | |
63 | String makeGetterTypeErrorMessage(const char* interfaceName, const char* attributeName); |
64 | String makeThisTypeErrorMessage(const char* interfaceName, const char* attributeName); |
65 | |
66 | WEBCORE_EXPORT JSC::EncodedJSValue throwGetterTypeError(JSC::ExecState&, JSC::ThrowScope&, const char* interfaceName, const char* attributeName); |
67 | WEBCORE_EXPORT JSC::EncodedJSValue throwThisTypeError(JSC::ExecState&, JSC::ThrowScope&, const char* interfaceName, const char* functionName); |
68 | |
69 | WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::ExecState&, const char* interfaceName, const char* attributeName); |
70 | WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithThisTypeError(DeferredPromise&, const char* interfaceName, const char* operationName); |
71 | WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithThisTypeError(JSC::ExecState&, const char* interfaceName, const char* operationName); |
72 | |
73 | String retrieveErrorMessage(JSC::ExecState&, JSC::VM&, JSC::JSValue exception, JSC::CatchScope&); |
74 | WEBCORE_EXPORT void reportException(JSC::ExecState*, JSC::JSValue exception, CachedScript* = nullptr); |
75 | WEBCORE_EXPORT void reportException(JSC::ExecState*, JSC::Exception*, CachedScript* = nullptr, ExceptionDetails* = nullptr); |
76 | void reportCurrentException(JSC::ExecState*); |
77 | |
78 | JSC::JSValue createDOMException(JSC::ExecState&, Exception&&); |
79 | JSC::JSValue createDOMException(JSC::ExecState*, ExceptionCode, const String& = emptyString()); |
80 | |
81 | // Convert a DOM implementation exception into a JavaScript exception in the execution state. |
82 | WEBCORE_EXPORT void propagateExceptionSlowPath(JSC::ExecState&, JSC::ThrowScope&, Exception&&); |
83 | |
84 | ALWAYS_INLINE void propagateException(JSC::ExecState& state, JSC::ThrowScope& throwScope, Exception&& exception) |
85 | { |
86 | if (throwScope.exception()) |
87 | return; |
88 | propagateExceptionSlowPath(state, throwScope, WTFMove(exception)); |
89 | } |
90 | |
91 | inline void propagateException(JSC::ExecState& state, JSC::ThrowScope& throwScope, ExceptionOr<void>&& value) |
92 | { |
93 | if (UNLIKELY(value.hasException())) |
94 | propagateException(state, throwScope, value.releaseException()); |
95 | } |
96 | |
97 | } // namespace WebCore |
98 | |