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

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

Issue 386963003: [WIP][NotForLand] IDL dictionary support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: sequence and array support Created 6 years, 5 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
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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); 383 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
384 for (size_t i = 0; i < v8Array->Length(); ++i) { 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)); 385 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(diction ary.isolate(), i));
386 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false); 386 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false);
387 value.append(stringValue); 387 value.append(stringValue);
388 } 388 }
389 389
390 return true; 390 return true;
391 } 391 }
392 392
393 // FIXME: Remove this special casing. We should either remove DictionaryHelper
394 // completely, or auto-generate DictionaryHelper::get<T>() if needed.
395 template <>
396 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP trWillBeMember<Element>& value)
397 {
398 v8::Local<v8::Value> v8Value;
399 if (!dictionary.get(key, v8Value))
400 return false;
401
402 value = V8Element::toNativeWithTypeCheck(dictionary.isolate(), v8Value);
403 return true;
404 }
405
406 // FIXME: Remove this. See above comment.
407 template <>
408 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Will BeHeapVector<RefPtrWillBeMember<Element> >& value)
409 {
410 v8::Local<v8::Value> v8Value;
411 if (!dictionary.get(key, v8Value))
412 return false;
413 if (!v8Value->IsArray())
414 return false;
415 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
416 for (size_t i = 0; i < v8Array->Length(); ++i) {
417 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(diction ary.isolate(), i));
418 value.append(V8Element::toNativeWithTypeCheck(dictionary.isolate(), inde xedValue));
419 }
420 return true;
421 }
422
393 template <> 423 template <>
394 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Vector<String>& value) 424 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Vector<String>& value)
395 { 425 {
396 Dictionary::ConversionContextScope scope(context); 426 Dictionary::ConversionContextScope scope(context);
397 427
398 v8::Local<v8::Value> v8Value; 428 v8::Local<v8::Value> v8Value;
399 if (!dictionary.get(key, v8Value)) 429 if (!dictionary.get(key, v8Value))
400 return true; 430 return true;
401 431
402 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) 432 if (context.isNullable() && blink::isUndefinedOrNull(v8Value))
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 Dictionary::ConversionContextScope scope(context); 676 Dictionary::ConversionContextScope scope(context);
647 677
648 v8::Local<v8::Value> v8Value; 678 v8::Local<v8::Value> v8Value;
649 if (!dictionary.get(key, v8Value)) 679 if (!dictionary.get(key, v8Value))
650 return true; 680 return true;
651 681
652 return DictionaryHelper::get(dictionary, key, value); 682 return DictionaryHelper::get(dictionary, key, value);
653 } 683 }
654 684
655 } // namespace blink 685 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/fast/dom/some-dictionary-expected.txt ('k') | Source/bindings/core/v8/generated.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698