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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 IndexedSetterContext, 63 IndexedSetterContext,
64 IndexedDeletionContext, 64 IndexedDeletionContext,
65 UnknownContext, // FIXME: Remove this once we've flipped over to the new API. 65 UnknownContext, // FIXME: Remove this once we've flipped over to the new API.
66 }; 66 };
67 67
68 ExceptionState(v8::Isolate* isolate, ContextType contextType, const char* in terfaceName, const char* propertyName) 68 ExceptionState(v8::Isolate* isolate, ContextType contextType, const char* in terfaceName, const char* propertyName)
69 : m_code(0) 69 : m_code(0)
70 , m_context(contextType) 70 , m_context(contextType)
71 , m_propertyName(propertyName) 71 , m_propertyName(propertyName)
72 , m_interfaceName(interfaceName) 72 , m_interfaceName(interfaceName)
73 , m_isolate(isolate) { } 73 , m_isolate(isolate)
74 {
75 DCHECK(m_isolate);
76 }
74 77
75 ExceptionState(v8::Isolate* isolate, ContextType contextType, const char* in terfaceName) 78 ExceptionState(v8::Isolate* isolate, ContextType contextType, const char* in terfaceName)
76 : ExceptionState(isolate, contextType, interfaceName, nullptr) 79 : ExceptionState(isolate, contextType, interfaceName, nullptr)
77 { 80 {
78 #if ENABLE(ASSERT) 81 #if ENABLE(ASSERT)
79 switch (m_context) { 82 switch (m_context) {
80 case ConstructionContext: 83 case ConstructionContext:
81 case EnumerationContext: 84 case EnumerationContext:
82 case IndexedGetterContext: 85 case IndexedGetterContext:
83 case IndexedSetterContext: 86 case IndexedSetterContext:
84 case IndexedDeletionContext: 87 case IndexedDeletionContext:
85 break; 88 break;
86 default: 89 default:
87 NOTREACHED(); 90 NOTREACHED();
88 } 91 }
89 #endif // ENABLE(ASSERT) 92 #endif // ENABLE(ASSERT)
90 } 93 }
91 94
92 ExceptionState(ContextType context, const char* propertyName, const char* in terfaceName, const v8::Local<v8::Object>& creationContext, v8::Isolate* isolate) // DEPRECATED 95 ExceptionState(ContextType context, const char* propertyName, const char* in terfaceName, const v8::Local<v8::Object>& creationContext, v8::Isolate* isolate) // DEPRECATED
93 : ExceptionState(isolate, context, interfaceName, propertyName) { } 96 : ExceptionState(isolate, context, interfaceName, propertyName) { }
94 97
95 ExceptionState(ContextType context, const char* interfaceName, const v8::Loc al<v8::Object>& creationContext, v8::Isolate* isolate) // DEPRECATED 98 ExceptionState(ContextType context, const char* interfaceName, const v8::Loc al<v8::Object>& creationContext, v8::Isolate* isolate) // DEPRECATED
96 : ExceptionState(isolate, context, interfaceName) { } 99 : ExceptionState(isolate, context, interfaceName) { }
97 100
101 ~ExceptionState()
102 {
103 if (!m_exception.isEmpty()) {
104 V8ThrowException::throwException(m_isolate, m_exception.newLocal(m_i solate));
105 }
106 }
107
98 virtual void throwDOMException(const ExceptionCode&, const String& message); 108 virtual void throwDOMException(const ExceptionCode&, const String& message);
109 virtual void throwRangeError(const String& message);
110 virtual void throwSecurityError(const String& sanitizedMessage, const String & unsanitizedMessage = String());
99 virtual void throwTypeError(const String& message); 111 virtual void throwTypeError(const String& message);
100 virtual void throwSecurityError(const String& sanitizedMessage, const String & unsanitizedMessage = String());
101 virtual void throwRangeError(const String& message);
102 112
103 bool hadException() const { return !m_exception.isEmpty() || m_code; } 113 bool hadException() const { return !m_exception.isEmpty(); }
104 void clearException(); 114 void clearException();
105 115
106 ExceptionCode code() const { return m_code; } 116 ExceptionCode code() const { return m_code; }
107 const String& message() const { return m_message; } 117 const String& message() const { return m_message; }
108 v8::Local<v8::Value> getException() { DCHECK(!m_exception.isEmpty()); return m_exception.newLocal(m_isolate); } 118 v8::Local<v8::Value> getException()
109
110 bool throwIfNeeded()
111 { 119 {
112 if (!hadException()) 120 DCHECK(!m_exception.isEmpty());
113 return false; 121 return m_exception.newLocal(m_isolate);
114 throwException();
115 return true;
116 } 122 }
117 123
118 // This method clears out the exception which |this| has. 124 // This method clears out the exception which |this| has.
119 ScriptPromise reject(ScriptState*); 125 ScriptPromise reject(ScriptState*);
120 126
121 // This method clears out the exception which |this| has. 127 // This method clears out the exception which |this| has.
122 void reject(ScriptPromiseResolver*); 128 void reject(ScriptPromiseResolver*);
123 129
124 ContextType context() const { return m_context; }
125 const char* propertyName() const { return m_propertyName; } 130 const char* propertyName() const { return m_propertyName; }
126 const char* interfaceName() const { return m_interfaceName; } 131 const char* interfaceName() const { return m_interfaceName; }
127 132
128 void rethrowV8Exception(v8::Local<v8::Value> value) 133 void rethrowV8Exception(v8::Local<v8::Value> value)
129 { 134 {
130 setException(value); 135 setException(0, String(), value);
131 } 136 }
132 137
133 // Might return nullptr.
134 v8::Isolate* isolate() const { return m_isolate; } 138 v8::Isolate* isolate() const { return m_isolate; }
135 139
136 #if ENABLE(ASSERT) 140 #if ENABLE(ASSERT)
137 OnStackObjectChecker& getOnStackObjectChecker() { return m_onStackObjectChec ker; } 141 OnStackObjectChecker& getOnStackObjectChecker() { return m_onStackObjectChec ker; }
138 #endif 142 #endif
139 143
140 protected: 144 protected:
145 void setException(ExceptionCode, const String&, v8::Local<v8::Value>);
146
147 private:
148 String addExceptionContext(const String&) const;
149
141 ExceptionCode m_code; 150 ExceptionCode m_code;
142 ContextType m_context; 151 ContextType m_context;
143 String m_message; 152 String m_message;
144 const char* m_propertyName; 153 const char* m_propertyName;
145 const char* m_interfaceName; 154 const char* m_interfaceName;
146
147 private:
148 void setException(v8::Local<v8::Value>);
149 void throwException();
150
151 String addExceptionContext(const String&) const;
152
153 ScopedPersistent<v8::Value> m_exception; 155 ScopedPersistent<v8::Value> m_exception;
154 v8::Isolate* m_isolate; 156 v8::Isolate* m_isolate;
155 #if ENABLE(ASSERT) 157 #if ENABLE(ASSERT)
156 OnStackObjectChecker m_onStackObjectChecker; 158 OnStackObjectChecker m_onStackObjectChecker;
157 #endif 159 #endif
158 }; 160 };
159 161
160 // Used if exceptions can/should not be directly thrown. 162 // Used if exceptions can/should not be directly thrown.
161 class CORE_EXPORT NonThrowableExceptionState final : public ExceptionState { 163 class CORE_EXPORT NonThrowableExceptionState final : public ExceptionState {
162 WTF_MAKE_NONCOPYABLE(NonThrowableExceptionState);
163 public: 164 public:
164 NonThrowableExceptionState(): ExceptionState(ExceptionState::UnknownContext, 0, 0, v8::Local<v8::Object>(), v8::Isolate::GetCurrent()) { } 165 NonThrowableExceptionState()
166 : ExceptionState(v8::Isolate::GetCurrent(), ExceptionState::UnknownConte xt, nullptr, nullptr) { }
165 void throwDOMException(const ExceptionCode&, const String& message) override ; 167 void throwDOMException(const ExceptionCode&, const String& message) override ;
166 void throwTypeError(const String& message = String()) override; 168 void throwTypeError(const String& message = String()) override;
167 void throwSecurityError(const String& sanitizedMessage, const String& unsani tizedMessage = String()) override; 169 void throwSecurityError(const String& sanitizedMessage, const String& unsani tizedMessage = String()) override;
168 void throwRangeError(const String& message) override; 170 void throwRangeError(const String& message) override;
169 }; 171 };
170 172
171 // Used if any exceptions thrown are ignorable. 173 // Used if any exceptions thrown are ignorable.
172 class CORE_EXPORT TrackExceptionState final : public ExceptionState { 174 class CORE_EXPORT TrackExceptionState final : public ExceptionState {
173 WTF_MAKE_NONCOPYABLE(TrackExceptionState);
174 public: 175 public:
175 TrackExceptionState(): ExceptionState(ExceptionState::UnknownContext, 0, 0, v8::Local<v8::Object>(), v8::Isolate::GetCurrent()) { } 176 TrackExceptionState()
177 : ExceptionState(v8::Isolate::GetCurrent(), ExceptionState::UnknownConte xt, nullptr, nullptr) { }
178 ~TrackExceptionState()
179 {
180 // Prevent the base class throw an exception.
181 if (hadException()) {
182 clearException();
183 }
184 }
185
176 void throwDOMException(const ExceptionCode&, const String& message) override ; 186 void throwDOMException(const ExceptionCode&, const String& message) override ;
177 void throwTypeError(const String& message = String()) override; 187 void throwTypeError(const String& message = String()) override;
178 void throwSecurityError(const String& sanitizedMessage, const String& unsani tizedMessage = String()) override; 188 void throwSecurityError(const String& sanitizedMessage, const String& unsani tizedMessage = String()) override;
179 void throwRangeError(const String& message) override; 189 void throwRangeError(const String& message) override;
180 }; 190 };
181 191
182 } // namespace blink 192 } // namespace blink
183 193
184 #endif // ExceptionState_h 194 #endif // ExceptionState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698