| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 class V8StringResource { | 174 class V8StringResource { |
| 175 public: | 175 public: |
| 176 V8StringResource(v8::Handle<v8::Value> object) | 176 V8StringResource(v8::Handle<v8::Value> object) |
| 177 : m_v8Object(object) | 177 : m_v8Object(object) |
| 178 , m_mode(Externalize) | 178 , m_mode(Externalize) |
| 179 , m_string() | 179 , m_string() |
| 180 { | 180 { |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool prepare(); | 183 bool prepare(); |
| 184 operator String() { return toString<String>(); } | 184 operator String() const { return toString<String>(); } |
| 185 operator AtomicString() { return toString<AtomicString>(); } | 185 operator AtomicString() const { return toString<AtomicString>(); } |
| 186 | 186 |
| 187 private: | 187 private: |
| 188 bool prepareBase() | 188 bool prepareBase() |
| 189 { | 189 { |
| 190 if (m_v8Object.IsEmpty()) | 190 if (m_v8Object.IsEmpty()) |
| 191 return true; | 191 return true; |
| 192 | 192 |
| 193 if (LIKELY(m_v8Object->IsString())) | 193 if (LIKELY(m_v8Object->IsString())) |
| 194 return true; | 194 return true; |
| 195 | 195 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 209 return true; | 209 return true; |
| 210 } | 210 } |
| 211 | 211 |
| 212 void setString(const String& string) | 212 void setString(const String& string) |
| 213 { | 213 { |
| 214 m_string = string; | 214 m_string = string; |
| 215 m_v8Object.Clear(); // To signal that String is ready. | 215 m_v8Object.Clear(); // To signal that String is ready. |
| 216 } | 216 } |
| 217 | 217 |
| 218 template <class StringType> | 218 template <class StringType> |
| 219 StringType toString() | 219 StringType toString() const |
| 220 { | 220 { |
| 221 if (LIKELY(!m_v8Object.IsEmpty())) | 221 if (LIKELY(!m_v8Object.IsEmpty())) |
| 222 return v8StringToWebCoreString<StringType>(m_v8Object.As<v8::String>
(), m_mode); | 222 return v8StringToWebCoreString<StringType>(const_cast<v8::Handle<v8:
:Value>*>(&m_v8Object)->As<v8::String>(), m_mode); |
| 223 | 223 |
| 224 return StringType(m_string); | 224 return StringType(m_string); |
| 225 } | 225 } |
| 226 | 226 |
| 227 v8::Handle<v8::Value> m_v8Object; | 227 v8::Handle<v8::Value> m_v8Object; |
| 228 ExternalMode m_mode; | 228 ExternalMode m_mode; |
| 229 String m_string; | 229 String m_string; |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 template<> inline bool V8StringResource<DefaultMode>::prepare() | 232 template<> inline bool V8StringResource<DefaultMode>::prepare() |
| (...skipping 15 matching lines...) Expand all Loading... |
| 248 if (m_v8Object.IsEmpty() || m_v8Object->IsNull() || m_v8Object->IsUndefined(
)) { | 248 if (m_v8Object.IsEmpty() || m_v8Object->IsNull() || m_v8Object->IsUndefined(
)) { |
| 249 setString(String()); | 249 setString(String()); |
| 250 return true; | 250 return true; |
| 251 } | 251 } |
| 252 return prepareBase(); | 252 return prepareBase(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace WebCore | 255 } // namespace WebCore |
| 256 | 256 |
| 257 #endif // V8StringResource_h | 257 #endif // V8StringResource_h |
| OLD | NEW |