Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ExceptionState.h

Issue 2272613003: binding: Retires ExceptionState::throwIfNeeded(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/ExceptionState.h
diff --git a/third_party/WebKit/Source/bindings/core/v8/ExceptionState.h b/third_party/WebKit/Source/bindings/core/v8/ExceptionState.h
index 6007ab6ad3ec1f243e9be76683a48401c6ce9f65..7deb52175b7e8251472ee8768e9ae225a67e5381 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ExceptionState.h
+++ b/third_party/WebKit/Source/bindings/core/v8/ExceptionState.h
@@ -70,7 +70,10 @@ public:
, m_context(contextType)
, m_propertyName(propertyName)
, m_interfaceName(interfaceName)
- , m_isolate(isolate) { }
+ , m_isolate(isolate)
+ {
+ DCHECK(m_isolate);
+ }
ExceptionState(v8::Isolate* isolate, ContextType contextType, const char* interfaceName)
: ExceptionState(isolate, contextType, interfaceName, nullptr)
@@ -95,24 +98,27 @@ public:
ExceptionState(ContextType context, const char* interfaceName, const v8::Local<v8::Object>& creationContext, v8::Isolate* isolate) // DEPRECATED
: ExceptionState(isolate, context, interfaceName) { }
+ ~ExceptionState()
+ {
+ if (!m_exception.isEmpty()) {
+ V8ThrowException::throwException(m_isolate, m_exception.newLocal(m_isolate));
+ }
+ }
+
virtual void throwDOMException(const ExceptionCode&, const String& message);
- virtual void throwTypeError(const String& message);
- virtual void throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage = String());
virtual void throwRangeError(const String& message);
+ virtual void throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage = String());
+ virtual void throwTypeError(const String& message);
- bool hadException() const { return !m_exception.isEmpty() || m_code; }
+ bool hadException() const { return !m_exception.isEmpty(); }
void clearException();
ExceptionCode code() const { return m_code; }
const String& message() const { return m_message; }
- v8::Local<v8::Value> getException() { DCHECK(!m_exception.isEmpty()); return m_exception.newLocal(m_isolate); }
-
- bool throwIfNeeded()
+ v8::Local<v8::Value> getException()
{
- if (!hadException())
- return false;
- throwException();
- return true;
+ DCHECK(!m_exception.isEmpty());
+ return m_exception.newLocal(m_isolate);
}
// This method clears out the exception which |this| has.
@@ -121,16 +127,14 @@ public:
// This method clears out the exception which |this| has.
void reject(ScriptPromiseResolver*);
- ContextType context() const { return m_context; }
const char* propertyName() const { return m_propertyName; }
const char* interfaceName() const { return m_interfaceName; }
void rethrowV8Exception(v8::Local<v8::Value> value)
{
- setException(value);
+ setException(0, String(), value);
}
- // Might return nullptr.
v8::Isolate* isolate() const { return m_isolate; }
#if ENABLE(ASSERT)
@@ -138,18 +142,16 @@ public:
#endif
protected:
+ void setException(ExceptionCode, const String&, v8::Local<v8::Value>);
+
+private:
+ String addExceptionContext(const String&) const;
+
ExceptionCode m_code;
ContextType m_context;
String m_message;
const char* m_propertyName;
const char* m_interfaceName;
-
-private:
- void setException(v8::Local<v8::Value>);
- void throwException();
-
- String addExceptionContext(const String&) const;
-
ScopedPersistent<v8::Value> m_exception;
v8::Isolate* m_isolate;
#if ENABLE(ASSERT)
@@ -159,9 +161,9 @@ private:
// Used if exceptions can/should not be directly thrown.
class CORE_EXPORT NonThrowableExceptionState final : public ExceptionState {
- WTF_MAKE_NONCOPYABLE(NonThrowableExceptionState);
public:
- NonThrowableExceptionState(): ExceptionState(ExceptionState::UnknownContext, 0, 0, v8::Local<v8::Object>(), v8::Isolate::GetCurrent()) { }
+ NonThrowableExceptionState()
+ : ExceptionState(v8::Isolate::GetCurrent(), ExceptionState::UnknownContext, nullptr, nullptr) { }
void throwDOMException(const ExceptionCode&, const String& message) override;
void throwTypeError(const String& message = String()) override;
void throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage = String()) override;
@@ -170,9 +172,17 @@ public:
// Used if any exceptions thrown are ignorable.
class CORE_EXPORT TrackExceptionState final : public ExceptionState {
- WTF_MAKE_NONCOPYABLE(TrackExceptionState);
public:
- TrackExceptionState(): ExceptionState(ExceptionState::UnknownContext, 0, 0, v8::Local<v8::Object>(), v8::Isolate::GetCurrent()) { }
+ TrackExceptionState()
+ : ExceptionState(v8::Isolate::GetCurrent(), ExceptionState::UnknownContext, nullptr, nullptr) { }
+ ~TrackExceptionState()
+ {
+ // Prevent the base class throw an exception.
+ if (hadException()) {
+ clearException();
+ }
+ }
+
void throwDOMException(const ExceptionCode&, const String& message) override;
void throwTypeError(const String& message = String()) override;
void throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage = String()) override;

Powered by Google App Engine
This is Rietveld 408576698