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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8StringResource.h

Issue 2519403002: binding: Lets Dictionary::getPropertyNames, etc. rethrow an exception. (Closed)
Patch Set: Fixed DictionaryTest. Created 4 years 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 180
181 V8StringResource(const String& string) 181 V8StringResource(const String& string)
182 : m_mode(Externalize), m_string(string) {} 182 : m_mode(Externalize), m_string(string) {}
183 183
184 void operator=(v8::Local<v8::Value> object) { m_v8Object = object; } 184 void operator=(v8::Local<v8::Value> object) { m_v8Object = object; }
185 185
186 void operator=(const String& string) { setString(string); } 186 void operator=(const String& string) { setString(string); }
187 187
188 void operator=(std::nullptr_t) { setString(String()); } 188 void operator=(std::nullptr_t) { setString(String()); }
189 189
190 bool prepare() { 190 bool prepare() {
haraken 2016/11/24 07:22:30 This should be deprecated as well, right?
Yuki 2016/11/24 10:19:32 Done.
191 if (prepareFast()) 191 if (prepareFast())
192 return true; 192 return true;
193 193
194 // TODO(bashi): Pass an isolate to this function and remove 194 // TODO(bashi): Pass an isolate to this function and remove
195 // v8::Isolate::GetCurrent(). 195 // v8::Isolate::GetCurrent().
196 // TODO(bashi): Pass an exceptionState to this function and handle an
bashi 2016/11/24 07:25:53 Why me? :)
Yuki 2016/11/24 10:19:32 Done. X( Removed TODO comments entirely because I
197 // exception correctly. If ToLocal() returned false, an exception is
198 // thrown.
196 return m_v8Object->ToString(v8::Isolate::GetCurrent()->GetCurrentContext()) 199 return m_v8Object->ToString(v8::Isolate::GetCurrent()->GetCurrentContext())
haraken 2016/11/24 07:22:30 Not related to your CL but why don't you need to h
Yuki 2016/11/24 10:19:32 If you were talking about "the best coding practic
197 .ToLocal(&m_v8Object); 200 .ToLocal(&m_v8Object);
198 } 201 }
199 202
200 bool prepare(ExceptionState& exceptionState) { 203 bool prepare(v8::Isolate* isolate, ExceptionState& exceptionState) {
204 return prepareFast() || prepareSlow(isolate, exceptionState);
205 }
206
207 bool prepare(ExceptionState& exceptionState) { // DEPRECATED
201 if (prepareFast()) 208 if (prepareFast())
peria 2016/11/24 07:21:23 Can't we make this like prepare(isoalte, state)?
Yuki 2016/11/24 10:19:33 Done.
202 return true; 209 return true;
203 210
204 // TODO(bashi): Pass an isolate to this function and remove 211 return prepareSlow(v8::Isolate::GetCurrent(), exceptionState);
205 // v8::Isolate::GetCurrent().
206 v8::Isolate* isolate = v8::Isolate::GetCurrent();
207 v8::TryCatch block(isolate);
208 // Handle the case where an exception is thrown as part of invoking toString
209 // on the object.
210 if (!m_v8Object->ToString(isolate->GetCurrentContext())
211 .ToLocal(&m_v8Object)) {
212 exceptionState.rethrowV8Exception(block.Exception());
213 return false;
214 }
215 return true;
216 } 212 }
217 213
218 operator String() const { return toString<String>(); } 214 operator String() const { return toString<String>(); }
219 operator AtomicString() const { return toString<AtomicString>(); } 215 operator AtomicString() const { return toString<AtomicString>(); }
220 216
221 private: 217 private:
222 bool prepareFast() { 218 bool prepareFast() {
223 if (m_v8Object.IsEmpty()) 219 if (m_v8Object.IsEmpty())
224 return true; 220 return true;
225 221
226 if (!isValid()) { 222 if (!isValid()) {
227 setString(fallbackString()); 223 setString(fallbackString());
228 return true; 224 return true;
229 } 225 }
230 226
231 if (LIKELY(m_v8Object->IsString())) 227 if (LIKELY(m_v8Object->IsString()))
232 return true; 228 return true;
233 229
234 if (LIKELY(m_v8Object->IsInt32())) { 230 if (LIKELY(m_v8Object->IsInt32())) {
235 setString(int32ToWebCoreString(m_v8Object.As<v8::Int32>()->Value())); 231 setString(int32ToWebCoreString(m_v8Object.As<v8::Int32>()->Value()));
236 return true; 232 return true;
237 } 233 }
238 234
239 m_mode = DoNotExternalize; 235 m_mode = DoNotExternalize;
240 return false; 236 return false;
241 } 237 }
238 bool prepareSlow(v8::Isolate* isolate, ExceptionState& exceptionState) {
peria 2016/11/24 07:21:23 nit: put an empty line here
Yuki 2016/11/24 10:19:32 Done.
239 v8::TryCatch tryCatch(isolate);
240 if (!m_v8Object->ToString(isolate->GetCurrentContext())
241 .ToLocal(&m_v8Object)) {
242 exceptionState.rethrowV8Exception(tryCatch.Exception());
243 return false;
244 }
245 return true;
246 }
242 247
243 bool isValid() const; 248 bool isValid() const;
244 String fallbackString() const; 249 String fallbackString() const;
245 250
246 void setString(const String& string) { 251 void setString(const String& string) {
247 m_string = string; 252 m_string = string;
248 m_v8Object.Clear(); // To signal that String is ready. 253 m_v8Object.Clear(); // To signal that String is ready.
249 } 254 }
250 255
251 template <class StringType> 256 template <class StringType>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 307
303 template <> 308 template <>
304 inline String 309 inline String
305 V8StringResource<TreatNullAndUndefinedAsNullString>::fallbackString() const { 310 V8StringResource<TreatNullAndUndefinedAsNullString>::fallbackString() const {
306 return String(); 311 return String();
307 } 312 }
308 313
309 } // namespace blink 314 } // namespace blink
310 315
311 #endif // V8StringResource_h 316 #endif // V8StringResource_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698