Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 (prepareSimple()) | |
|
haraken
2014/09/24 09:29:49
prepareFast ? (We normally add "Fast" for a fast p
Jens Widell
2014/09/24 10:00:19
Done.
| |
| 203 return true; | |
| 204 | |
| 205 v8::TryCatch block; | |
| 206 m_v8Object = m_v8Object->ToString(); | |
| 207 // Handle the case where an exception is thrown as part of invoking toSt ring on the object. | |
| 208 if (block.HasCaught()) { | |
| 209 block.ReThrow(); | |
| 210 return false; | |
| 211 } | |
| 212 return true; | |
| 213 } | |
| 214 | |
| 215 bool prepare(ExceptionState& exceptionState) | |
| 216 { | |
| 217 if (prepareSimple()) | |
| 218 return true; | |
| 219 | |
| 220 v8::TryCatch block; | |
| 221 m_v8Object = m_v8Object->ToString(); | |
| 222 // Handle the case where an exception is thrown as part of invoking toSt ring on the object. | |
| 223 if (block.HasCaught()) { | |
| 224 exceptionState.rethrowV8Exception(block.Exception()); | |
| 225 return false; | |
| 226 } | |
| 227 return true; | |
| 228 } | |
| 229 | |
| 230 operator String() const { return toString<String>(); } | |
| 231 operator AtomicString() const { return toString<AtomicString>(); } | |
| 232 | |
| 233 private: | |
| 234 bool prepareSimple() | |
| 235 { | |
| 201 if (m_v8Object.IsEmpty()) | 236 if (m_v8Object.IsEmpty()) |
| 202 return true; | 237 return true; |
| 203 | 238 |
| 204 if (!isValid()) { | 239 if (!isValid()) { |
| 205 setString(fallbackString()); | 240 setString(fallbackString()); |
| 206 return true; | 241 return true; |
| 207 } | 242 } |
| 208 | 243 |
| 209 if (LIKELY(m_v8Object->IsString())) | 244 if (LIKELY(m_v8Object->IsString())) |
| 210 return true; | 245 return true; |
| 211 | 246 |
| 212 if (LIKELY(m_v8Object->IsInt32())) { | 247 if (LIKELY(m_v8Object->IsInt32())) { |
| 213 setString(int32ToWebCoreString(m_v8Object->Int32Value())); | 248 setString(int32ToWebCoreString(m_v8Object->Int32Value())); |
| 214 return true; | 249 return true; |
| 215 } | 250 } |
| 216 | 251 |
| 217 m_mode = DoNotExternalize; | 252 m_mode = DoNotExternalize; |
| 218 v8::TryCatch block; | 253 return false; |
| 219 m_v8Object = m_v8Object->ToString(); | |
| 220 // Handle the case where an exception is thrown as part of invoking toSt ring on the object. | |
| 221 if (block.HasCaught()) { | |
| 222 block.ReThrow(); | |
| 223 return false; | |
| 224 } | |
| 225 return true; | |
| 226 } | 254 } |
| 227 operator String() const { return toString<String>(); } | |
| 228 operator AtomicString() const { return toString<AtomicString>(); } | |
| 229 | 255 |
| 230 private: | |
| 231 bool isValid() const; | 256 bool isValid() const; |
| 232 String fallbackString() const; | 257 String fallbackString() const; |
| 233 | 258 |
| 234 void setString(const String& string) | 259 void setString(const String& string) |
| 235 { | 260 { |
| 236 m_string = string; | 261 m_string = string; |
| 237 m_v8Object.Clear(); // To signal that String is ready. | 262 m_v8Object.Clear(); // To signal that String is ready. |
| 238 } | 263 } |
| 239 | 264 |
| 240 template <class StringType> | 265 template <class StringType> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 } | 313 } |
| 289 | 314 |
| 290 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa llbackString() const | 315 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa llbackString() const |
| 291 { | 316 { |
| 292 return String(); | 317 return String(); |
| 293 } | 318 } |
| 294 | 319 |
| 295 } // namespace blink | 320 } // namespace blink |
| 296 | 321 |
| 297 #endif // V8StringResource_h | 322 #endif // V8StringResource_h |
| OLD | NEW |