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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, bool& value) | 62 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, bool& value) |
63 { | 63 { |
64 v8::Local<v8::Value> v8Value; | 64 v8::Local<v8::Value> v8Value; |
65 if (!dictionary.get(key, v8Value)) | 65 if (!dictionary.get(key, v8Value)) |
66 return false; | 66 return false; |
67 | 67 |
68 return v8Call(v8Value->BooleanValue(dictionary.v8Context()), value); | 68 return v8Call(v8Value->BooleanValue(dictionary.v8Context()), value); |
69 } | 69 } |
70 | 70 |
71 template <> | 71 template <> |
72 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, bool& value) | |
73 { | |
74 Dictionary::ConversionContextScope scope(context); | |
75 DictionaryHelper::get(dictionary, key, value); | |
76 return true; | |
77 } | |
78 | |
79 template <> | |
80 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, int32_t& value) | 72 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, int32_t& value) |
81 { | 73 { |
82 v8::Local<v8::Value> v8Value; | 74 v8::Local<v8::Value> v8Value; |
83 if (!dictionary.get(key, v8Value)) | 75 if (!dictionary.get(key, v8Value)) |
84 return false; | 76 return false; |
85 | 77 |
86 return v8Call(v8Value->Int32Value(dictionary.v8Context()), value); | 78 return v8Call(v8Value->Int32Value(dictionary.v8Context()), value); |
87 } | 79 } |
88 | 80 |
89 template <> | 81 template <> |
90 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, double& value, bool& hasValue) | 82 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, double& value, bool& hasValue) |
91 { | 83 { |
92 v8::Local<v8::Value> v8Value; | 84 v8::Local<v8::Value> v8Value; |
93 if (!dictionary.get(key, v8Value)) { | 85 if (!dictionary.get(key, v8Value)) { |
94 hasValue = false; | 86 hasValue = false; |
95 return false; | 87 return false; |
96 } | 88 } |
97 | 89 |
98 hasValue = true; | 90 hasValue = true; |
99 return v8Call(v8Value->NumberValue(dictionary.v8Context()), value); | 91 return v8Call(v8Value->NumberValue(dictionary.v8Context()), value); |
100 } | 92 } |
101 | 93 |
102 template <> | 94 template <> |
103 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub
le& value) | 95 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub
le& value) |
104 { | 96 { |
105 bool unused; | 97 bool unused; |
106 return DictionaryHelper::get(dictionary, key, value, unused); | 98 return DictionaryHelper::get(dictionary, key, value, unused); |
107 } | 99 } |
108 | 100 |
109 template <> | |
110 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, double& value) | |
111 { | |
112 Dictionary::ConversionContextScope scope(context); | |
113 | |
114 bool hasValue = false; | |
115 if (!DictionaryHelper::get(dictionary, key, value, hasValue) && hasValue) { | |
116 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "is
not of type 'double'.")); | |
117 return false; | |
118 } | |
119 return true; | |
120 } | |
121 | |
122 template<typename StringType> | 101 template<typename StringType> |
123 bool getStringType(const Dictionary& dictionary, const String& key, StringType&
value) | 102 bool getStringType(const Dictionary& dictionary, const String& key, StringType&
value) |
124 { | 103 { |
125 v8::Local<v8::Value> v8Value; | 104 v8::Local<v8::Value> v8Value; |
126 if (!dictionary.get(key, v8Value)) | 105 if (!dictionary.get(key, v8Value)) |
127 return false; | 106 return false; |
128 | 107 |
129 V8StringResource<> stringValue(v8Value); | 108 V8StringResource<> stringValue(v8Value); |
130 if (!stringValue.prepare()) | 109 if (!stringValue.prepare()) |
131 return false; | 110 return false; |
132 value = stringValue; | 111 value = stringValue; |
133 return true; | 112 return true; |
134 } | 113 } |
135 | 114 |
136 template <> | 115 template <> |
137 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, String& value) | 116 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, String& value) |
138 { | 117 { |
139 return getStringType(dictionary, key, value); | 118 return getStringType(dictionary, key, value); |
140 } | 119 } |
141 | 120 |
142 template <> | 121 template <> |
143 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Atom
icString& value) | 122 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Atom
icString& value) |
144 { | 123 { |
145 return getStringType(dictionary, key, value); | 124 return getStringType(dictionary, key, value); |
146 } | 125 } |
147 | 126 |
148 template <> | 127 template <> |
149 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, String& value) | |
150 { | |
151 Dictionary::ConversionContextScope scope(context); | |
152 | |
153 v8::Local<v8::Value> v8Value; | |
154 if (!dictionary.get(key, v8Value)) | |
155 return true; | |
156 | |
157 V8StringResource<> stringValue(v8Value); | |
158 if (!stringValue.prepare()) | |
159 return false; | |
160 value = stringValue; | |
161 return true; | |
162 } | |
163 | |
164 template <> | |
165 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Scri
ptValue& value) | 128 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Scri
ptValue& value) |
166 { | 129 { |
167 v8::Local<v8::Value> v8Value; | 130 v8::Local<v8::Value> v8Value; |
168 if (!dictionary.get(key, v8Value)) | 131 if (!dictionary.get(key, v8Value)) |
169 return false; | 132 return false; |
170 | 133 |
171 value = ScriptValue(ScriptState::current(dictionary.isolate()), v8Value); | 134 value = ScriptValue(ScriptState::current(dictionary.isolate()), v8Value); |
172 return true; | 135 return true; |
173 } | 136 } |
174 | 137 |
175 template <> | |
176 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, ScriptValue& value) | |
177 { | |
178 Dictionary::ConversionContextScope scope(context); | |
179 | |
180 DictionaryHelper::get(dictionary, key, value); | |
181 return true; | |
182 } | |
183 | |
184 template<typename NumericType> | 138 template<typename NumericType> |
185 bool getNumericType(const Dictionary& dictionary, const String& key, NumericType
& value) | 139 bool getNumericType(const Dictionary& dictionary, const String& key, NumericType
& value) |
186 { | 140 { |
187 int32_t int32Value; | 141 int32_t int32Value; |
188 if (!DictionaryHelper::get(dictionary, key, int32Value)) | 142 if (!DictionaryHelper::get(dictionary, key, int32Value)) |
189 return false; | 143 return false; |
190 value = static_cast<NumericType>(int32Value); | 144 value = static_cast<NumericType>(int32Value); |
191 return true; | 145 return true; |
192 } | 146 } |
193 | 147 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 Vector<String> indexedValue = toImplArray<Vector<String>>(v8IndexedValue
, i, dictionary.isolate(), exceptionState); | 291 Vector<String> indexedValue = toImplArray<Vector<String>>(v8IndexedValue
, i, dictionary.isolate(), exceptionState); |
338 if (exceptionState.hadException()) | 292 if (exceptionState.hadException()) |
339 return false; | 293 return false; |
340 value.append(indexedValue); | 294 value.append(indexedValue); |
341 } | 295 } |
342 | 296 |
343 return true; | 297 return true; |
344 } | 298 } |
345 | 299 |
346 template <> | 300 template <> |
347 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, Vector<String>& value) | |
348 { | |
349 Dictionary::ConversionContextScope scope(context); | |
350 | |
351 v8::Local<v8::Value> v8Value; | |
352 if (!dictionary.get(key, v8Value)) | |
353 return true; | |
354 | |
355 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) | |
356 return true; | |
357 | |
358 if (!v8Value->IsArray()) { | |
359 context.throwTypeError(ExceptionMessages::notASequenceTypeProperty(key))
; | |
360 return false; | |
361 } | |
362 | |
363 return DictionaryHelper::get(dictionary, key, value); | |
364 } | |
365 | |
366 template <> | |
367 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, ArrayValue& value) | 301 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin
g& key, ArrayValue& value) |
368 { | 302 { |
369 v8::Local<v8::Value> v8Value; | 303 v8::Local<v8::Value> v8Value; |
370 if (!dictionary.get(key, v8Value)) | 304 if (!dictionary.get(key, v8Value)) |
371 return false; | 305 return false; |
372 | 306 |
373 if (!v8Value->IsArray()) | 307 if (!v8Value->IsArray()) |
374 return false; | 308 return false; |
375 | 309 |
376 ASSERT(dictionary.isolate()); | 310 ASSERT(dictionary.isolate()); |
377 ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent()); | 311 ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent()); |
378 value = ArrayValue(v8::Local<v8::Array>::Cast(v8Value), dictionary.isolate()
); | 312 value = ArrayValue(v8::Local<v8::Array>::Cast(v8Value), dictionary.isolate()
); |
379 return true; | 313 return true; |
380 } | 314 } |
381 | 315 |
382 template <> | |
383 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, ArrayValue& value) | |
384 { | |
385 Dictionary::ConversionContextScope scope(context); | |
386 | |
387 v8::Local<v8::Value> v8Value; | |
388 if (!dictionary.get(key, v8Value)) | |
389 return true; | |
390 | |
391 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) | |
392 return true; | |
393 | |
394 if (!v8Value->IsArray()) { | |
395 context.throwTypeError(ExceptionMessages::notASequenceTypeProperty(key))
; | |
396 return false; | |
397 } | |
398 | |
399 return DictionaryHelper::get(dictionary, key, value); | |
400 } | |
401 | |
402 template CORE_EXPORT bool DictionaryHelper::get(const Dictionary&, const String&
key, RefPtr<DOMUint8Array>& value); | 316 template CORE_EXPORT bool DictionaryHelper::get(const Dictionary&, const String&
key, RefPtr<DOMUint8Array>& value); |
403 | 317 |
404 template <typename T> | 318 template <typename T> |
405 struct IntegralTypeTraits { | 319 struct IntegralTypeTraits { |
406 }; | 320 }; |
407 | 321 |
408 template <> | 322 template <> |
409 struct IntegralTypeTraits<uint8_t> { | 323 struct IntegralTypeTraits<uint8_t> { |
410 static inline uint8_t toIntegral(v8::Isolate* isolate, v8::Local<v8::Value>
value, IntegerConversionConfiguration configuration, ExceptionState& exceptionSt
ate) | 324 static inline uint8_t toIntegral(v8::Isolate* isolate, v8::Local<v8::Value>
value, IntegerConversionConfiguration configuration, ExceptionState& exceptionSt
ate) |
411 { | 325 { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 402 |
489 template <> | 403 template <> |
490 struct IntegralTypeTraits<long long> { | 404 struct IntegralTypeTraits<long long> { |
491 static inline long long toIntegral(v8::Isolate* isolate, v8::Local<v8::Value
> value, IntegerConversionConfiguration configuration, ExceptionState& exception
State) | 405 static inline long long toIntegral(v8::Isolate* isolate, v8::Local<v8::Value
> value, IntegerConversionConfiguration configuration, ExceptionState& exception
State) |
492 { | 406 { |
493 return toInt64(isolate, value, configuration, exceptionState); | 407 return toInt64(isolate, value, configuration, exceptionState); |
494 } | 408 } |
495 static const String typeName() { return "Int64"; } | 409 static const String typeName() { return "Int64"; } |
496 }; | 410 }; |
497 | 411 |
498 template<typename T> | |
499 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, T& value) | |
500 { | |
501 Dictionary::ConversionContextScope scope(context); | |
502 | |
503 v8::Local<v8::Value> v8Value; | |
504 if (!dictionary.get(key, v8Value)) | |
505 return true; | |
506 | |
507 value = IntegralTypeTraits<T>::toIntegral(dictionary.isolate(), v8Value, Nor
malConversion, context.exceptionState()); | |
508 if (context.exceptionState().throwIfNeeded()) | |
509 return false; | |
510 | |
511 return true; | |
512 } | |
513 | |
514 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, uint8_t& value); | |
515 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, int8_t& value); | |
516 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, unsigned short& value); | |
517 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, short& value); | |
518 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, unsigned& value); | |
519 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, unsigned long& value); | |
520 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, int& value); | |
521 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, long& value); | |
522 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, long long& value); | |
523 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, unsigned long long& value); | |
524 | |
525 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, RefPtrWillBeMember<EventTarget>& value); | |
526 | |
527 template <> | |
528 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, MessagePortArray& value) | |
529 { | |
530 Dictionary::ConversionContextScope scope(context); | |
531 | |
532 v8::Local<v8::Value> v8Value; | |
533 if (!dictionary.get(key, v8Value)) | |
534 return true; | |
535 | |
536 ASSERT(dictionary.isolate()); | |
537 ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent()); | |
538 | |
539 if (isUndefinedOrNull(v8Value)) | |
540 return true; | |
541 | |
542 value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value,
key, dictionary.isolate(), context.exceptionState()); | |
543 | |
544 if (context.exceptionState().throwIfNeeded()) | |
545 return false; | |
546 | |
547 return true; | |
548 } | |
549 | |
550 } // namespace blink | 412 } // namespace blink |
OLD | NEW |