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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 return true; | 201 return true; |
202 } | 202 } |
203 | 203 |
204 template<typename StringType> | 204 template<typename StringType> |
205 inline bool Dictionary::getStringType(const String& key, StringType& value) cons
t | 205 inline bool Dictionary::getStringType(const String& key, StringType& value) cons
t |
206 { | 206 { |
207 v8::Local<v8::Value> v8Value; | 207 v8::Local<v8::Value> v8Value; |
208 if (!getKey(key, v8Value)) | 208 if (!getKey(key, v8Value)) |
209 return false; | 209 return false; |
210 | 210 |
211 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, v8Va
lue, false); | 211 V8STRINGRESOURCE_PREPARE_RETURN(V8StringResource<>, stringValue, v8Value, fa
lse); |
212 value = stringValue; | 212 value = stringValue; |
213 return true; | 213 return true; |
214 } | 214 } |
215 | 215 |
216 bool Dictionary::get(const String& key, String& value) const | 216 bool Dictionary::get(const String& key, String& value) const |
217 { | 217 { |
218 return getStringType(key, value); | 218 return getStringType(key, value); |
219 } | 219 } |
220 | 220 |
221 bool Dictionary::get(const String& key, AtomicString& value) const | 221 bool Dictionary::get(const String& key, AtomicString& value) const |
222 { | 222 { |
223 return getStringType(key, value); | 223 return getStringType(key, value); |
224 } | 224 } |
225 | 225 |
226 bool Dictionary::convert(ConversionContext& context, const String& key, String&
value) const | 226 bool Dictionary::convert(ConversionContext& context, const String& key, String&
value) const |
227 { | 227 { |
228 ConversionContextScope scope(context); | 228 ConversionContextScope scope(context); |
229 | 229 |
230 v8::Local<v8::Value> v8Value; | 230 v8::Local<v8::Value> v8Value; |
231 if (!getKey(key, v8Value)) | 231 if (!getKey(key, v8Value)) |
232 return true; | 232 return true; |
233 | 233 |
234 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, v8Va
lue, false); | 234 V8STRINGRESOURCE_PREPARE_RETURN(V8StringResource<>, stringValue, v8Value, fa
lse); |
235 value = stringValue; | 235 value = stringValue; |
236 return true; | 236 return true; |
237 } | 237 } |
238 | 238 |
239 bool Dictionary::get(const String& key, ScriptValue& value) const | 239 bool Dictionary::get(const String& key, ScriptValue& value) const |
240 { | 240 { |
241 v8::Local<v8::Value> v8Value; | 241 v8::Local<v8::Value> v8Value; |
242 if (!getKey(key, v8Value)) | 242 if (!getKey(key, v8Value)) |
243 return false; | 243 return false; |
244 | 244 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 376 |
377 // FIXME: Support array-like objects | 377 // FIXME: Support array-like objects |
378 if (!v8Value->IsArray()) | 378 if (!v8Value->IsArray()) |
379 return false; | 379 return false; |
380 | 380 |
381 ASSERT(m_isolate); | 381 ASSERT(m_isolate); |
382 ASSERT(m_isolate == v8::Isolate::GetCurrent()); | 382 ASSERT(m_isolate == v8::Isolate::GetCurrent()); |
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::Integer::New(m_isol
ate, i)); | 385 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(m_isol
ate, i)); |
386 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue,
indexedValue, false); | 386 V8STRINGRESOURCE_PREPARE_RETURN(V8StringResource<>, stringValue, indexed
Value, false); |
387 value.add(stringValue); | 387 value.add(stringValue); |
388 } | 388 } |
389 | 389 |
390 return true; | 390 return true; |
391 } | 391 } |
392 | 392 |
393 bool Dictionary::convert(ConversionContext& context, const String& key, HashSet<
AtomicString>& value) const | 393 bool Dictionary::convert(ConversionContext& context, const String& key, HashSet<
AtomicString>& value) const |
394 { | 394 { |
395 ConversionContextScope scope(context); | 395 ConversionContextScope scope(context); |
396 | 396 |
(...skipping 11 matching lines...) Expand all Loading... |
408 | 408 |
409 return get(key, value); | 409 return get(key, value); |
410 } | 410 } |
411 | 411 |
412 bool Dictionary::getWithUndefinedOrNullCheck(const String& key, String& value) c
onst | 412 bool Dictionary::getWithUndefinedOrNullCheck(const String& key, String& value) c
onst |
413 { | 413 { |
414 v8::Local<v8::Value> v8Value; | 414 v8::Local<v8::Value> v8Value; |
415 if (!getKey(key, v8Value) || WebCore::isUndefinedOrNull(v8Value)) | 415 if (!getKey(key, v8Value) || WebCore::isUndefinedOrNull(v8Value)) |
416 return false; | 416 return false; |
417 | 417 |
418 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, v8Va
lue, false); | 418 V8STRINGRESOURCE_PREPARE_RETURN(V8StringResource<>, stringValue, v8Value, fa
lse); |
419 value = stringValue; | 419 value = stringValue; |
420 return true; | 420 return true; |
421 } | 421 } |
422 | 422 |
423 bool Dictionary::get(const String& key, RefPtr<Uint8Array>& value) const | 423 bool Dictionary::get(const String& key, RefPtr<Uint8Array>& value) const |
424 { | 424 { |
425 v8::Local<v8::Value> v8Value; | 425 v8::Local<v8::Value> v8Value; |
426 if (!getKey(key, v8Value)) | 426 if (!getKey(key, v8Value)) |
427 return false; | 427 return false; |
428 | 428 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 v8::Local<v8::Value> v8Value; | 593 v8::Local<v8::Value> v8Value; |
594 if (!getKey(key, v8Value)) | 594 if (!getKey(key, v8Value)) |
595 return false; | 595 return false; |
596 | 596 |
597 if (!v8Value->IsArray()) | 597 if (!v8Value->IsArray()) |
598 return false; | 598 return false; |
599 | 599 |
600 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); | 600 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); |
601 for (size_t i = 0; i < v8Array->Length(); ++i) { | 601 for (size_t i = 0; i < v8Array->Length(); ++i) { |
602 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(m_isola
te, i)); | 602 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(m_isola
te, i)); |
603 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue,
indexedValue, false); | 603 V8STRINGRESOURCE_PREPARE_RETURN(V8StringResource<>, stringValue, indexed
Value, false); |
604 value.append(stringValue); | 604 value.append(stringValue); |
605 } | 605 } |
606 | 606 |
607 return true; | 607 return true; |
608 } | 608 } |
609 | 609 |
610 bool Dictionary::convert(ConversionContext& context, const String& key, Vector<S
tring>& value) const | 610 bool Dictionary::convert(ConversionContext& context, const String& key, Vector<S
tring>& value) const |
611 { | 611 { |
612 ConversionContextScope scope(context); | 612 ConversionContextScope scope(context); |
613 | 613 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 | 694 |
695 v8::Local<v8::Array> properties = options->GetOwnPropertyNames(); | 695 v8::Local<v8::Array> properties = options->GetOwnPropertyNames(); |
696 if (properties.IsEmpty()) | 696 if (properties.IsEmpty()) |
697 return true; | 697 return true; |
698 for (uint32_t i = 0; i < properties->Length(); ++i) { | 698 for (uint32_t i = 0; i < properties->Length(); ++i) { |
699 v8::Local<v8::String> key = properties->Get(i)->ToString(); | 699 v8::Local<v8::String> key = properties->Get(i)->ToString(); |
700 if (!options->Has(key)) | 700 if (!options->Has(key)) |
701 continue; | 701 continue; |
702 | 702 |
703 v8::Local<v8::Value> value = options->Get(key); | 703 v8::Local<v8::Value> value = options->Get(key); |
704 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringKey, ke
y, false); | 704 V8STRINGRESOURCE_PREPARE_RETURN(V8StringResource<>, stringKey, key, fals
e); |
705 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue,
value, false); | 705 V8STRINGRESOURCE_PREPARE_RETURN(V8StringResource<>, stringValue, value,
false); |
706 if (!static_cast<const String&>(stringKey).isEmpty()) | 706 if (!static_cast<const String&>(stringKey).isEmpty()) |
707 hashMap.set(stringKey, stringValue); | 707 hashMap.set(stringKey, stringValue); |
708 } | 708 } |
709 | 709 |
710 return true; | 710 return true; |
711 } | 711 } |
712 | 712 |
713 bool Dictionary::getOwnPropertyNames(Vector<String>& names) const | 713 bool Dictionary::getOwnPropertyNames(Vector<String>& names) const |
714 { | 714 { |
715 if (!isObject()) | 715 if (!isObject()) |
716 return false; | 716 return false; |
717 | 717 |
718 v8::Handle<v8::Object> options = m_options->ToObject(); | 718 v8::Handle<v8::Object> options = m_options->ToObject(); |
719 if (options.IsEmpty()) | 719 if (options.IsEmpty()) |
720 return false; | 720 return false; |
721 | 721 |
722 v8::Local<v8::Array> properties = options->GetOwnPropertyNames(); | 722 v8::Local<v8::Array> properties = options->GetOwnPropertyNames(); |
723 if (properties.IsEmpty()) | 723 if (properties.IsEmpty()) |
724 return true; | 724 return true; |
725 for (uint32_t i = 0; i < properties->Length(); ++i) { | 725 for (uint32_t i = 0; i < properties->Length(); ++i) { |
726 v8::Local<v8::String> key = properties->Get(i)->ToString(); | 726 v8::Local<v8::String> key = properties->Get(i)->ToString(); |
727 if (!options->Has(key)) | 727 if (!options->Has(key)) |
728 continue; | 728 continue; |
729 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringKey, ke
y, false); | 729 V8STRINGRESOURCE_PREPARE_RETURN(V8StringResource<>, stringKey, key, fals
e); |
730 names.append(stringKey); | 730 names.append(stringKey); |
731 } | 731 } |
732 | 732 |
733 return true; | 733 return true; |
734 } | 734 } |
735 | 735 |
736 void Dictionary::ConversionContext::resetPerPropertyContext() | 736 void Dictionary::ConversionContext::resetPerPropertyContext() |
737 { | 737 { |
738 if (m_dirty) { | 738 if (m_dirty) { |
739 m_dirty = false; | 739 m_dirty = false; |
(...skipping 11 matching lines...) Expand all Loading... |
751 | 751 |
752 return *this; | 752 return *this; |
753 } | 753 } |
754 | 754 |
755 void Dictionary::ConversionContext::throwTypeError(const String& detail) | 755 void Dictionary::ConversionContext::throwTypeError(const String& detail) |
756 { | 756 { |
757 exceptionState().throwTypeError(detail); | 757 exceptionState().throwTypeError(detail); |
758 } | 758 } |
759 | 759 |
760 } // namespace WebCore | 760 } // namespace WebCore |
OLD | NEW |