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

Side by Side Diff: content/child/v8_value_converter_impl.cc

Issue 2792573002: Remove base::Value::CreateNullValue (Closed)
Patch Set: Rebase Created 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/child/v8_value_converter_impl.h" 5 #include "content/child/v8_value_converter_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 FromV8ValueState* state, 351 FromV8ValueState* state,
352 v8::Local<v8::Value> val, 352 v8::Local<v8::Value> val,
353 v8::Isolate* isolate) const { 353 v8::Isolate* isolate) const {
354 CHECK(!val.IsEmpty()); 354 CHECK(!val.IsEmpty());
355 355
356 FromV8ValueState::Level state_level(state); 356 FromV8ValueState::Level state_level(state);
357 if (state->HasReachedMaxRecursionDepth()) 357 if (state->HasReachedMaxRecursionDepth())
358 return nullptr; 358 return nullptr;
359 359
360 if (val->IsNull()) 360 if (val->IsNull())
361 return base::Value::CreateNullValue(); 361 return base::MakeUnique<base::Value>();
362 362
363 if (val->IsBoolean()) 363 if (val->IsBoolean())
364 return base::MakeUnique<base::Value>(val->ToBoolean(isolate)->Value()); 364 return base::MakeUnique<base::Value>(val->ToBoolean(isolate)->Value());
365 365
366 if (val->IsNumber() && strategy_) { 366 if (val->IsNumber() && strategy_) {
367 std::unique_ptr<base::Value> out; 367 std::unique_ptr<base::Value> out;
368 if (strategy_->FromV8Number(val.As<v8::Number>(), &out)) 368 if (strategy_->FromV8Number(val.As<v8::Number>(), &out))
369 return out; 369 return out;
370 } 370 }
371 371
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 LOG(ERROR) << "Unexpected v8 value type encountered."; 435 LOG(ERROR) << "Unexpected v8 value type encountered.";
436 return nullptr; 436 return nullptr;
437 } 437 }
438 438
439 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8Array( 439 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8Array(
440 v8::Local<v8::Array> val, 440 v8::Local<v8::Array> val,
441 FromV8ValueState* state, 441 FromV8ValueState* state,
442 v8::Isolate* isolate) const { 442 v8::Isolate* isolate) const {
443 ScopedUniquenessGuard uniqueness_guard(state, val); 443 ScopedUniquenessGuard uniqueness_guard(state, val);
444 if (!uniqueness_guard.is_valid()) 444 if (!uniqueness_guard.is_valid())
445 return base::Value::CreateNullValue(); 445 return base::MakeUnique<base::Value>();
446 446
447 std::unique_ptr<v8::Context::Scope> scope; 447 std::unique_ptr<v8::Context::Scope> scope;
448 // If val was created in a different context than our current one, change to 448 // If val was created in a different context than our current one, change to
449 // that context, but change back after val is converted. 449 // that context, but change back after val is converted.
450 if (!val->CreationContext().IsEmpty() && 450 if (!val->CreationContext().IsEmpty() &&
451 val->CreationContext() != isolate->GetCurrentContext()) 451 val->CreationContext() != isolate->GetCurrentContext())
452 scope.reset(new v8::Context::Scope(val->CreationContext())); 452 scope.reset(new v8::Context::Scope(val->CreationContext()));
453 453
454 if (strategy_) { 454 if (strategy_) {
455 // These base::Unretained's are safe, because Strategy::FromV8Value should 455 // These base::Unretained's are safe, because Strategy::FromV8Value should
(...skipping 12 matching lines...) Expand all
468 // Only fields with integer keys are carried over to the ListValue. 468 // Only fields with integer keys are carried over to the ListValue.
469 for (uint32_t i = 0; i < val->Length(); ++i) { 469 for (uint32_t i = 0; i < val->Length(); ++i) {
470 v8::TryCatch try_catch(isolate); 470 v8::TryCatch try_catch(isolate);
471 v8::Local<v8::Value> child_v8 = val->Get(i); 471 v8::Local<v8::Value> child_v8 = val->Get(i);
472 if (try_catch.HasCaught()) { 472 if (try_catch.HasCaught()) {
473 LOG(ERROR) << "Getter for index " << i << " threw an exception."; 473 LOG(ERROR) << "Getter for index " << i << " threw an exception.";
474 child_v8 = v8::Null(isolate); 474 child_v8 = v8::Null(isolate);
475 } 475 }
476 476
477 if (!val->HasRealIndexedProperty(i)) { 477 if (!val->HasRealIndexedProperty(i)) {
478 result->Append(base::Value::CreateNullValue()); 478 result->Append(base::MakeUnique<base::Value>());
479 continue; 479 continue;
480 } 480 }
481 481
482 std::unique_ptr<base::Value> child = 482 std::unique_ptr<base::Value> child =
483 FromV8ValueImpl(state, child_v8, isolate); 483 FromV8ValueImpl(state, child_v8, isolate);
484 if (child) 484 if (child)
485 result->Append(std::move(child)); 485 result->Append(std::move(child));
486 else 486 else
487 // JSON.stringify puts null in places where values don't serialize, for 487 // JSON.stringify puts null in places where values don't serialize, for
488 // example undefined and functions. Emulate that behavior. 488 // example undefined and functions. Emulate that behavior.
489 result->Append(base::Value::CreateNullValue()); 489 result->Append(base::MakeUnique<base::Value>());
490 } 490 }
491 return std::move(result); 491 return std::move(result);
492 } 492 }
493 493
494 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8ArrayBuffer( 494 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8ArrayBuffer(
495 v8::Local<v8::Object> val, 495 v8::Local<v8::Object> val,
496 v8::Isolate* isolate) const { 496 v8::Isolate* isolate) const {
497 if (strategy_) { 497 if (strategy_) {
498 std::unique_ptr<base::Value> out; 498 std::unique_ptr<base::Value> out;
499 if (strategy_->FromV8ArrayBuffer(val, &out, isolate)) 499 if (strategy_->FromV8ArrayBuffer(val, &out, isolate))
(...skipping 15 matching lines...) Expand all
515 return nullptr; 515 return nullptr;
516 } 516 }
517 } 517 }
518 518
519 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8Object( 519 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8Object(
520 v8::Local<v8::Object> val, 520 v8::Local<v8::Object> val,
521 FromV8ValueState* state, 521 FromV8ValueState* state,
522 v8::Isolate* isolate) const { 522 v8::Isolate* isolate) const {
523 ScopedUniquenessGuard uniqueness_guard(state, val); 523 ScopedUniquenessGuard uniqueness_guard(state, val);
524 if (!uniqueness_guard.is_valid()) 524 if (!uniqueness_guard.is_valid())
525 return base::Value::CreateNullValue(); 525 return base::MakeUnique<base::Value>();
526 526
527 std::unique_ptr<v8::Context::Scope> scope; 527 std::unique_ptr<v8::Context::Scope> scope;
528 // If val was created in a different context than our current one, change to 528 // If val was created in a different context than our current one, change to
529 // that context, but change back after val is converted. 529 // that context, but change back after val is converted.
530 if (!val->CreationContext().IsEmpty() && 530 if (!val->CreationContext().IsEmpty() &&
531 val->CreationContext() != isolate->GetCurrentContext()) 531 val->CreationContext() != isolate->GetCurrentContext())
532 scope.reset(new v8::Context::Scope(val->CreationContext())); 532 scope.reset(new v8::Context::Scope(val->CreationContext()));
533 533
534 if (strategy_) { 534 if (strategy_) {
535 // These base::Unretained's are safe, because Strategy::FromV8Value should 535 // These base::Unretained's are safe, because Strategy::FromV8Value should
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 continue; 615 continue;
616 616
617 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), 617 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()),
618 std::move(child)); 618 std::move(child));
619 } 619 }
620 620
621 return std::move(result); 621 return std::move(result);
622 } 622 }
623 623
624 } // namespace content 624 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_internals_ui.cc ('k') | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698