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

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

Issue 2666093002: Remove base::FundamentalValue (Closed)
Patch Set: Rebase Created 3 years, 9 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::Value::CreateNullValue();
362 362
363 if (val->IsBoolean()) 363 if (val->IsBoolean())
364 return base::MakeUnique<base::FundamentalValue>( 364 return base::MakeUnique<base::Value>(val->ToBoolean(isolate)->Value());
365 val->ToBoolean(isolate)->Value());
366 365
367 if (val->IsNumber() && strategy_) { 366 if (val->IsNumber() && strategy_) {
368 std::unique_ptr<base::Value> out; 367 std::unique_ptr<base::Value> out;
369 if (strategy_->FromV8Number(val.As<v8::Number>(), &out)) 368 if (strategy_->FromV8Number(val.As<v8::Number>(), &out))
370 return out; 369 return out;
371 } 370 }
372 371
373 if (val->IsInt32()) 372 if (val->IsInt32())
374 return base::MakeUnique<base::FundamentalValue>( 373 return base::MakeUnique<base::Value>(val->ToInt32(isolate)->Value());
375 val->ToInt32(isolate)->Value());
376 374
377 if (val->IsNumber()) { 375 if (val->IsNumber()) {
378 double val_as_double = val.As<v8::Number>()->Value(); 376 double val_as_double = val.As<v8::Number>()->Value();
379 if (!std::isfinite(val_as_double)) 377 if (!std::isfinite(val_as_double))
380 return nullptr; 378 return nullptr;
381 // Normally, this would be an integer, and fall into IsInt32(). But if the 379 // Normally, this would be an integer, and fall into IsInt32(). But if the
382 // value is -0, it's treated internally as a double. Consumers are allowed 380 // value is -0, it's treated internally as a double. Consumers are allowed
383 // to ignore this esoterica and treat it as an integer. 381 // to ignore this esoterica and treat it as an integer.
384 if (convert_negative_zero_to_int_ && val_as_double == 0.0) 382 if (convert_negative_zero_to_int_ && val_as_double == 0.0)
385 return base::MakeUnique<base::FundamentalValue>(0); 383 return base::MakeUnique<base::Value>(0);
386 return base::MakeUnique<base::FundamentalValue>(val_as_double); 384 return base::MakeUnique<base::Value>(val_as_double);
387 } 385 }
388 386
389 if (val->IsString()) { 387 if (val->IsString()) {
390 v8::String::Utf8Value utf8(val); 388 v8::String::Utf8Value utf8(val);
391 return base::MakeUnique<base::StringValue>( 389 return base::MakeUnique<base::StringValue>(
392 std::string(*utf8, utf8.length())); 390 std::string(*utf8, utf8.length()));
393 } 391 }
394 392
395 if (val->IsUndefined()) { 393 if (val->IsUndefined()) {
396 if (strategy_) { 394 if (strategy_) {
397 std::unique_ptr<base::Value> out; 395 std::unique_ptr<base::Value> out;
398 if (strategy_->FromV8Undefined(&out)) 396 if (strategy_->FromV8Undefined(&out))
399 return out; 397 return out;
400 } 398 }
401 // JSON.stringify ignores undefined. 399 // JSON.stringify ignores undefined.
402 return nullptr; 400 return nullptr;
403 } 401 }
404 402
405 if (val->IsDate()) { 403 if (val->IsDate()) {
406 if (!date_allowed_) 404 if (!date_allowed_)
407 // JSON.stringify would convert this to a string, but an object is more 405 // JSON.stringify would convert this to a string, but an object is more
408 // consistent within this class. 406 // consistent within this class.
409 return FromV8Object(val->ToObject(isolate), state, isolate); 407 return FromV8Object(val->ToObject(isolate), state, isolate);
410 v8::Date* date = v8::Date::Cast(*val); 408 v8::Date* date = v8::Date::Cast(*val);
411 return base::MakeUnique<base::FundamentalValue>(date->ValueOf() / 1000.0); 409 return base::MakeUnique<base::Value>(date->ValueOf() / 1000.0);
412 } 410 }
413 411
414 if (val->IsRegExp()) { 412 if (val->IsRegExp()) {
415 if (!reg_exp_allowed_) 413 if (!reg_exp_allowed_)
416 // JSON.stringify converts to an object. 414 // JSON.stringify converts to an object.
417 return FromV8Object(val.As<v8::Object>(), state, isolate); 415 return FromV8Object(val.As<v8::Object>(), state, isolate);
418 return base::MakeUnique<base::StringValue>(*v8::String::Utf8Value(val)); 416 return base::MakeUnique<base::StringValue>(*v8::String::Utf8Value(val));
419 } 417 }
420 418
421 // v8::Value doesn't have a ToArray() method for some reason. 419 // v8::Value doesn't have a ToArray() method for some reason.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 continue; 616 continue;
619 617
620 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), 618 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()),
621 std::move(child)); 619 std::move(child));
622 } 620 }
623 621
624 return std::move(result); 622 return std::move(result);
625 } 623 }
626 624
627 } // namespace content 625 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/web_ui_message_handler.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