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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // 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 |
380 // 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 |
381 // to ignore this esoterica and treat it as an integer. | 381 // to ignore this esoterica and treat it as an integer. |
382 if (convert_negative_zero_to_int_ && val_as_double == 0.0) | 382 if (convert_negative_zero_to_int_ && val_as_double == 0.0) |
383 return base::MakeUnique<base::Value>(0); | 383 return base::MakeUnique<base::Value>(0); |
384 return base::MakeUnique<base::Value>(val_as_double); | 384 return base::MakeUnique<base::Value>(val_as_double); |
385 } | 385 } |
386 | 386 |
387 if (val->IsString()) { | 387 if (val->IsString()) { |
388 v8::String::Utf8Value utf8(val); | 388 v8::String::Utf8Value utf8(val); |
389 return base::MakeUnique<base::StringValue>( | 389 return base::MakeUnique<base::Value>(std::string(*utf8, utf8.length())); |
390 std::string(*utf8, utf8.length())); | |
391 } | 390 } |
392 | 391 |
393 if (val->IsUndefined()) { | 392 if (val->IsUndefined()) { |
394 if (strategy_) { | 393 if (strategy_) { |
395 std::unique_ptr<base::Value> out; | 394 std::unique_ptr<base::Value> out; |
396 if (strategy_->FromV8Undefined(&out)) | 395 if (strategy_->FromV8Undefined(&out)) |
397 return out; | 396 return out; |
398 } | 397 } |
399 // JSON.stringify ignores undefined. | 398 // JSON.stringify ignores undefined. |
400 return nullptr; | 399 return nullptr; |
401 } | 400 } |
402 | 401 |
403 if (val->IsDate()) { | 402 if (val->IsDate()) { |
404 if (!date_allowed_) | 403 if (!date_allowed_) |
405 // JSON.stringify would convert this to a string, but an object is more | 404 // JSON.stringify would convert this to a string, but an object is more |
406 // consistent within this class. | 405 // consistent within this class. |
407 return FromV8Object(val->ToObject(isolate), state, isolate); | 406 return FromV8Object(val->ToObject(isolate), state, isolate); |
408 v8::Date* date = v8::Date::Cast(*val); | 407 v8::Date* date = v8::Date::Cast(*val); |
409 return base::MakeUnique<base::Value>(date->ValueOf() / 1000.0); | 408 return base::MakeUnique<base::Value>(date->ValueOf() / 1000.0); |
410 } | 409 } |
411 | 410 |
412 if (val->IsRegExp()) { | 411 if (val->IsRegExp()) { |
413 if (!reg_exp_allowed_) | 412 if (!reg_exp_allowed_) |
414 // JSON.stringify converts to an object. | 413 // JSON.stringify converts to an object. |
415 return FromV8Object(val.As<v8::Object>(), state, isolate); | 414 return FromV8Object(val.As<v8::Object>(), state, isolate); |
416 return base::MakeUnique<base::StringValue>(*v8::String::Utf8Value(val)); | 415 return base::MakeUnique<base::Value>(*v8::String::Utf8Value(val)); |
417 } | 416 } |
418 | 417 |
419 // v8::Value doesn't have a ToArray() method for some reason. | 418 // v8::Value doesn't have a ToArray() method for some reason. |
420 if (val->IsArray()) | 419 if (val->IsArray()) |
421 return FromV8Array(val.As<v8::Array>(), state, isolate); | 420 return FromV8Array(val.As<v8::Array>(), state, isolate); |
422 | 421 |
423 if (val->IsFunction()) { | 422 if (val->IsFunction()) { |
424 if (!function_allowed_) | 423 if (!function_allowed_) |
425 // JSON.stringify refuses to convert function(){}. | 424 // JSON.stringify refuses to convert function(){}. |
426 return nullptr; | 425 return nullptr; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 continue; | 615 continue; |
617 | 616 |
618 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 617 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
619 std::move(child)); | 618 std::move(child)); |
620 } | 619 } |
621 | 620 |
622 return std::move(result); | 621 return std::move(result); |
623 } | 622 } |
624 | 623 |
625 } // namespace content | 624 } // namespace content |
OLD | NEW |