OLD | NEW |
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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 CHECK(!val.IsEmpty()); | 353 CHECK(!val.IsEmpty()); |
354 | 354 |
355 FromV8ValueState::Level state_level(state); | 355 FromV8ValueState::Level state_level(state); |
356 if (state->HasReachedMaxRecursionDepth()) | 356 if (state->HasReachedMaxRecursionDepth()) |
357 return nullptr; | 357 return nullptr; |
358 | 358 |
359 if (val->IsNull()) | 359 if (val->IsNull()) |
360 return base::Value::CreateNullValue(); | 360 return base::Value::CreateNullValue(); |
361 | 361 |
362 if (val->IsBoolean()) | 362 if (val->IsBoolean()) |
363 return base::MakeUnique<base::FundamentalValue>( | 363 return base::MakeUnique<base::Value>( |
364 val->ToBoolean(isolate)->Value()); | 364 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 |
372 if (val->IsInt32()) | 372 if (val->IsInt32()) |
373 return base::MakeUnique<base::FundamentalValue>( | 373 return base::MakeUnique<base::Value>( |
374 val->ToInt32(isolate)->Value()); | 374 val->ToInt32(isolate)->Value()); |
375 | 375 |
376 if (val->IsNumber()) { | 376 if (val->IsNumber()) { |
377 double val_as_double = val.As<v8::Number>()->Value(); | 377 double val_as_double = val.As<v8::Number>()->Value(); |
378 if (!std::isfinite(val_as_double)) | 378 if (!std::isfinite(val_as_double)) |
379 return nullptr; | 379 return nullptr; |
380 return base::MakeUnique<base::FundamentalValue>(val_as_double); | 380 return base::MakeUnique<base::Value>(val_as_double); |
381 } | 381 } |
382 | 382 |
383 if (val->IsString()) { | 383 if (val->IsString()) { |
384 v8::String::Utf8Value utf8(val); | 384 v8::String::Utf8Value utf8(val); |
385 return base::MakeUnique<base::StringValue>( | 385 return base::MakeUnique<base::StringValue>( |
386 std::string(*utf8, utf8.length())); | 386 std::string(*utf8, utf8.length())); |
387 } | 387 } |
388 | 388 |
389 if (val->IsUndefined()) { | 389 if (val->IsUndefined()) { |
390 if (strategy_) { | 390 if (strategy_) { |
391 std::unique_ptr<base::Value> out; | 391 std::unique_ptr<base::Value> out; |
392 if (strategy_->FromV8Undefined(&out)) | 392 if (strategy_->FromV8Undefined(&out)) |
393 return out; | 393 return out; |
394 } | 394 } |
395 // JSON.stringify ignores undefined. | 395 // JSON.stringify ignores undefined. |
396 return nullptr; | 396 return nullptr; |
397 } | 397 } |
398 | 398 |
399 if (val->IsDate()) { | 399 if (val->IsDate()) { |
400 if (!date_allowed_) | 400 if (!date_allowed_) |
401 // JSON.stringify would convert this to a string, but an object is more | 401 // JSON.stringify would convert this to a string, but an object is more |
402 // consistent within this class. | 402 // consistent within this class. |
403 return FromV8Object(val->ToObject(isolate), state, isolate); | 403 return FromV8Object(val->ToObject(isolate), state, isolate); |
404 v8::Date* date = v8::Date::Cast(*val); | 404 v8::Date* date = v8::Date::Cast(*val); |
405 return base::MakeUnique<base::FundamentalValue>(date->ValueOf() / 1000.0); | 405 return base::MakeUnique<base::Value>(date->ValueOf() / 1000.0); |
406 } | 406 } |
407 | 407 |
408 if (val->IsRegExp()) { | 408 if (val->IsRegExp()) { |
409 if (!reg_exp_allowed_) | 409 if (!reg_exp_allowed_) |
410 // JSON.stringify converts to an object. | 410 // JSON.stringify converts to an object. |
411 return FromV8Object(val.As<v8::Object>(), state, isolate); | 411 return FromV8Object(val.As<v8::Object>(), state, isolate); |
412 return base::MakeUnique<base::StringValue>(*v8::String::Utf8Value(val)); | 412 return base::MakeUnique<base::StringValue>(*v8::String::Utf8Value(val)); |
413 } | 413 } |
414 | 414 |
415 // v8::Value doesn't have a ToArray() method for some reason. | 415 // v8::Value doesn't have a ToArray() method for some reason. |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 continue; | 619 continue; |
620 | 620 |
621 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 621 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
622 std::move(child)); | 622 std::move(child)); |
623 } | 623 } |
624 | 624 |
625 return std::move(result); | 625 return std::move(result); |
626 } | 626 } |
627 | 627 |
628 } // namespace content | 628 } // namespace content |
OLD | NEW |