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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 }; | 159 }; |
160 | 160 |
161 template <typename StringType> | 161 template <typename StringType> |
162 StringType v8StringToWebCoreString(v8::Handle<v8::String>, ExternalMode); | 162 StringType v8StringToWebCoreString(v8::Handle<v8::String>, ExternalMode); |
163 String int32ToWebCoreString(int value); | 163 String int32ToWebCoreString(int value); |
164 | 164 |
165 // V8StringResource is an adapter class that converts V8 values to Strings | 165 // V8StringResource is an adapter class that converts V8 values to Strings |
166 // or AtomicStrings as appropriate, using multiple typecast operators. | 166 // or AtomicStrings as appropriate, using multiple typecast operators. |
167 enum V8StringResourceMode { | 167 enum V8StringResourceMode { |
168 DefaultMode, | 168 DefaultMode, |
169 TreatNullAsEmptyString, | |
169 WithNullCheck, | 170 WithNullCheck, |
170 WithUndefinedOrNullCheck | 171 WithUndefinedOrNullCheck |
haraken
2014/01/15 11:57:36
Shall we also rename WithNullCheck to TreatNullAsN
arv (Not doing code reviews)
2014/01/15 15:44:59
sounds good to me
| |
171 }; | 172 }; |
172 | 173 |
173 template <V8StringResourceMode Mode = DefaultMode> | 174 template <V8StringResourceMode Mode = DefaultMode> |
174 class V8StringResource { | 175 class V8StringResource { |
175 public: | 176 public: |
176 V8StringResource(v8::Handle<v8::Value> object) | 177 V8StringResource(v8::Handle<v8::Value> object) |
177 : m_v8Object(object) | 178 : m_v8Object(object) |
178 , m_mode(Externalize) | 179 , m_mode(Externalize) |
179 , m_string() | 180 , m_string() |
180 { | 181 { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 v8::Handle<v8::Value> m_v8Object; | 228 v8::Handle<v8::Value> m_v8Object; |
228 ExternalMode m_mode; | 229 ExternalMode m_mode; |
229 String m_string; | 230 String m_string; |
230 }; | 231 }; |
231 | 232 |
232 template<> inline bool V8StringResource<DefaultMode>::prepare() | 233 template<> inline bool V8StringResource<DefaultMode>::prepare() |
233 { | 234 { |
234 return prepareBase(); | 235 return prepareBase(); |
235 } | 236 } |
236 | 237 |
238 template<> inline bool V8StringResource<TreatNullAsEmptyString>::prepare() | |
239 { | |
240 if (m_v8Object.IsEmpty() || m_v8Object->IsNull()) { | |
241 setString(emptyString()); | |
242 return true; | |
243 } | |
244 return prepareBase(); | |
245 } | |
246 | |
237 template<> inline bool V8StringResource<WithNullCheck>::prepare() | 247 template<> inline bool V8StringResource<WithNullCheck>::prepare() |
238 { | 248 { |
239 if (m_v8Object.IsEmpty() || m_v8Object->IsNull()) { | 249 if (m_v8Object.IsEmpty() || m_v8Object->IsNull()) { |
240 setString(String()); | 250 setString(String()); |
241 return true; | 251 return true; |
242 } | 252 } |
243 return prepareBase(); | 253 return prepareBase(); |
244 } | 254 } |
245 | 255 |
246 template<> inline bool V8StringResource<WithUndefinedOrNullCheck>::prepare() | 256 template<> inline bool V8StringResource<WithUndefinedOrNullCheck>::prepare() |
247 { | 257 { |
248 if (m_v8Object.IsEmpty() || m_v8Object->IsNull() || m_v8Object->IsUndefined( )) { | 258 if (m_v8Object.IsEmpty() || m_v8Object->IsNull() || m_v8Object->IsUndefined( )) { |
249 setString(String()); | 259 setString(String()); |
250 return true; | 260 return true; |
251 } | 261 } |
252 return prepareBase(); | 262 return prepareBase(); |
253 } | 263 } |
254 | 264 |
255 } // namespace WebCore | 265 } // namespace WebCore |
256 | 266 |
257 #endif // V8StringResource_h | 267 #endif // V8StringResource_h |
OLD | NEW |