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

Side by Side Diff: content/renderer/pepper/v8_var_converter.cc

Issue 753523002: remove some calls to to-be-deprecated v8::Value::To* functions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/v8_var_converter.h" 5 #include "content/renderer/pepper/v8_var_converter.h"
6 6
7 #include <map> 7 #include <map>
8 #include <stack> 8 #include <stack>
9 #include <string> 9 #include <string>
10 10
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // 3) If the object is an array, return an ArrayVar. 237 // 3) If the object is an array, return an ArrayVar.
238 // 4) If the object can be converted to a resource, return the ResourceVar. 238 // 4) If the object can be converted to a resource, return the ResourceVar.
239 // 5) Otherwise return a DictionaryVar. 239 // 5) Otherwise return a DictionaryVar.
240 scoped_ptr<blink::WebArrayBuffer> web_array_buffer( 240 scoped_ptr<blink::WebArrayBuffer> web_array_buffer(
241 blink::WebArrayBufferConverter::createFromV8Value(val, isolate)); 241 blink::WebArrayBufferConverter::createFromV8Value(val, isolate));
242 if (web_array_buffer.get()) { 242 if (web_array_buffer.get()) {
243 scoped_refptr<HostArrayBufferVar> buffer_var( 243 scoped_refptr<HostArrayBufferVar> buffer_var(
244 new HostArrayBufferVar(*web_array_buffer)); 244 new HostArrayBufferVar(*web_array_buffer));
245 *result = buffer_var->GetPPVar(); 245 *result = buffer_var->GetPPVar();
246 } else if (object_vars_allowed == V8VarConverter::kAllowObjectVars) { 246 } else if (object_vars_allowed == V8VarConverter::kAllowObjectVars) {
247 v8::Handle<v8::Object> object = val->ToObject(); 247 v8::Handle<v8::Object> object = val.As<v8::Object>();
248 *result = content::HostGlobals::Get()-> 248 *result = content::HostGlobals::Get()->
249 host_var_tracker()->V8ObjectVarForV8Object(instance, object); 249 host_var_tracker()->V8ObjectVarForV8Object(instance, object);
250 } else if (val->IsArray()) { 250 } else if (val->IsArray()) {
251 *result = (new ArrayVar())->GetPPVar(); 251 *result = (new ArrayVar())->GetPPVar();
252 } else { 252 } else {
253 bool was_resource; 253 bool was_resource;
254 if (!resource_converter->FromV8Value( 254 if (!resource_converter->FromV8Value(val.As<v8::Object>(), context,
255 val->ToObject(), context, result, &was_resource)) 255 result, &was_resource))
256 return false; 256 return false;
257 if (!was_resource) { 257 if (!was_resource) {
258 *result = (new DictionaryVar())->GetPPVar(); 258 *result = (new DictionaryVar())->GetPPVar();
259 } 259 }
260 } 260 }
261 } else { 261 } else {
262 // Silently ignore the case where we can't convert to a Var as we may 262 // Silently ignore the case where we can't convert to a Var as we may
263 // be trying to convert a type that doesn't have a corresponding 263 // be trying to convert a type that doesn't have a corresponding
264 // PP_Var type. 264 // PP_Var type.
265 return true; 265 return true;
266 } 266 }
267 267
268 *did_create = true; 268 *did_create = true;
269 if (val->IsObject() || val->IsString()) { 269 if (val->IsObject() || val->IsString()) {
270 visited_handles->insert( 270 visited_handles->insert(
271 make_pair(HashedHandle(val->ToObject()), 271 make_pair(HashedHandle(val->ToObject(isolate)),
272 ScopedPPVar(ScopedPPVar::PassRef(), *result))); 272 ScopedPPVar(ScopedPPVar::PassRef(), *result)));
273 } 273 }
274 return true; 274 return true;
275 } 275 }
276 276
277 bool CanHaveChildren(PP_Var var) { 277 bool CanHaveChildren(PP_Var var) {
278 return var.type == PP_VARTYPE_ARRAY || var.type == PP_VARTYPE_DICTIONARY; 278 return var.type == PP_VARTYPE_ARRAY || var.type == PP_VARTYPE_DICTIONARY;
279 } 279 }
280 280
281 } // namespace 281 } // namespace
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 384 }
385 } 385 }
386 } else if (current_var.type == PP_VARTYPE_DICTIONARY) { 386 } else if (current_var.type == PP_VARTYPE_DICTIONARY) {
387 parent_ids.insert(current_var.value.as_id); 387 parent_ids.insert(current_var.value.as_id);
388 DictionaryVar* dict_var = DictionaryVar::FromPPVar(current_var); 388 DictionaryVar* dict_var = DictionaryVar::FromPPVar(current_var);
389 if (!dict_var) { 389 if (!dict_var) {
390 NOTREACHED(); 390 NOTREACHED();
391 return false; 391 return false;
392 } 392 }
393 DCHECK(current_v8->IsObject()); 393 DCHECK(current_v8->IsObject());
394 v8::Handle<v8::Object> v8_object = current_v8->ToObject(); 394 v8::Handle<v8::Object> v8_object = current_v8.As<v8::Object>();
395 395
396 for (DictionaryVar::KeyValueMap::const_iterator iter = 396 for (DictionaryVar::KeyValueMap::const_iterator iter =
397 dict_var->key_value_map().begin(); 397 dict_var->key_value_map().begin();
398 iter != dict_var->key_value_map().end(); 398 iter != dict_var->key_value_map().end();
399 ++iter) { 399 ++iter) {
400 const std::string& key = iter->first; 400 const std::string& key = iter->first;
401 const PP_Var& child_var = iter->second.get(); 401 const PP_Var& child_var = iter->second.get();
402 v8::Handle<v8::Value> child_v8; 402 v8::Handle<v8::Value> child_v8;
403 if (!GetOrCreateV8Value(context, 403 if (!GetOrCreateV8Value(context,
404 child_var, 404 child_var,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 *result_var = PP_MakeUndefined(); 473 *result_var = PP_MakeUndefined();
474 bool is_root = true; 474 bool is_root = true;
475 475
476 while (!stack.empty()) { 476 while (!stack.empty()) {
477 v8::Handle<v8::Value> current_v8 = stack.top().val; 477 v8::Handle<v8::Value> current_v8 = stack.top().val;
478 PP_Var current_var; 478 PP_Var current_var;
479 479
480 if (stack.top().sentinel) { 480 if (stack.top().sentinel) {
481 stack.pop(); 481 stack.pop();
482 if (current_v8->IsObject()) 482 if (current_v8->IsObject())
483 parent_handles.erase(HashedHandle(current_v8->ToObject())); 483 parent_handles.erase(HashedHandle(current_v8.As<v8::Object>()));
484 continue; 484 continue;
485 } else { 485 } else {
486 stack.top().sentinel = true; 486 stack.top().sentinel = true;
487 } 487 }
488 488
489 bool did_create = false; 489 bool did_create = false;
490 if (!GetOrCreateVar(current_v8, 490 if (!GetOrCreateVar(current_v8,
491 context, 491 context,
492 instance_, 492 instance_,
493 object_vars_allowed_, 493 object_vars_allowed_,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 resource_converter_.get())) { 537 resource_converter_.get())) {
538 return false; 538 return false;
539 } 539 }
540 if (did_create && child_v8->IsObject()) 540 if (did_create && child_v8->IsObject())
541 stack.push(child_v8); 541 stack.push(child_v8);
542 542
543 array_var->Set(i, child_var); 543 array_var->Set(i, child_var);
544 } 544 }
545 } else if (current_var.type == PP_VARTYPE_DICTIONARY) { 545 } else if (current_var.type == PP_VARTYPE_DICTIONARY) {
546 DCHECK(current_v8->IsObject()); 546 DCHECK(current_v8->IsObject());
547 v8::Handle<v8::Object> v8_object = current_v8->ToObject(); 547 v8::Handle<v8::Object> v8_object = current_v8.As<v8::Object>();
548 parent_handles.insert(HashedHandle(v8_object)); 548 parent_handles.insert(HashedHandle(v8_object));
549 549
550 DictionaryVar* dict_var = DictionaryVar::FromPPVar(current_var); 550 DictionaryVar* dict_var = DictionaryVar::FromPPVar(current_var);
551 if (!dict_var) { 551 if (!dict_var) {
552 NOTREACHED(); 552 NOTREACHED();
553 return false; 553 return false;
554 } 554 }
555 555
556 v8::Handle<v8::Array> property_names(v8_object->GetOwnPropertyNames()); 556 v8::Handle<v8::Array> property_names(v8_object->GetOwnPropertyNames());
557 for (uint32 i = 0; i < property_names->Length(); ++i) { 557 for (uint32 i = 0; i < property_names->Length(); ++i) {
558 v8::Handle<v8::Value> key(property_names->Get(i)); 558 v8::Handle<v8::Value> key(property_names->Get(i));
559 559
560 // Extend this test to cover more types as necessary and if sensible. 560 // Extend this test to cover more types as necessary and if sensible.
561 if (!key->IsString() && !key->IsNumber()) { 561 if (!key->IsString() && !key->IsNumber()) {
562 NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key) 562 NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key)
563 << "\" " 563 << "\" "
564 "is neither a string nor a number"; 564 "is neither a string nor a number";
565 return false; 565 return false;
566 } 566 }
567 567
568 v8::Handle<v8::String> key_string =
569 key->ToString(context->GetIsolate());
568 // Skip all callbacks: crbug.com/139933 570 // Skip all callbacks: crbug.com/139933
569 if (v8_object->HasRealNamedCallbackProperty(key->ToString())) 571 if (v8_object->HasRealNamedCallbackProperty(key_string))
570 continue; 572 continue;
571 573
572 v8::String::Utf8Value name_utf8(key->ToString()); 574 v8::String::Utf8Value name_utf8(key_string);
573 575
574 v8::TryCatch try_catch; 576 v8::TryCatch try_catch;
575 v8::Handle<v8::Value> child_v8 = v8_object->Get(key); 577 v8::Handle<v8::Value> child_v8 = v8_object->Get(key);
576 if (try_catch.HasCaught()) 578 if (try_catch.HasCaught())
577 return false; 579 return false;
578 580
579 PP_Var child_var; 581 PP_Var child_var;
580 if (!GetOrCreateVar(child_v8, 582 if (!GetOrCreateVar(child_v8,
581 context, 583 context,
582 instance_, 584 instance_,
(...skipping 12 matching lines...) Expand all
595 std::string(*name_utf8, name_utf8.length()), child_var); 597 std::string(*name_utf8, name_utf8.length()), child_var);
596 DCHECK(success); 598 DCHECK(success);
597 } 599 }
598 } 600 }
599 } 601 }
600 *result_var = root; 602 *result_var = root;
601 return true; 603 return true;
602 } 604 }
603 605
604 } // namespace content 606 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/ppb_var_deprecated_impl.cc ('k') | content/renderer/pepper/v8_var_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698