OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef ExceptionState_h | 31 #ifndef ExceptionState_h |
32 #define ExceptionState_h | 32 #define ExceptionState_h |
33 | 33 |
34 #include "bindings/core/v8/OnStackObjectChecker.h" | |
35 #include "bindings/core/v8/ScopedPersistent.h" | 34 #include "bindings/core/v8/ScopedPersistent.h" |
36 #include "bindings/core/v8/ScriptPromise.h" | 35 #include "bindings/core/v8/ScriptPromise.h" |
37 #include "bindings/core/v8/V8ThrowException.h" | 36 #include "bindings/core/v8/V8ThrowException.h" |
38 #include "core/CoreExport.h" | 37 #include "core/CoreExport.h" |
39 #include "wtf/Allocator.h" | 38 #include "wtf/Allocator.h" |
40 #include "wtf/Noncopyable.h" | 39 #include "wtf/Noncopyable.h" |
41 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
42 #include <v8.h> | 41 #include <v8.h> |
43 | 42 |
44 namespace blink { | 43 namespace blink { |
45 | 44 |
46 typedef int ExceptionCode; | 45 typedef int ExceptionCode; |
47 class ScriptPromiseResolver; | 46 class ScriptPromiseResolver; |
48 class ScriptState; | 47 class ScriptState; |
49 | 48 |
50 // ExceptionState is a scope-like class and provides a way to throw an exception | 49 // ExceptionState is a scope-like class and provides a way to throw an exception |
51 // with an option to cancel it. An exception message may be auto-generated. | 50 // with an option to cancel it. An exception message may be auto-generated. |
52 // You can convert an exception to a reject promise. | 51 // You can convert an exception to a reject promise. |
53 class CORE_EXPORT ExceptionState { | 52 class CORE_EXPORT ExceptionState { |
| 53 STACK_ALLOCATED(); |
54 WTF_MAKE_NONCOPYABLE(ExceptionState); | 54 WTF_MAKE_NONCOPYABLE(ExceptionState); |
55 USING_FAST_MALLOC(ExceptionState); | |
56 public: | 55 public: |
57 enum ContextType { | 56 enum ContextType { |
58 ConstructionContext, | 57 ConstructionContext, |
59 ExecutionContext, | 58 ExecutionContext, |
60 DeletionContext, | 59 DeletionContext, |
61 GetterContext, | 60 GetterContext, |
62 SetterContext, | 61 SetterContext, |
63 EnumerationContext, | 62 EnumerationContext, |
64 QueryContext, | 63 QueryContext, |
65 IndexedGetterContext, | 64 IndexedGetterContext, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 123 |
125 // This method clears out the exception which |this| has. | 124 // This method clears out the exception which |this| has. |
126 ScriptPromise reject(ScriptState*); | 125 ScriptPromise reject(ScriptState*); |
127 | 126 |
128 // This method clears out the exception which |this| has. | 127 // This method clears out the exception which |this| has. |
129 void reject(ScriptPromiseResolver*); | 128 void reject(ScriptPromiseResolver*); |
130 | 129 |
131 const char* propertyName() const { return m_propertyName; } | 130 const char* propertyName() const { return m_propertyName; } |
132 const char* interfaceName() const { return m_interfaceName; } | 131 const char* interfaceName() const { return m_interfaceName; } |
133 | 132 |
134 #if ENABLE(ASSERT) | |
135 OnStackObjectChecker& getOnStackObjectChecker() { return m_onStackObjectChec
ker; } | |
136 #endif | |
137 | |
138 protected: | 133 protected: |
139 // An ExceptionCode for the case that an exception is rethrown. In that | 134 // An ExceptionCode for the case that an exception is rethrown. In that |
140 // case, we cannot determine an exception code. | 135 // case, we cannot determine an exception code. |
141 static const int kRethrownException = UnknownError; | 136 static const int kRethrownException = UnknownError; |
142 | 137 |
143 void setException(ExceptionCode, const String&, v8::Local<v8::Value>); | 138 void setException(ExceptionCode, const String&, v8::Local<v8::Value>); |
144 | 139 |
145 private: | 140 private: |
146 String addExceptionContext(const String&) const; | 141 String addExceptionContext(const String&) const; |
147 | 142 |
148 ExceptionCode m_code; | 143 ExceptionCode m_code; |
149 ContextType m_context; | 144 ContextType m_context; |
150 String m_message; | 145 String m_message; |
151 const char* m_propertyName; | 146 const char* m_propertyName; |
152 const char* m_interfaceName; | 147 const char* m_interfaceName; |
153 // The exception is empty when it was thrown through TrackExceptionState. | 148 // The exception is empty when it was thrown through TrackExceptionState. |
154 ScopedPersistent<v8::Value> m_exception; | 149 ScopedPersistent<v8::Value> m_exception; |
155 v8::Isolate* m_isolate; | 150 v8::Isolate* m_isolate; |
156 #if ENABLE(ASSERT) | |
157 OnStackObjectChecker m_onStackObjectChecker; | |
158 #endif | |
159 }; | 151 }; |
160 | 152 |
161 // NonThrowableExceptionState never allow call sites to throw an exception. | 153 // NonThrowableExceptionState never allow call sites to throw an exception. |
162 // Should be used if an exception must not be thrown. | 154 // Should be used if an exception must not be thrown. |
163 class CORE_EXPORT NonThrowableExceptionState final : public ExceptionState { | 155 class CORE_EXPORT NonThrowableExceptionState final : public ExceptionState { |
164 public: | 156 public: |
165 NonThrowableExceptionState() | 157 NonThrowableExceptionState() |
166 : ExceptionState(nullptr, ExceptionState::UnknownContext, nullptr, nullp
tr) { } | 158 : ExceptionState(nullptr, ExceptionState::UnknownContext, nullptr, nullp
tr) { } |
167 | 159 |
168 void throwDOMException(const ExceptionCode&, const String& message) override
; | 160 void throwDOMException(const ExceptionCode&, const String& message) override
; |
(...skipping 21 matching lines...) Expand all Loading... |
190 void throwDOMException(const ExceptionCode&, const String& message) override
; | 182 void throwDOMException(const ExceptionCode&, const String& message) override
; |
191 void throwTypeError(const String& message = String()) override; | 183 void throwTypeError(const String& message = String()) override; |
192 void throwSecurityError(const String& sanitizedMessage, const String& unsani
tizedMessage = String()) override; | 184 void throwSecurityError(const String& sanitizedMessage, const String& unsani
tizedMessage = String()) override; |
193 void throwRangeError(const String& message) override; | 185 void throwRangeError(const String& message) override; |
194 void rethrowV8Exception(v8::Local<v8::Value>) override; | 186 void rethrowV8Exception(v8::Local<v8::Value>) override; |
195 }; | 187 }; |
196 | 188 |
197 } // namespace blink | 189 } // namespace blink |
198 | 190 |
199 #endif // ExceptionState_h | 191 #endif // ExceptionState_h |
OLD | NEW |