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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/TraceWrapperMemberTest.cpp

Issue 2788833002: TraceWrapperMember crashes when used as a value type of HeapHashMap
Patch Set: Created 3 years, 8 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 | « no previous file | 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "bindings/core/v8/TraceWrapperMember.h" 5 #include "bindings/core/v8/TraceWrapperMember.h"
6 6
7 #include "core/testing/DeathAwareScriptWrappable.h" 7 #include "core/testing/DeathAwareScriptWrappable.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 using Wrapper = TraceWrapperMember<DeathAwareScriptWrappable>;
13
12 TEST(TraceWrapperMemberTest, HeapVectorSwap) { 14 TEST(TraceWrapperMemberTest, HeapVectorSwap) {
13 typedef TraceWrapperMember<DeathAwareScriptWrappable> Wrapper;
14
15 HeapVector<Wrapper> vector1; 15 HeapVector<Wrapper> vector1;
16 DeathAwareScriptWrappable* parent1 = DeathAwareScriptWrappable::create(); 16 DeathAwareScriptWrappable* parent1 = DeathAwareScriptWrappable::create();
17 DeathAwareScriptWrappable* child1 = DeathAwareScriptWrappable::create(); 17 DeathAwareScriptWrappable* child1 = DeathAwareScriptWrappable::create();
18 vector1.push_back(Wrapper(parent1, child1)); 18 vector1.push_back(Wrapper(parent1, child1));
19 19
20 HeapVector<Wrapper> vector2; 20 HeapVector<Wrapper> vector2;
21 DeathAwareScriptWrappable* parent2 = DeathAwareScriptWrappable::create(); 21 DeathAwareScriptWrappable* parent2 = DeathAwareScriptWrappable::create();
22 DeathAwareScriptWrappable* child2 = DeathAwareScriptWrappable::create(); 22 DeathAwareScriptWrappable* child2 = DeathAwareScriptWrappable::create();
23 vector2.push_back(Wrapper(parent2, child2)); 23 vector2.push_back(Wrapper(parent2, child2));
24 24
25 swap(vector1, vector2, parent1, parent2); 25 swap(vector1, vector2, parent1, parent2);
26 EXPECT_EQ(parent1, vector1.front().parent()); 26 EXPECT_EQ(parent1, vector1.front().parent());
27 EXPECT_EQ(parent2, vector2.front().parent()); 27 EXPECT_EQ(parent2, vector2.front().parent());
28 } 28 }
29 29
30 TEST(TraceWrapperMemberTest, HeapVectorSwap2) { 30 TEST(TraceWrapperMemberTest, HeapVectorSwap2) {
31 typedef TraceWrapperMember<DeathAwareScriptWrappable> Wrapper;
32
33 HeapVector<Wrapper> vector1; 31 HeapVector<Wrapper> vector1;
34 DeathAwareScriptWrappable* parent1 = DeathAwareScriptWrappable::create(); 32 DeathAwareScriptWrappable* parent1 = DeathAwareScriptWrappable::create();
35 DeathAwareScriptWrappable* child1 = DeathAwareScriptWrappable::create(); 33 DeathAwareScriptWrappable* child1 = DeathAwareScriptWrappable::create();
36 vector1.push_back(Wrapper(parent1, child1)); 34 vector1.push_back(Wrapper(parent1, child1));
37 35
38 HeapVector<Member<DeathAwareScriptWrappable>> vector2; 36 HeapVector<Member<DeathAwareScriptWrappable>> vector2;
39 DeathAwareScriptWrappable* child2 = DeathAwareScriptWrappable::create(); 37 DeathAwareScriptWrappable* child2 = DeathAwareScriptWrappable::create();
40 vector2.push_back(child2); 38 vector2.push_back(child2);
41 39
42 swap(vector1, vector2, parent1); 40 swap(vector1, vector2, parent1);
43 EXPECT_EQ(1u, vector1.size()); 41 EXPECT_EQ(1u, vector1.size());
44 EXPECT_EQ(child2, vector1.front().get()); 42 EXPECT_EQ(child2, vector1.front().get());
45 EXPECT_EQ(parent1, vector1.front().parent()); 43 EXPECT_EQ(parent1, vector1.front().parent());
46 EXPECT_EQ(1u, vector2.size()); 44 EXPECT_EQ(1u, vector2.size());
47 EXPECT_EQ(child1, vector2.front().get()); 45 EXPECT_EQ(child1, vector2.front().get());
48 } 46 }
49 47
48 TEST(TraceWrapperMemberTest, HeapHashSet) {
49 HeapHashSet<Wrapper> set;
50 DeathAwareScriptWrappable* parent = DeathAwareScriptWrappable::create();
51
52 for (int i = 0; i < 10000; ++i) {
53 DeathAwareScriptWrappable* child = DeathAwareScriptWrappable::create();
54 set.insert(Wrapper(parent, child));
55 }
56 EXPECT_EQ(10000u, set.size());
57
58 HeapHashSet<Wrapper> set2;
59 swap(set, set2);
60 EXPECT_EQ(0u, set.size());
61 EXPECT_EQ(10000u, set2.size());
62
63 for (int i = 0; i < 10000; ++i) {
64 set2.takeAny();
65 }
66
67 EXPECT_EQ(0u, set2.size());
68 }
69
70 TEST(TraceWrapperMemberTest, HeapHashMapValue) {
71 HeapHashMap<int, Wrapper> map;
72 DeathAwareScriptWrappable* parent = DeathAwareScriptWrappable::create();
73
74 for (int i = 0; i < 10000; ++i) {
kouhei (in TOK) 2017/03/31 05:59:20 OK This was because HashMap key should never be 0.
75 DeathAwareScriptWrappable* child = DeathAwareScriptWrappable::create();
76 map.insert(i, Wrapper(parent, child));
77 }
78 EXPECT_EQ(10000u, map.size());
79
80 for (int i = 0; i < 10000; ++i) {
81 map.take(i);
82 }
83
84 EXPECT_EQ(0u, map.size());
85 }
86
50 } // namespace blink 87 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698