Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: Source/bindings/core/v8/DictionaryHelperForCore.cpp

Issue 534133002: [WIP] bindings: Introduce PropertyBag (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
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
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27
28 #include "bindings/core/v8/ArrayValue.h"
29 #include "bindings/core/v8/DictionaryHelperForBindings.h"
30 #include "bindings/core/v8/ExceptionMessages.h"
31 #include "bindings/core/v8/ExceptionState.h"
32 #include "bindings/core/v8/V8Binding.h"
33 #include "bindings/core/v8/V8DOMError.h"
34 #include "bindings/core/v8/V8Element.h"
35 #include "bindings/core/v8/V8EventTarget.h"
36 #include "bindings/core/v8/V8MediaKeyError.h"
37 #include "bindings/core/v8/V8MessagePort.h"
38 #include "bindings/core/v8/V8Path2D.h"
39 #include "bindings/core/v8/V8Storage.h"
40 #include "bindings/core/v8/V8TextTrack.h"
41 #include "bindings/core/v8/V8VoidCallback.h"
42 #include "bindings/core/v8/V8Window.h"
43 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h"
44 #include "bindings/core/v8/custom/V8Uint8ArrayCustom.h"
45 #include "core/html/track/TrackBase.h"
46 #include "wtf/MathExtras.h"
47
48 namespace blink {
49
50 template <>
51 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, v8:: Local<v8::Value>& value)
52 {
53 return dictionary.get(key, value);
54 }
55
56 template <>
57 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Dict ionary& value)
58 {
59 return dictionary.get(key, value);
60 }
61
62 template <>
63 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, bool & value)
64 {
65 v8::Local<v8::Value> v8Value;
66 if (!dictionary.get(key, v8Value))
67 return false;
68
69 v8::Local<v8::Boolean> v8Bool = v8Value->ToBoolean();
70 if (v8Bool.IsEmpty())
71 return false;
72 value = v8Bool->Value();
73 return true;
74 }
75
76 template <>
77 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, bool& value)
78 {
79 Dictionary::ConversionContextScope scope(context);
80 DictionaryHelper::get(dictionary, key, value);
81 return true;
82 }
83
84 template <>
85 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, int3 2_t& value)
86 {
87 v8::Local<v8::Value> v8Value;
88 if (!dictionary.get(key, v8Value))
89 return false;
90
91 v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32();
92 if (v8Int32.IsEmpty())
93 return false;
94 value = v8Int32->Value();
95 return true;
96 }
97
98 template <>
99 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub le& value, bool& hasValue)
100 {
101 v8::Local<v8::Value> v8Value;
102 if (!dictionary.get(key, v8Value)) {
103 hasValue = false;
104 return false;
105 }
106
107 hasValue = true;
108 TONATIVE_DEFAULT(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false );
109 if (v8Number.IsEmpty())
110 return false;
111 value = v8Number->Value();
112 return true;
113 }
114
115 template <>
116 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub le& value)
117 {
118 bool unused;
119 return DictionaryHelper::get(dictionary, key, value, unused);
120 }
121
122 template <>
123 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, double& value)
124 {
125 Dictionary::ConversionContextScope scope(context);
126
127 bool hasValue = false;
128 if (!DictionaryHelper::get(dictionary, key, value, hasValue) && hasValue) {
129 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "is not of type 'double'."));
130 return false;
131 }
132 return true;
133 }
134
135 template<typename StringType>
136 bool getStringType(const Dictionary& dictionary, const String& key, StringType& value)
137 {
138 v8::Local<v8::Value> v8Value;
139 if (!dictionary.get(key, v8Value))
140 return false;
141
142 TOSTRING_DEFAULT(V8StringResource<>, stringValue, v8Value, false);
143 value = stringValue;
144 return true;
145 }
146
147 template <>
148 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Stri ng& value)
149 {
150 return getStringType(dictionary, key, value);
151 }
152
153 template <>
154 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Atom icString& value)
155 {
156 return getStringType(dictionary, key, value);
157 }
158
159 template <>
160 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, String& value)
161 {
162 Dictionary::ConversionContextScope scope(context);
163
164 v8::Local<v8::Value> v8Value;
165 if (!dictionary.get(key, v8Value))
166 return true;
167
168 TOSTRING_DEFAULT(V8StringResource<>, stringValue, v8Value, false);
169 value = stringValue;
170 return true;
171 }
172
173 template <>
174 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Scri ptValue& value)
175 {
176 v8::Local<v8::Value> v8Value;
177 if (!dictionary.get(key, v8Value))
178 return false;
179
180 value = ScriptValue(ScriptState::current(dictionary.isolate()), v8Value);
181 return true;
182 }
183
184 template <>
185 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, ScriptValue& value)
186 {
187 Dictionary::ConversionContextScope scope(context);
188
189 DictionaryHelper::get(dictionary, key, value);
190 return true;
191 }
192
193 template<typename NumericType>
194 bool getNumericType(const Dictionary& dictionary, const String& key, NumericType & value)
195 {
196 v8::Local<v8::Value> v8Value;
197 if (!dictionary.get(key, v8Value))
198 return false;
199
200 v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32();
201 if (v8Int32.IsEmpty())
202 return false;
203 value = static_cast<NumericType>(v8Int32->Value());
204 return true;
205 }
206
207 template <>
208 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, shor t& value)
209 {
210 return getNumericType<short>(dictionary, key, value);
211 }
212
213 template <>
214 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned short& value)
215 {
216 return getNumericType<unsigned short>(dictionary, key, value);
217 }
218
219 template <>
220 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned& value)
221 {
222 return getNumericType<unsigned>(dictionary, key, value);
223 }
224
225 template <>
226 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long& value)
227 {
228 v8::Local<v8::Value> v8Value;
229 if (!dictionary.get(key, v8Value))
230 return false;
231
232 v8::Local<v8::Integer> v8Integer = v8Value->ToInteger();
233 if (v8Integer.IsEmpty())
234 return false;
235 value = static_cast<unsigned long>(v8Integer->Value());
236 return true;
237 }
238
239 template <>
240 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long long& value)
241 {
242 v8::Local<v8::Value> v8Value;
243 if (!dictionary.get(key, v8Value))
244 return false;
245
246 TONATIVE_DEFAULT(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false );
247 if (v8Number.IsEmpty())
248 return false;
249 double d = v8Number->Value();
250 doubleToInteger(d, value);
251 return true;
252 }
253
254 template <>
255 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP trWillBeMember<LocalDOMWindow>& value)
256 {
257 v8::Local<v8::Value> v8Value;
258 if (!dictionary.get(key, v8Value))
259 return false;
260
261 // We need to handle a DOMWindow specially, because a DOMWindow wrapper
262 // exists on a prototype chain of v8Value.
263 value = toDOMWindow(v8Value, dictionary.isolate());
264 return true;
265 }
266
267 template <>
268 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Mess agePortArray& value)
269 {
270 v8::Local<v8::Value> v8Value;
271 if (!dictionary.get(key, v8Value))
272 return false;
273
274 ASSERT(dictionary.isolate());
275 ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent());
276 if (blink::isUndefinedOrNull(v8Value))
277 return true;
278 bool success = false;
279 value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value, key, dictionary.isolate(), &success);
280 return success;
281 }
282
283 template <>
284 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Hash Set<AtomicString>& value)
285 {
286 v8::Local<v8::Value> v8Value;
287 if (!dictionary.get(key, v8Value))
288 return false;
289
290 // FIXME: Support array-like objects
291 if (!v8Value->IsArray())
292 return false;
293
294 ASSERT(dictionary.isolate());
295 ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent());
296 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
297 for (size_t i = 0; i < v8Array->Length(); ++i) {
298 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(dictio nary.isolate(), i));
299 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false);
300 value.add(stringValue);
301 }
302
303 return true;
304 }
305
306 template <>
307 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, HashSet<AtomicString>& value)
308 {
309 Dictionary::ConversionContextScope scope(context);
310
311 v8::Local<v8::Value> v8Value;
312 if (!dictionary.get(key, v8Value))
313 return true;
314
315 if (context.isNullable() && blink::isUndefinedOrNull(v8Value))
316 return true;
317
318 if (!v8Value->IsArray()) {
319 context.throwTypeError(ExceptionMessages::notASequenceTypeProperty(key)) ;
320 return false;
321 }
322
323 return DictionaryHelper::get(dictionary, key, value);
324 }
325
326 template <>
327 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP trWillBeMember<TrackBase>& value)
328 {
329 v8::Local<v8::Value> v8Value;
330 if (!dictionary.get(key, v8Value))
331 return false;
332
333 TrackBase* source = 0;
334 if (v8Value->IsObject()) {
335 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
336
337 // FIXME: this will need to be changed so it can also return an AudioTra ck or a VideoTrack once
338 // we add them.
339 v8::Handle<v8::Object> track = V8TextTrack::findInstanceInPrototypeChain (wrapper, dictionary.isolate());
340 if (!track.IsEmpty())
341 source = V8TextTrack::toImpl(track);
342 }
343 value = source;
344 return true;
345 }
346
347 template <>
348 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP trWillBeMember<EventTarget>& value)
349 {
350 v8::Local<v8::Value> v8Value;
351 if (!dictionary.get(key, v8Value))
352 return false;
353
354 value = nullptr;
355 // We need to handle a LocalDOMWindow specially, because a LocalDOMWindow wr apper
356 // exists on a prototype chain of v8Value.
357 if (v8Value->IsObject()) {
358 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
359 v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(w rapper, dictionary.isolate());
360 if (!window.IsEmpty()) {
361 value = toWrapperTypeInfo(window)->toEventTarget(window);
362 return true;
363 }
364 }
365
366 if (V8DOMWrapper::isDOMWrapper(v8Value)) {
367 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
368 value = toWrapperTypeInfo(wrapper)->toEventTarget(wrapper);
369 }
370 return true;
371 }
372
373 template <>
374 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Vect or<String>& value)
375 {
376 v8::Local<v8::Value> v8Value;
377 if (!dictionary.get(key, v8Value))
378 return false;
379
380 if (!v8Value->IsArray())
381 return false;
382
383 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
384 for (size_t i = 0; i < v8Array->Length(); ++i) {
385 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(diction ary.isolate(), i));
386 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false);
387 value.append(stringValue);
388 }
389
390 return true;
391 }
392
393 template <>
394 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Vector<String>& value)
395 {
396 Dictionary::ConversionContextScope scope(context);
397
398 v8::Local<v8::Value> v8Value;
399 if (!dictionary.get(key, v8Value))
400 return true;
401
402 if (context.isNullable() && blink::isUndefinedOrNull(v8Value))
403 return true;
404
405 if (!v8Value->IsArray()) {
406 context.throwTypeError(ExceptionMessages::notASequenceTypeProperty(key)) ;
407 return false;
408 }
409
410 return DictionaryHelper::get(dictionary, key, value);
411 }
412
413 template <>
414 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Arra yValue& value)
415 {
416 v8::Local<v8::Value> v8Value;
417 if (!dictionary.get(key, v8Value))
418 return false;
419
420 if (!v8Value->IsArray())
421 return false;
422
423 ASSERT(dictionary.isolate());
424 ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent());
425 value = ArrayValue(v8::Local<v8::Array>::Cast(v8Value), dictionary.isolate() );
426 return true;
427 }
428
429 template <>
430 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, ArrayValue& value)
431 {
432 Dictionary::ConversionContextScope scope(context);
433
434 v8::Local<v8::Value> v8Value;
435 if (!dictionary.get(key, v8Value))
436 return true;
437
438 if (context.isNullable() && blink::isUndefinedOrNull(v8Value))
439 return true;
440
441 if (!v8Value->IsArray()) {
442 context.throwTypeError(ExceptionMessages::notASequenceTypeProperty(key)) ;
443 return false;
444 }
445
446 return DictionaryHelper::get(dictionary, key, value);
447 }
448
449 template <>
450 struct DictionaryHelperTraits<Uint8Array> {
451 typedef V8Uint8Array type;
452 };
453
454 template <>
455 struct DictionaryHelperTraits<ArrayBufferView> {
456 typedef V8ArrayBufferView type;
457 };
458
459 template <>
460 struct DictionaryHelperTraits<MediaKeyError> {
461 typedef V8MediaKeyError type;
462 };
463
464 template <>
465 struct DictionaryHelperTraits<DOMError> {
466 typedef V8DOMError type;
467 };
468
469 template <>
470 struct DictionaryHelperTraits<Storage> {
471 typedef V8Storage type;
472 };
473
474 template bool DictionaryHelper::get(const Dictionary&, const String& key, RefPtr <Uint8Array>& value);
475 template bool DictionaryHelper::get(const Dictionary&, const String& key, RefPtr <ArrayBufferView>& value);
476 template bool DictionaryHelper::get(const Dictionary&, const String& key, RefPtr WillBeMember<MediaKeyError>& value);
477 template bool DictionaryHelper::get(const Dictionary&, const String& key, RefPtr WillBeMember<DOMError>& value);
478 template bool DictionaryHelper::get(const Dictionary&, const String& key, RefPtr WillBeMember<Storage>& value);
479
480 template <typename T>
481 struct IntegralTypeTraits {
482 };
483
484 template <>
485 struct IntegralTypeTraits<uint8_t> {
486 static inline uint8_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers ionConfiguration configuration, ExceptionState& exceptionState)
487 {
488 return toUInt8(value, configuration, exceptionState);
489 }
490 static const String typeName() { return "UInt8"; }
491 };
492
493 template <>
494 struct IntegralTypeTraits<int8_t> {
495 static inline int8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversi onConfiguration configuration, ExceptionState& exceptionState)
496 {
497 return toInt8(value, configuration, exceptionState);
498 }
499 static const String typeName() { return "Int8"; }
500 };
501
502 template <>
503 struct IntegralTypeTraits<unsigned short> {
504 static inline uint16_t toIntegral(v8::Handle<v8::Value> value, IntegerConver sionConfiguration configuration, ExceptionState& exceptionState)
505 {
506 return toUInt16(value, configuration, exceptionState);
507 }
508 static const String typeName() { return "UInt16"; }
509 };
510
511 template <>
512 struct IntegralTypeTraits<short> {
513 static inline int16_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers ionConfiguration configuration, ExceptionState& exceptionState)
514 {
515 return toInt16(value, configuration, exceptionState);
516 }
517 static const String typeName() { return "Int16"; }
518 };
519
520 template <>
521 struct IntegralTypeTraits<unsigned> {
522 static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConver sionConfiguration configuration, ExceptionState& exceptionState)
523 {
524 return toUInt32(value, configuration, exceptionState);
525 }
526 static const String typeName() { return "UInt32"; }
527 };
528
529 template <>
530 struct IntegralTypeTraits<unsigned long> {
531 static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConver sionConfiguration configuration, ExceptionState& exceptionState)
532 {
533 return toUInt32(value, configuration, exceptionState);
534 }
535 static const String typeName() { return "UInt32"; }
536 };
537
538 template <>
539 struct IntegralTypeTraits<int> {
540 static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers ionConfiguration configuration, ExceptionState& exceptionState)
541 {
542 return toInt32(value, configuration, exceptionState);
543 }
544 static const String typeName() { return "Int32"; }
545 };
546
547 template <>
548 struct IntegralTypeTraits<long> {
549 static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers ionConfiguration configuration, ExceptionState& exceptionState)
550 {
551 return toInt32(value, configuration, exceptionState);
552 }
553 static const String typeName() { return "Int32"; }
554 };
555
556 template <>
557 struct IntegralTypeTraits<unsigned long long> {
558 static inline unsigned long long toIntegral(v8::Handle<v8::Value> value, Int egerConversionConfiguration configuration, ExceptionState& exceptionState)
559 {
560 return toUInt64(value, configuration, exceptionState);
561 }
562 static const String typeName() { return "UInt64"; }
563 };
564
565 template <>
566 struct IntegralTypeTraits<long long> {
567 static inline long long toIntegral(v8::Handle<v8::Value> value, IntegerConve rsionConfiguration configuration, ExceptionState& exceptionState)
568 {
569 return toInt64(value, configuration, exceptionState);
570 }
571 static const String typeName() { return "Int64"; }
572 };
573
574 template<typename T>
575 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, T& value)
576 {
577 Dictionary::ConversionContextScope scope(context);
578
579 v8::Local<v8::Value> v8Value;
580 if (!dictionary.get(key, v8Value))
581 return true;
582
583 value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context .exceptionState());
584 if (context.exceptionState().throwIfNeeded())
585 return false;
586
587 return true;
588 }
589
590 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, uint8_t& value);
591 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, int8_t& value);
592 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, unsigned short& value);
593 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, short& value);
594 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, unsigned& value);
595 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, unsigned long& value);
596 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, int& value);
597 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, long& value);
598 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, long long& value);
599 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, unsigned long long& value);
600
601 template<typename T>
602 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Nullable<T>& value)
603 {
604 Dictionary::ConversionContextScope scope(context);
605
606 v8::Local<v8::Value> v8Value;
607 if (!dictionary.get(key, v8Value))
608 return true;
609
610 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) {
611 value = Nullable<T>();
612 return true;
613 }
614
615 T converted = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, c ontext.exceptionState());
616
617 if (context.exceptionState().throwIfNeeded())
618 return false;
619
620 value = Nullable<T>(converted);
621 return true;
622 }
623
624 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<uint8_t>& value);
625 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<int8_t>& value);
626 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<unsigned short>& value);
627 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<short>& value);
628 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<unsigned>& value);
629 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<unsigned long>& value);
630 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<int>& value);
631 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<long>& value);
632 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<long long>& value);
633 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, Nullable<unsigned long long>& value);
634
635 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, RefPtrWillBeMember<LocalDOMWindow>& value);
636 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, RefPtrWillBeMember<Storage>& value);
637 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, RefPtr<Uint8Array>& value);
638 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, RefPtr<ArrayBufferView>& value);
639 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, RefPtrWillBeMember<MediaKeyError>& value);
640 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, RefPtrWillBeMember<TrackBase>& value);
641 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio nContext&, const String& key, RefPtrWillBeMember<EventTarget>& value);
642
643 template <>
644 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, MessagePortArray& value)
645 {
646 Dictionary::ConversionContextScope scope(context);
647
648 v8::Local<v8::Value> v8Value;
649 if (!dictionary.get(key, v8Value))
650 return true;
651
652 return DictionaryHelper::get(dictionary, key, value);
653 }
654
655 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/DictionaryHelperForBindings.h ('k') | Source/bindings/core/v8/PropertyBag.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698