Index: third_party/WebKit/Source/bindings/core/v8/ExceptionState.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/ExceptionState.cpp b/third_party/WebKit/Source/bindings/core/v8/ExceptionState.cpp |
index fe50602608ce9a230a6ead4ad27f152cc401d04d..ed04551798292e7d0d7b423c05de818154c0c76e 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/ExceptionState.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/ExceptionState.cpp |
@@ -37,133 +37,69 @@ |
namespace blink { |
-void ExceptionState::clearException() |
-{ |
- m_code = 0; |
- m_exception.clear(); |
-} |
- |
-ScriptPromise ExceptionState::reject(ScriptState* scriptState) |
-{ |
- ScriptPromise promise = ScriptPromise::reject(scriptState, m_exception.newLocal(scriptState->isolate())); |
- clearException(); |
- return promise; |
-} |
- |
-void ExceptionState::reject(ScriptPromiseResolver* resolver) |
-{ |
- resolver->reject(m_exception.newLocal(resolver->getScriptState()->isolate())); |
- clearException(); |
-} |
- |
void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& message) |
{ |
- ASSERT(ec); |
- ASSERT(m_isolate); |
- |
// SecurityError is thrown via ::throwSecurityError, and _careful_ consideration must be given to the data exposed to JavaScript via the 'sanitizedMessage'. |
- ASSERT(ec != SecurityError); |
+ DCHECK(ec != SecurityError); |
- m_code = ec; |
- String processedMessage = addExceptionContext(message); |
- m_message = processedMessage; |
- setException(V8ThrowException::createDOMException(m_isolate, ec, processedMessage)); |
+ const String& processedMessage = addExceptionContext(message); |
+ setException(ec, processedMessage, V8ThrowException::createDOMException(m_isolate, ec, processedMessage)); |
} |
-void ExceptionState::throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage) |
+void ExceptionState::throwRangeError(const String& message) |
{ |
- ASSERT(m_isolate); |
- m_code = SecurityError; |
- String finalSanitized = addExceptionContext(sanitizedMessage); |
- m_message = finalSanitized; |
- String finalUnsanitized = addExceptionContext(unsanitizedMessage); |
- |
- setException(V8ThrowException::createDOMException(m_isolate, SecurityError, finalSanitized, finalUnsanitized)); |
+ setException(V8RangeError, message, V8ThrowException::createRangeError(m_isolate, addExceptionContext(message))); |
} |
-void ExceptionState::setException(v8::Local<v8::Value> exception) |
-{ |
- // FIXME: Assert that exception is not empty? |
- if (exception.IsEmpty()) { |
- clearException(); |
- return; |
- } |
- |
- m_exception.set(m_isolate, exception); |
-} |
- |
-void ExceptionState::throwException() |
+void ExceptionState::throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage) |
{ |
- ASSERT(!m_exception.isEmpty()); |
- V8ThrowException::throwException(m_isolate, m_exception.newLocal(m_isolate)); |
+ const String& finalSanitized = addExceptionContext(sanitizedMessage); |
+ const String& finalUnsanitized = addExceptionContext(unsanitizedMessage); |
+ setException(SecurityError, finalSanitized, V8ThrowException::createDOMException(m_isolate, SecurityError, finalSanitized, finalUnsanitized)); |
} |
void ExceptionState::throwTypeError(const String& message) |
{ |
- ASSERT(m_isolate); |
- m_code = V8TypeError; |
- m_message = message; |
- setException(V8ThrowException::createTypeError(m_isolate, addExceptionContext(message))); |
+ setException(V8TypeError, message, V8ThrowException::createTypeError(m_isolate, addExceptionContext(message))); |
} |
-void ExceptionState::throwRangeError(const String& message) |
+void ExceptionState::rethrowV8Exception(v8::Local<v8::Value> value) |
{ |
- ASSERT(m_isolate); |
- m_code = V8RangeError; |
- m_message = message; |
- setException(V8ThrowException::createRangeError(m_isolate, addExceptionContext(message))); |
+ setException(kRethrownException, String(), value); |
} |
-void NonThrowableExceptionState::throwDOMException(const ExceptionCode& ec, const String& message) |
+void ExceptionState::clearException() |
{ |
- ASSERT_NOT_REACHED(); |
- m_code = ec; |
- m_message = message; |
+ m_code = 0; |
+ m_message = String(); |
+ m_exception.clear(); |
} |
-void NonThrowableExceptionState::throwTypeError(const String& message) |
+ScriptPromise ExceptionState::reject(ScriptState* scriptState) |
{ |
- ASSERT_NOT_REACHED(); |
- m_code = V8TypeError; |
- m_message = message; |
+ ScriptPromise promise = ScriptPromise::reject(scriptState, getException()); |
+ clearException(); |
+ return promise; |
} |
-void NonThrowableExceptionState::throwSecurityError(const String& sanitizedMessage, const String&) |
+void ExceptionState::reject(ScriptPromiseResolver* resolver) |
{ |
- ASSERT_NOT_REACHED(); |
- m_code = SecurityError; |
- m_message = sanitizedMessage; |
+ resolver->reject(getException()); |
+ clearException(); |
} |
-void NonThrowableExceptionState::throwRangeError(const String& message) |
+void ExceptionState::setException(ExceptionCode ec, const String& message, v8::Local<v8::Value> exception) |
{ |
- ASSERT_NOT_REACHED(); |
- m_code = V8RangeError; |
- m_message = message; |
-} |
+ CHECK(ec); |
-void TrackExceptionState::throwDOMException(const ExceptionCode& ec, const String& message) |
-{ |
m_code = ec; |
m_message = message; |
-} |
- |
-void TrackExceptionState::throwTypeError(const String& message) |
-{ |
- m_code = V8TypeError; |
- m_message = message; |
-} |
- |
-void TrackExceptionState::throwSecurityError(const String& sanitizedMessage, const String&) |
-{ |
- m_code = SecurityError; |
- m_message = sanitizedMessage; |
-} |
- |
-void TrackExceptionState::throwRangeError(const String& message) |
-{ |
- m_code = V8RangeError; |
- m_message = message; |
+ if (exception.IsEmpty()) { |
+ m_exception.clear(); |
+ } else { |
+ DCHECK(m_isolate); |
+ m_exception.set(m_isolate, exception); |
+ } |
} |
String ExceptionState::addExceptionContext(const String& message) const |
@@ -196,4 +132,54 @@ String ExceptionState::addExceptionContext(const String& message) const |
return processedMessage; |
} |
+void NonThrowableExceptionState::throwDOMException(const ExceptionCode& ec, const String& message) |
+{ |
+ NOTREACHED(); |
+} |
+ |
+void NonThrowableExceptionState::throwRangeError(const String& message) |
+{ |
+ NOTREACHED(); |
+} |
+ |
+void NonThrowableExceptionState::throwSecurityError(const String& sanitizedMessage, const String&) |
+{ |
+ NOTREACHED(); |
+} |
+ |
+void NonThrowableExceptionState::throwTypeError(const String& message) |
+{ |
+ NOTREACHED(); |
+} |
+ |
+void NonThrowableExceptionState::rethrowV8Exception(v8::Local<v8::Value>) |
+{ |
+ NOTREACHED(); |
+} |
+ |
+void TrackExceptionState::throwDOMException(const ExceptionCode& ec, const String& message) |
+{ |
+ setException(ec, message, v8::Local<v8::Value>()); |
+} |
+ |
+void TrackExceptionState::throwRangeError(const String& message) |
+{ |
+ setException(V8RangeError, message, v8::Local<v8::Value>()); |
+} |
+ |
+void TrackExceptionState::throwSecurityError(const String& sanitizedMessage, const String&) |
+{ |
+ setException(SecurityError, sanitizedMessage, v8::Local<v8::Value>()); |
+} |
+ |
+void TrackExceptionState::throwTypeError(const String& message) |
+{ |
+ setException(V8TypeError, message, v8::Local<v8::Value>()); |
+} |
+ |
+void TrackExceptionState::rethrowV8Exception(v8::Local<v8::Value>) |
+{ |
+ setException(kRethrownException, String(), v8::Local<v8::Value>()); |
+} |
+ |
} // namespace blink |