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

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

Issue 23812006: Have Dictionary use V8TRYCATCH_FOR_V8STRINGRESOURCE() macro (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add test Created 7 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 | Annotate | Revision Log
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 bool unused; 163 bool unused;
164 return get(key, value, unused); 164 return get(key, value, unused);
165 } 165 }
166 166
167 bool Dictionary::get(const String& key, String& value) const 167 bool Dictionary::get(const String& key, String& value) const
168 { 168 {
169 v8::Local<v8::Value> v8Value; 169 v8::Local<v8::Value> v8Value;
170 if (!getKey(key, v8Value)) 170 if (!getKey(key, v8Value))
171 return false; 171 return false;
172 172
173 // FIXME: It is possible for this to throw in which case we'd be getting bac k 173 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, v8Va lue, false);
174 // an empty string and returning true when we should be returning fal se. 174 value = stringValue;
175 // See fast/dom/Geolocation/script-tests/argument-types.js for a simi lar
176 // example.
177 value = toWebCoreString(v8Value);
178 return true; 175 return true;
179 } 176 }
180 177
181 bool Dictionary::get(const String& key, ScriptValue& value) const 178 bool Dictionary::get(const String& key, ScriptValue& value) const
182 { 179 {
183 v8::Local<v8::Value> v8Value; 180 v8::Local<v8::Value> v8Value;
184 if (!getKey(key, v8Value)) 181 if (!getKey(key, v8Value))
185 return false; 182 return false;
186 183
187 value = ScriptValue(v8Value); 184 value = ScriptValue(v8Value);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 300
304 // FIXME: Support array-like objects 301 // FIXME: Support array-like objects
305 if (!v8Value->IsArray()) 302 if (!v8Value->IsArray())
306 return false; 303 return false;
307 304
308 ASSERT(m_isolate); 305 ASSERT(m_isolate);
309 ASSERT(m_isolate == v8::Isolate::GetCurrent()); 306 ASSERT(m_isolate == v8::Isolate::GetCurrent());
310 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); 307 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
311 for (size_t i = 0; i < v8Array->Length(); ++i) { 308 for (size_t i = 0; i < v8Array->Length(); ++i) {
312 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(i, m_i solate)); 309 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(i, m_i solate));
313 value.add(toWebCoreString(indexedValue)); 310 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, indexedValue, false);
311 value.add(stringValue);
314 } 312 }
315 313
316 return true; 314 return true;
317 } 315 }
318 316
319 bool Dictionary::getWithUndefinedOrNullCheck(const String& key, String& value) c onst 317 bool Dictionary::getWithUndefinedOrNullCheck(const String& key, String& value) c onst
320 { 318 {
321 v8::Local<v8::Value> v8Value; 319 v8::Local<v8::Value> v8Value;
322 if (!getKey(key, v8Value) || v8Value->IsNull() || v8Value->IsUndefined()) 320 if (!getKey(key, v8Value) || v8Value->IsNull() || v8Value->IsUndefined())
323 return false; 321 return false;
324 322
325 // FIXME: It is possible for this to throw in which case we'd be getting bac k 323 if (WebCore::isUndefinedOrNull(v8Value)) {
326 // an empty string and returning true when we should be returning fal se. 324 value = String();
327 // See fast/dom/Geolocation/script-tests/argument-types.js for a simi lar 325 return true;
328 // example. 326 }
329 value = WebCore::isUndefinedOrNull(v8Value) ? String() : toWebCoreString(v8V alue); 327
328 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, v8Va lue, false);
329 value = stringValue;
330 return true; 330 return true;
331 } 331 }
332 332
333 bool Dictionary::get(const String& key, RefPtr<Uint8Array>& value) const 333 bool Dictionary::get(const String& key, RefPtr<Uint8Array>& value) const
334 { 334 {
335 v8::Local<v8::Value> v8Value; 335 v8::Local<v8::Value> v8Value;
336 if (!getKey(key, v8Value)) 336 if (!getKey(key, v8Value))
337 return false; 337 return false;
338 338
339 value = 0; 339 value = 0;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 v8::Local<v8::Value> v8Value; 491 v8::Local<v8::Value> v8Value;
492 if (!getKey(key, v8Value)) 492 if (!getKey(key, v8Value))
493 return false; 493 return false;
494 494
495 if (!v8Value->IsArray()) 495 if (!v8Value->IsArray())
496 return false; 496 return false;
497 497
498 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); 498 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
499 for (size_t i = 0; i < v8Array->Length(); ++i) { 499 for (size_t i = 0; i < v8Array->Length(); ++i) {
500 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(i)); 500 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(i));
501 value.append(toWebCoreString(indexedValue)); 501 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, indexedValue, false);
502 value.append(stringValue);
502 } 503 }
503 504
504 return true; 505 return true;
505 } 506 }
506 507
507 bool Dictionary::get(const String& key, ArrayValue& value) const 508 bool Dictionary::get(const String& key, ArrayValue& value) const
508 { 509 {
509 v8::Local<v8::Value> v8Value; 510 v8::Local<v8::Value> v8Value;
510 if (!getKey(key, v8Value)) 511 if (!getKey(key, v8Value))
511 return false; 512 return false;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 578
578 v8::Local<v8::Array> properties = options->GetOwnPropertyNames(); 579 v8::Local<v8::Array> properties = options->GetOwnPropertyNames();
579 if (properties.IsEmpty()) 580 if (properties.IsEmpty())
580 return true; 581 return true;
581 for (uint32_t i = 0; i < properties->Length(); ++i) { 582 for (uint32_t i = 0; i < properties->Length(); ++i) {
582 v8::Local<v8::String> key = properties->Get(i)->ToString(); 583 v8::Local<v8::String> key = properties->Get(i)->ToString();
583 if (!options->Has(key)) 584 if (!options->Has(key))
584 continue; 585 continue;
585 586
586 v8::Local<v8::Value> value = options->Get(key); 587 v8::Local<v8::Value> value = options->Get(key);
587 String stringKey = toWebCoreString(key); 588 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringKey, ke y, false);
588 String stringValue = toWebCoreString(value); 589 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, value, false);
589 if (!stringKey.isEmpty()) 590 if (!static_cast<const String&>(stringKey).isEmpty())
590 hashMap.set(stringKey, stringValue); 591 hashMap.set(stringKey, stringValue);
591 } 592 }
592 593
593 return true; 594 return true;
594 } 595 }
595 596
596 bool Dictionary::getOwnPropertyNames(Vector<String>& names) const 597 bool Dictionary::getOwnPropertyNames(Vector<String>& names) const
597 { 598 {
598 if (!isObject()) 599 if (!isObject())
599 return false; 600 return false;
600 601
601 v8::Handle<v8::Object> options = m_options->ToObject(); 602 v8::Handle<v8::Object> options = m_options->ToObject();
602 if (options.IsEmpty()) 603 if (options.IsEmpty())
603 return false; 604 return false;
604 605
605 v8::Local<v8::Array> properties = options->GetOwnPropertyNames(); 606 v8::Local<v8::Array> properties = options->GetOwnPropertyNames();
606 if (properties.IsEmpty()) 607 if (properties.IsEmpty())
607 return true; 608 return true;
608 for (uint32_t i = 0; i < properties->Length(); ++i) { 609 for (uint32_t i = 0; i < properties->Length(); ++i) {
609 v8::Local<v8::String> key = properties->Get(i)->ToString(); 610 v8::Local<v8::String> key = properties->Get(i)->ToString();
610 if (!options->Has(key)) 611 if (!options->Has(key))
611 continue; 612 continue;
612 names.append(toWebCoreString(key)); 613 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringKey, ke y, false);
614 names.append(stringKey);
613 } 615 }
614 616
615 return true; 617 return true;
616 } 618 }
617 619
618 } // namespace WebCore 620 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/js/dictionary-string-conversion-exception-expected.txt ('k') | Source/bindings/v8/V8BindingMacros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698