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

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

Issue 1939233002: Properly detect cycles in V8ValueConverter, current impl is too strict. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from asargent@ Created 4 years, 7 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
« no previous file with comments | « content/child/v8_value_converter_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 expected_dictionary.Set(key, base::Value::CreateNullValue()); 678 expected_dictionary.Set(key, base::Value::CreateNullValue());
679 679
680 // The actual result. 680 // The actual result.
681 std::unique_ptr<base::Value> actual_dictionary( 681 std::unique_ptr<base::Value> actual_dictionary(
682 converter.FromV8Value(recursive_object, context)); 682 converter.FromV8Value(recursive_object, context));
683 ASSERT_TRUE(actual_dictionary.get()); 683 ASSERT_TRUE(actual_dictionary.get());
684 684
685 EXPECT_TRUE(expected_dictionary.Equals(actual_dictionary.get())); 685 EXPECT_TRUE(expected_dictionary.Equals(actual_dictionary.get()));
686 } 686 }
687 687
688 // Tests that reused object values with no cycles do not get nullified.
689 TEST_F(V8ValueConverterImplTest, ReuseObjects) {
690 v8::HandleScope handle_scope(isolate_);
691 v8::Local<v8::Context> context =
692 v8::Local<v8::Context>::New(isolate_, context_);
693 v8::Context::Scope context_scope(context);
694 v8::MicrotasksScope microtasks(
695 isolate_, v8::MicrotasksScope::kDoNotRunMicrotasks);
696 V8ValueConverterImpl converter;
697
698 // Object with reused values in different keys.
699 {
700 const char* source = "(function() {"
701 "var objA = {key: 'another same value'};"
702 "var obj = {one: objA, two: objA};"
703 "return obj;"
704 "})();";
705 v8::Local<v8::Script> script(
706 v8::Script::Compile(v8::String::NewFromUtf8(isolate_, source)));
707 v8::Local<v8::Object> object = script->Run().As<v8::Object>();
708 ASSERT_FALSE(object.IsEmpty());
709
710 // The actual result.
711 std::unique_ptr<base::DictionaryValue> result(
712 static_cast<base::DictionaryValue*>(
713 converter.FromV8Value(object, context)));
714 ASSERT_TRUE(result.get());
715 EXPECT_EQ(2u, result->size());
716
717 {
718 base::DictionaryValue* one_dict = nullptr;
719 const char* key1 = "one";
720 ASSERT_TRUE(result->GetDictionary(key1, &one_dict));
721 EXPECT_EQ("another same value", GetString(one_dict, "key"));
722 }
723 {
724 base::DictionaryValue* two_dict = nullptr;
725 const char* key2 = "two";
726 ASSERT_TRUE(result->GetDictionary(key2, &two_dict));
727 EXPECT_EQ("another same value", GetString(two_dict, "key"));
728 }
729 }
730
731 // Array with reused values.
732 {
733 const char* source = "(function() {"
734 "var objA = {key: 'same value'};"
735 "var arr = [objA, objA];"
736 "return arr;"
737 "})();";
738 v8::Local<v8::Script> script(
739 v8::Script::Compile(v8::String::NewFromUtf8(isolate_, source)));
740 v8::Local<v8::Array> array = script->Run().As<v8::Array>();
741 ASSERT_FALSE(array.IsEmpty());
742
743 // The actual result.
744 std::unique_ptr<base::ListValue> list_result(
745 static_cast<base::ListValue*>(converter.FromV8Value(array, context)));
746 ASSERT_TRUE(list_result.get());
747 ASSERT_EQ(2u, list_result->GetSize());
748 for (size_t i = 0; i < list_result->GetSize(); ++i) {
749 ASSERT_FALSE(IsNull(list_result.get(), i));
750 base::DictionaryValue* dict_value = nullptr;
751 ASSERT_TRUE(list_result->GetDictionary(0u, &dict_value));
752 EXPECT_EQ("same value", GetString(dict_value, "key"));
753 }
754 }
755 }
756
688 TEST_F(V8ValueConverterImplTest, MaxRecursionDepth) { 757 TEST_F(V8ValueConverterImplTest, MaxRecursionDepth) {
689 v8::HandleScope handle_scope(isolate_); 758 v8::HandleScope handle_scope(isolate_);
690 v8::Local<v8::Context> context = 759 v8::Local<v8::Context> context =
691 v8::Local<v8::Context>::New(isolate_, context_); 760 v8::Local<v8::Context>::New(isolate_, context_);
692 v8::Context::Scope context_scope(context); 761 v8::Context::Scope context_scope(context);
693 762
694 // Must larger than kMaxRecursionDepth in v8_value_converter_impl.cc. 763 // Must larger than kMaxRecursionDepth in v8_value_converter_impl.cc.
695 int kDepth = 1000; 764 int kDepth = 1000;
696 const char kKey[] = "key"; 765 const char kKey[] = "key";
697 766
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 EXPECT_TRUE( 959 EXPECT_TRUE(
891 base::Value::Equals(reference_number_value.get(), number_value.get())); 960 base::Value::Equals(reference_number_value.get(), number_value.get()));
892 961
893 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); 962 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_));
894 std::unique_ptr<base::Value> undefined_value( 963 std::unique_ptr<base::Value> undefined_value(
895 converter.FromV8Value(undefined, context)); 964 converter.FromV8Value(undefined, context));
896 EXPECT_FALSE(undefined_value); 965 EXPECT_FALSE(undefined_value);
897 } 966 }
898 967
899 } // namespace content 968 } // namespace content
OLDNEW
« no previous file with comments | « content/child/v8_value_converter_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698