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

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

Issue 555133003: Use ExceptionState to throw exceptions when converting arrays (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 6 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) 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef V8StringResource_h 26 #ifndef V8StringResource_h
27 #define V8StringResource_h 27 #define V8StringResource_h
28 28
29 #include "bindings/core/v8/ExceptionState.h"
29 #include "wtf/Threading.h" 30 #include "wtf/Threading.h"
30 #include "wtf/text/AtomicString.h" 31 #include "wtf/text/AtomicString.h"
31 #include "wtf/text/WTFString.h" 32 #include "wtf/text/WTFString.h"
32 #include <v8.h> 33 #include <v8.h>
33 34
34 namespace blink { 35 namespace blink {
35 36
36 class ExternalStringVisitor; 37 class ExternalStringVisitor;
37 38
38 // WebCoreStringResource is a helper class for v8ExternalString. It is used 39 // WebCoreStringResource is a helper class for v8ExternalString. It is used
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 setString(string); 192 setString(string);
192 } 193 }
193 194
194 void operator=(std::nullptr_t) 195 void operator=(std::nullptr_t)
195 { 196 {
196 setString(String()); 197 setString(String());
197 } 198 }
198 199
199 bool prepare() 200 bool prepare()
200 { 201 {
202 if (prepareFast())
203 return true;
204
205 m_v8Object = m_v8Object->ToString();
206 // Handle the case where an exception is thrown as part of invoking toSt ring on the object.
207 if (m_v8Object.IsEmpty())
208 return false;
209 return true;
210 }
211
212 bool prepare(ExceptionState& exceptionState)
213 {
214 if (prepareFast())
215 return true;
216
217 v8::TryCatch block;
218 m_v8Object = m_v8Object->ToString();
219 // Handle the case where an exception is thrown as part of invoking toSt ring on the object.
220 if (block.HasCaught()) {
221 exceptionState.rethrowV8Exception(block.Exception());
222 return false;
223 }
224 return true;
225 }
226
227 operator String() const { return toString<String>(); }
228 operator AtomicString() const { return toString<AtomicString>(); }
229
230 private:
231 bool prepareFast()
232 {
201 if (m_v8Object.IsEmpty()) 233 if (m_v8Object.IsEmpty())
202 return true; 234 return true;
203 235
204 if (!isValid()) { 236 if (!isValid()) {
205 setString(fallbackString()); 237 setString(fallbackString());
206 return true; 238 return true;
207 } 239 }
208 240
209 if (LIKELY(m_v8Object->IsString())) 241 if (LIKELY(m_v8Object->IsString()))
210 return true; 242 return true;
211 243
212 if (LIKELY(m_v8Object->IsInt32())) { 244 if (LIKELY(m_v8Object->IsInt32())) {
213 setString(int32ToWebCoreString(m_v8Object->Int32Value())); 245 setString(int32ToWebCoreString(m_v8Object->Int32Value()));
214 return true; 246 return true;
215 } 247 }
216 248
217 m_mode = DoNotExternalize; 249 m_mode = DoNotExternalize;
218 m_v8Object = m_v8Object->ToString(); 250 return false;
219 // Handle the case where an exception is thrown as part of invoking toSt ring on the object.
220 if (m_v8Object.IsEmpty())
221 return false;
222 return true;
223 } 251 }
224 operator String() const { return toString<String>(); }
225 operator AtomicString() const { return toString<AtomicString>(); }
226 252
227 private:
228 bool isValid() const; 253 bool isValid() const;
229 String fallbackString() const; 254 String fallbackString() const;
230 255
231 void setString(const String& string) 256 void setString(const String& string)
232 { 257 {
233 m_string = string; 258 m_string = string;
234 m_v8Object.Clear(); // To signal that String is ready. 259 m_v8Object.Clear(); // To signal that String is ready.
235 } 260 }
236 261
237 template <class StringType> 262 template <class StringType>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 310 }
286 311
287 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa llbackString() const 312 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa llbackString() const
288 { 313 {
289 return String(); 314 return String();
290 } 315 }
291 316
292 } // namespace blink 317 } // namespace blink
293 318
294 #endif // V8StringResource_h 319 #endif // V8StringResource_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8BindingTest.cpp ('k') | Source/bindings/core/v8/custom/V8ElementCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698