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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 // The exception is empty when it was thrown through | 149 // The exception is empty when it was thrown through |
150 // DummyExceptionStateForTesting. | 150 // DummyExceptionStateForTesting. |
151 ScopedPersistent<v8::Value> m_exception; | 151 ScopedPersistent<v8::Value> m_exception; |
152 v8::Isolate* m_isolate; | 152 v8::Isolate* m_isolate; |
153 }; | 153 }; |
154 | 154 |
155 // NonThrowableExceptionState never allow call sites to throw an exception. | 155 // NonThrowableExceptionState never allow call sites to throw an exception. |
156 // Should be used if an exception must not be thrown. | 156 // Should be used if an exception must not be thrown. |
157 class CORE_EXPORT NonThrowableExceptionState final : public ExceptionState { | 157 class CORE_EXPORT NonThrowableExceptionState final : public ExceptionState { |
158 public: | 158 public: |
159 NonThrowableExceptionState() | 159 NonThrowableExceptionState(); |
160 : ExceptionState(nullptr, | 160 NonThrowableExceptionState(const char*, int); |
161 ExceptionState::UnknownContext, | |
162 nullptr, | |
163 nullptr) {} | |
164 | 161 |
165 void throwDOMException(ExceptionCode, const String& message) override; | 162 void throwDOMException(ExceptionCode, const String& message) override; |
166 void throwTypeError(const String& message) override; | 163 void throwTypeError(const String& message) override; |
167 void throwSecurityError(const String& sanitizedMessage, | 164 void throwSecurityError(const String& sanitizedMessage, |
168 const String& unsanitizedMessage) override; | 165 const String& unsanitizedMessage) override; |
169 void throwRangeError(const String& message) override; | 166 void throwRangeError(const String& message) override; |
170 void rethrowV8Exception(v8::Local<v8::Value>) override; | 167 void rethrowV8Exception(v8::Local<v8::Value>) override; |
168 ExceptionState& returnThis() { return *this; } | |
169 | |
170 private: | |
171 const char* m_file; | |
172 const int m_line; | |
171 }; | 173 }; |
172 | 174 |
175 // Syntax sugar for NonThrowableExceptionState. | |
176 // This can be used as a default value of an ExceptionState parameter like this: | |
177 // | |
178 // Node* removeChild(Node* child, ExceptionState& = ASSERT_NO_EXCEPTION) | |
179 #if ENABLE(ASSERT) | |
180 #define ASSERT_NO_EXCEPTION \ | |
181 (::blink::NonThrowableExceptionState(__FILE__, __LINE__).returnThis()) | |
182 #else | |
183 #define ASSERT_NO_EXCEPTION \ | |
184 (::blink::DummyExceptionStateForTesting().returnThis()) | |
185 #endif | |
186 | |
173 // DummyExceptionStateForTesting ignores all thrown exceptions. You should not | 187 // DummyExceptionStateForTesting ignores all thrown exceptions. You should not |
174 // use DummyExceptionStateForTesting in production code, where you need to | 188 // use DummyExceptionStateForTesting in production code, where you need to |
175 // handle all exceptions properly. If you really need to ignore exceptions in | 189 // handle all exceptions properly. If you really need to ignore exceptions in |
176 // production code for some special reason, explicitly call clearException(). | 190 // production code for some special reason, explicitly call clearException(). |
177 class CORE_EXPORT DummyExceptionStateForTesting final : public ExceptionState { | 191 class CORE_EXPORT DummyExceptionStateForTesting final : public ExceptionState { |
178 public: | 192 public: |
179 DummyExceptionStateForTesting() | 193 DummyExceptionStateForTesting() |
180 : ExceptionState(nullptr, | 194 : ExceptionState(nullptr, |
181 ExceptionState::UnknownContext, | 195 ExceptionState::UnknownContext, |
182 nullptr, | 196 nullptr, |
183 nullptr) {} | 197 nullptr) {} |
184 ~DummyExceptionStateForTesting() { | 198 ~DummyExceptionStateForTesting() { |
185 // Prevent the base class throw an exception. | 199 // Prevent the base class throw an exception. |
186 if (hadException()) { | 200 if (hadException()) { |
187 clearException(); | 201 clearException(); |
188 } | 202 } |
189 } | 203 } |
190 void throwDOMException(ExceptionCode, const String& message) override; | 204 void throwDOMException(ExceptionCode, const String& message) override; |
191 void throwTypeError(const String& message) override; | 205 void throwTypeError(const String& message) override; |
192 void throwSecurityError(const String& sanitizedMessage, | 206 void throwSecurityError(const String& sanitizedMessage, |
193 const String& unsanitizedMessage) override; | 207 const String& unsanitizedMessage) override; |
194 void throwRangeError(const String& message) override; | 208 void throwRangeError(const String& message) override; |
195 void rethrowV8Exception(v8::Local<v8::Value>) override; | 209 void rethrowV8Exception(v8::Local<v8::Value>) override; |
196 ExceptionState& returnThis() { return *this; } | 210 ExceptionState& returnThis() { return *this; } |
197 }; | 211 }; |
198 | 212 |
213 // Syntax sugar for DummyExceptionStateForTesting. | |
214 // This can be used as a default value of an ExceptionState parameter like this: | |
215 // | |
216 // Node* removeChild(Node* child, ExceptionState& = IGNORE_EXCEPTION) | |
217 #define IGNORE_EXCEPTION (::blink::DummyExceptionStateForTesting().returnThis()) | |
Yuki
2017/01/06 06:34:07
IIRC, we don't want IGNORE_EXCEPTION in our codeba
| |
218 | |
199 } // namespace blink | 219 } // namespace blink |
200 | 220 |
201 #endif // ExceptionState_h | 221 #endif // ExceptionState_h |
OLD | NEW |