OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 10 matching lines...) Expand all Loading... |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef Dictionary_h | 26 #ifndef Dictionary_h |
27 #define Dictionary_h | 27 #define Dictionary_h |
28 | 28 |
29 #include "bindings/v8/ExceptionMessages.h" | 29 #include "bindings/v8/ExceptionMessages.h" |
30 #include "bindings/v8/ExceptionState.h" | 30 #include "bindings/v8/ExceptionState.h" |
| 31 #include "bindings/v8/Nullable.h" |
31 #include "bindings/v8/ScriptValue.h" | 32 #include "bindings/v8/ScriptValue.h" |
32 #include "bindings/v8/V8Binding.h" | 33 #include "bindings/v8/V8Binding.h" |
33 #include "bindings/v8/V8BindingMacros.h" | 34 #include "bindings/v8/V8BindingMacros.h" |
34 #include "core/events/EventListener.h" | 35 #include "core/events/EventListener.h" |
35 #include "core/dom/MessagePort.h" | 36 #include "core/dom/MessagePort.h" |
36 #include <v8.h> | 37 #include <v8.h> |
37 #include "wtf/HashMap.h" | 38 #include "wtf/HashMap.h" |
38 #include "wtf/HashSet.h" | 39 #include "wtf/HashSet.h" |
39 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
40 #include "wtf/text/AtomicString.h" | 41 #include "wtf/text/AtomicString.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 ConversionContext& m_context; | 148 ConversionContext& m_context; |
148 }; | 149 }; |
149 | 150 |
150 bool convert(ConversionContext&, const String&, bool&) const; | 151 bool convert(ConversionContext&, const String&, bool&) const; |
151 bool convert(ConversionContext&, const String&, double&) const; | 152 bool convert(ConversionContext&, const String&, double&) const; |
152 bool convert(ConversionContext&, const String&, String&) const; | 153 bool convert(ConversionContext&, const String&, String&) const; |
153 bool convert(ConversionContext&, const String&, ScriptValue&) const; | 154 bool convert(ConversionContext&, const String&, ScriptValue&) const; |
154 | 155 |
155 template<typename IntegralType> | 156 template<typename IntegralType> |
156 bool convert(ConversionContext&, const String&, IntegralType&) const; | 157 bool convert(ConversionContext&, const String&, IntegralType&) const; |
| 158 template<typename IntegralType> |
| 159 bool convert(ConversionContext&, const String&, Nullable<IntegralType>&) con
st; |
| 160 |
157 bool convert(ConversionContext&, const String&, MessagePortArray&) const; | 161 bool convert(ConversionContext&, const String&, MessagePortArray&) const; |
158 bool convert(ConversionContext&, const String&, HashSet<AtomicString>&) cons
t; | 162 bool convert(ConversionContext&, const String&, HashSet<AtomicString>&) cons
t; |
159 bool convert(ConversionContext&, const String&, Dictionary&) const; | 163 bool convert(ConversionContext&, const String&, Dictionary&) const; |
160 bool convert(ConversionContext&, const String&, Vector<String>&) const; | 164 bool convert(ConversionContext&, const String&, Vector<String>&) const; |
161 bool convert(ConversionContext&, const String&, ArrayValue&) const; | 165 bool convert(ConversionContext&, const String&, ArrayValue&) const; |
162 template<template <typename> class PointerType, typename T> | 166 template<template <typename> class PointerType, typename T> |
163 bool convert(ConversionContext&, const String&, PointerType<T>&) const; | 167 bool convert(ConversionContext&, const String&, PointerType<T>&) const; |
164 | 168 |
165 template<typename StringType> | 169 template<typename StringType> |
166 bool getStringType(const String&, StringType&) const; | 170 bool getStringType(const String&, StringType&) const; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 if (!getKey(key, v8Value)) | 299 if (!getKey(key, v8Value)) |
296 return true; | 300 return true; |
297 | 301 |
298 value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context
.exceptionState()); | 302 value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context
.exceptionState()); |
299 if (context.exceptionState().throwIfNeeded()) | 303 if (context.exceptionState().throwIfNeeded()) |
300 return false; | 304 return false; |
301 | 305 |
302 return true; | 306 return true; |
303 } | 307 } |
304 | 308 |
| 309 template<typename T> bool Dictionary::convert(ConversionContext& context, const
String& key, Nullable<T>& value) const |
| 310 { |
| 311 ConversionContextScope scope(context); |
| 312 |
| 313 v8::Local<v8::Value> v8Value; |
| 314 if (!getKey(key, v8Value)) |
| 315 return true; |
| 316 |
| 317 if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) { |
| 318 value = Nullable<T>(); |
| 319 return true; |
| 320 } |
| 321 |
| 322 T converted = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, c
ontext.exceptionState()); |
| 323 |
| 324 if (context.exceptionState().throwIfNeeded()) |
| 325 return false; |
| 326 |
| 327 value = Nullable<T>(converted); |
| 328 return true; |
| 329 } |
| 330 |
305 template<template <typename> class PointerType, typename T> bool Dictionary::con
vert(ConversionContext& context, const String& key, PointerType<T>& value) const | 331 template<template <typename> class PointerType, typename T> bool Dictionary::con
vert(ConversionContext& context, const String& key, PointerType<T>& value) const |
306 { | 332 { |
307 ConversionContextScope scope(context); | 333 ConversionContextScope scope(context); |
308 | 334 |
309 if (!get(key, value)) | 335 if (!get(key, value)) |
310 return true; | 336 return true; |
311 | 337 |
312 if (value) | 338 if (value) |
313 return true; | 339 return true; |
314 | 340 |
315 v8::Local<v8::Value> v8Value; | 341 v8::Local<v8::Value> v8Value; |
316 getKey(key, v8Value); | 342 getKey(key, v8Value); |
317 if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) | 343 if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) |
318 return true; | 344 return true; |
319 | 345 |
320 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have a " + context.typeName() + " type.")); | 346 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have a " + context.typeName() + " type.")); |
321 return false; | 347 return false; |
322 } | 348 } |
323 | 349 |
324 } | 350 } |
325 | 351 |
326 #endif // Dictionary_h | 352 #endif // Dictionary_h |
OLD | NEW |