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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 v8::Local<v8::Context>::New(isolate_, context_); | 807 v8::Local<v8::Context>::New(isolate_, context_); |
808 v8::Context::Scope context_scope(context); | 808 v8::Context::Scope context_scope(context); |
809 V8ValueConverterImpl converter; | 809 V8ValueConverterImpl converter; |
810 | 810 |
811 // Create a recursive array. | 811 // Create a recursive array. |
812 v8::Local<v8::Array> recursive_array(v8::Array::New(isolate_, 1)); | 812 v8::Local<v8::Array> recursive_array(v8::Array::New(isolate_, 1)); |
813 recursive_array->Set(0, recursive_array); | 813 recursive_array->Set(0, recursive_array); |
814 | 814 |
815 // The first repetition should be trimmed and replaced by a null value. | 815 // The first repetition should be trimmed and replaced by a null value. |
816 base::ListValue expected_list; | 816 base::ListValue expected_list; |
817 expected_list.Append(base::Value::CreateNullValue()); | 817 expected_list.Append(base::MakeUnique<base::Value>()); |
818 | 818 |
819 // The actual result. | 819 // The actual result. |
820 std::unique_ptr<base::Value> actual_list( | 820 std::unique_ptr<base::Value> actual_list( |
821 converter.FromV8Value(recursive_array, context)); | 821 converter.FromV8Value(recursive_array, context)); |
822 ASSERT_TRUE(actual_list.get()); | 822 ASSERT_TRUE(actual_list.get()); |
823 | 823 |
824 EXPECT_TRUE(expected_list.Equals(actual_list.get())); | 824 EXPECT_TRUE(expected_list.Equals(actual_list.get())); |
825 | 825 |
826 // Now create a recursive object | 826 // Now create a recursive object |
827 const std::string key("key"); | 827 const std::string key("key"); |
828 v8::Local<v8::Object> recursive_object(v8::Object::New(isolate_)); | 828 v8::Local<v8::Object> recursive_object(v8::Object::New(isolate_)); |
829 v8::TryCatch try_catch(isolate_); | 829 v8::TryCatch try_catch(isolate_); |
830 recursive_object->Set( | 830 recursive_object->Set( |
831 v8::String::NewFromUtf8( | 831 v8::String::NewFromUtf8( |
832 isolate_, key.c_str(), v8::String::kNormalString, key.length()), | 832 isolate_, key.c_str(), v8::String::kNormalString, key.length()), |
833 recursive_object); | 833 recursive_object); |
834 ASSERT_FALSE(try_catch.HasCaught()); | 834 ASSERT_FALSE(try_catch.HasCaught()); |
835 | 835 |
836 // The first repetition should be trimmed and replaced by a null value. | 836 // The first repetition should be trimmed and replaced by a null value. |
837 base::DictionaryValue expected_dictionary; | 837 base::DictionaryValue expected_dictionary; |
838 expected_dictionary.Set(key, base::Value::CreateNullValue()); | 838 expected_dictionary.Set(key, base::MakeUnique<base::Value>()); |
839 | 839 |
840 // The actual result. | 840 // The actual result. |
841 std::unique_ptr<base::Value> actual_dictionary( | 841 std::unique_ptr<base::Value> actual_dictionary( |
842 converter.FromV8Value(recursive_object, context)); | 842 converter.FromV8Value(recursive_object, context)); |
843 ASSERT_TRUE(actual_dictionary.get()); | 843 ASSERT_TRUE(actual_dictionary.get()); |
844 | 844 |
845 EXPECT_TRUE(expected_dictionary.Equals(actual_dictionary.get())); | 845 EXPECT_TRUE(expected_dictionary.Equals(actual_dictionary.get())); |
846 } | 846 } |
847 | 847 |
848 // Tests that reused object values with no cycles do not get nullified. | 848 // Tests that reused object values with no cycles do not get nullified. |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 EXPECT_TRUE( | 1172 EXPECT_TRUE( |
1173 base::Value::Equals(reference_number_value.get(), number_value.get())); | 1173 base::Value::Equals(reference_number_value.get(), number_value.get())); |
1174 | 1174 |
1175 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); | 1175 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); |
1176 std::unique_ptr<base::Value> undefined_value( | 1176 std::unique_ptr<base::Value> undefined_value( |
1177 converter.FromV8Value(undefined, context)); | 1177 converter.FromV8Value(undefined, context)); |
1178 EXPECT_FALSE(undefined_value); | 1178 EXPECT_FALSE(undefined_value); |
1179 } | 1179 } |
1180 | 1180 |
1181 } // namespace content | 1181 } // namespace content |
OLD | NEW |