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

Side by Side Diff: Source/bindings/v8/Dictionary.cpp

Issue 242223004: Rename macros TONATIVE_BOOL* and TOSTRING_BOOL to *_DEFAULT (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix comment Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/v8/ScriptController.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 bool Dictionary::get(const String& key, double& value, bool& hasValue) const 170 bool Dictionary::get(const String& key, double& value, bool& hasValue) const
171 { 171 {
172 v8::Local<v8::Value> v8Value; 172 v8::Local<v8::Value> v8Value;
173 if (!getKey(key, v8Value)) { 173 if (!getKey(key, v8Value)) {
174 hasValue = false; 174 hasValue = false;
175 return false; 175 return false;
176 } 176 }
177 177
178 hasValue = true; 178 hasValue = true;
179 TONATIVE_BOOL(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false); 179 TONATIVE_DEFAULT(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false );
180 if (v8Number.IsEmpty()) 180 if (v8Number.IsEmpty())
181 return false; 181 return false;
182 value = v8Number->Value(); 182 value = v8Number->Value();
183 return true; 183 return true;
184 } 184 }
185 185
186 bool Dictionary::get(const String& key, double& value) const 186 bool Dictionary::get(const String& key, double& value) const
187 { 187 {
188 bool unused; 188 bool unused;
189 return get(key, value, unused); 189 return get(key, value, unused);
(...skipping 11 matching lines...) Expand all
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 TOSTRING_BOOL(V8StringResource<>, stringValue, v8Value, false); 211 TOSTRING_DEFAULT(V8StringResource<>, stringValue, v8Value, false);
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 TOSTRING_BOOL(V8StringResource<>, stringValue, v8Value, false); 234 TOSTRING_DEFAULT(V8StringResource<>, stringValue, v8Value, false);
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 value = static_cast<unsigned long>(v8Integer->Value()); 305 value = static_cast<unsigned long>(v8Integer->Value());
306 return true; 306 return true;
307 } 307 }
308 308
309 bool Dictionary::get(const String& key, unsigned long long& value) const 309 bool Dictionary::get(const String& key, unsigned long long& value) const
310 { 310 {
311 v8::Local<v8::Value> v8Value; 311 v8::Local<v8::Value> v8Value;
312 if (!getKey(key, v8Value)) 312 if (!getKey(key, v8Value))
313 return false; 313 return false;
314 314
315 TONATIVE_BOOL(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false); 315 TONATIVE_DEFAULT(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false );
316 if (v8Number.IsEmpty()) 316 if (v8Number.IsEmpty())
317 return false; 317 return false;
318 double d = v8Number->Value(); 318 double d = v8Number->Value();
319 doubleToInteger(d, value); 319 doubleToInteger(d, value);
320 return true; 320 return true;
321 } 321 }
322 322
323 bool Dictionary::get(const String& key, RefPtrWillBeMember<DOMWindow>& value) co nst 323 bool Dictionary::get(const String& key, RefPtrWillBeMember<DOMWindow>& value) co nst
324 { 324 {
325 v8::Local<v8::Value> v8Value; 325 v8::Local<v8::Value> v8Value;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 TOSTRING_BOOL(V8StringResource<>, stringValue, indexedValue, false); 386 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, 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
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 TOSTRING_BOOL(V8StringResource<>, stringValue, v8Value, false); 418 TOSTRING_DEFAULT(V8StringResource<>, stringValue, v8Value, false);
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
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 TOSTRING_BOOL(V8StringResource<>, stringValue, indexedValue, false); 603 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, 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
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 TOSTRING_BOOL(V8StringResource<>, stringKey, key, false); 704 TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false);
705 TOSTRING_BOOL(V8StringResource<>, stringValue, value, false); 705 TOSTRING_DEFAULT(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 TOSTRING_BOOL(V8StringResource<>, stringKey, key, false); 729 TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false);
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
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
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/v8/ScriptController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698