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