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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/TraceWrapperMember.h

Issue 2567463003: [wrapper-tracing] Fix write barrier in copy ctor (Closed)
Patch Set: Fix swap for TraceWrapperMember Created 4 years 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 #ifndef TraceWrapperMember_h 5 #ifndef TraceWrapperMember_h
6 #define TraceWrapperMember_h 6 #define TraceWrapperMember_h
7 7
8 #include "bindings/core/v8/ScriptWrappableVisitor.h" 8 #include "bindings/core/v8/ScriptWrappableVisitor.h"
9 #include "platform/heap/HeapAllocator.h" 9 #include "platform/heap/HeapAllocator.h"
10 10
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 TraceWrapperMember(WTF::HashTableDeletedValueType x) 33 TraceWrapperMember(WTF::HashTableDeletedValueType x)
34 : Member<T>(x), m_parent(nullptr) {} 34 : Member<T>(x), m_parent(nullptr) {}
35 35
36 /** 36 /**
37 * Copying a TraceWrapperMember means that its backpointer will also be 37 * Copying a TraceWrapperMember means that its backpointer will also be
38 * copied. 38 * copied.
39 */ 39 */
40 TraceWrapperMember(const TraceWrapperMember& other) { *this = other; } 40 TraceWrapperMember(const TraceWrapperMember& other) { *this = other; }
41 41
42 template <typename U> 42 TraceWrapperMember& operator=(const TraceWrapperMember& other) {
43 TraceWrapperMember& operator=(const TraceWrapperMember<U>& other) {
44 DCHECK(other.m_parent); 43 DCHECK(other.m_parent);
45 m_parent = other.m_parent; 44 m_parent = other.m_parent;
46 Member<T>::operator=(other); 45 Member<T>::operator=(other);
47 ScriptWrappableVisitor::writeBarrier(m_parent, other); 46 ScriptWrappableVisitor::writeBarrier(m_parent, other);
48 return *this; 47 return *this;
49 } 48 }
50 49
51 template <typename U> 50 TraceWrapperMember& operator=(const Member<T>& other) {
52 TraceWrapperMember& operator=(const Member<U>& other) {
53 DCHECK(!traceWrapperMemberIsNotInitialized()); 51 DCHECK(!traceWrapperMemberIsNotInitialized());
54 Member<T>::operator=(other); 52 Member<T>::operator=(other);
55 ScriptWrappableVisitor::writeBarrier(m_parent, other); 53 ScriptWrappableVisitor::writeBarrier(m_parent, other);
56 return *this; 54 return *this;
57 } 55 }
58 56
59 template <typename U> 57 TraceWrapperMember& operator=(T* other) {
60 TraceWrapperMember& operator=(U* other) {
61 DCHECK(!traceWrapperMemberIsNotInitialized()); 58 DCHECK(!traceWrapperMemberIsNotInitialized());
62 Member<T>::operator=(other); 59 Member<T>::operator=(other);
63 ScriptWrappableVisitor::writeBarrier(m_parent, other); 60 ScriptWrappableVisitor::writeBarrier(m_parent, other);
64 return *this; 61 return *this;
65 } 62 }
66 63
67 TraceWrapperMember& operator=(std::nullptr_t) { 64 TraceWrapperMember& operator=(std::nullptr_t) {
68 // No need for a write barrier when assigning nullptr. 65 // No need for a write barrier when assigning nullptr.
69 Member<T>::operator=(nullptr); 66 Member<T>::operator=(nullptr);
70 return *this; 67 return *this;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 * TraceWrapperMember contains ownership information which is not copyable 111 * TraceWrapperMember contains ownership information which is not copyable
115 * but has to be explicitly specified. 112 * but has to be explicitly specified.
116 */ 113 */
117 template <typename T> 114 template <typename T>
118 void swap(HeapVector<TraceWrapperMember<T>>& a, 115 void swap(HeapVector<TraceWrapperMember<T>>& a,
119 HeapVector<Member<T>>& b, 116 HeapVector<Member<T>>& b,
120 void* parentForA) { 117 void* parentForA) {
121 HeapVector<TraceWrapperMember<T>> temp; 118 HeapVector<TraceWrapperMember<T>> temp;
122 temp.reserveCapacity(a.size()); 119 temp.reserveCapacity(a.size());
123 for (auto item : a) { 120 for (auto item : a) {
124 temp.push_back(TraceWrapperMember<T>(nullptr, item.get())); 121 temp.push_back(TraceWrapperMember<T>(item.parent(), item.get()));
125 } 122 }
126 a.clear(); 123 a.clear();
127 a.reserveCapacity(b.size()); 124 a.reserveCapacity(b.size());
128 for (auto item : b) { 125 for (auto item : b) {
129 a.push_back(TraceWrapperMember<T>(parentForA, item.get())); 126 a.push_back(TraceWrapperMember<T>(parentForA, item.get()));
130 } 127 }
131 b.clear(); 128 b.clear();
132 b.reserveCapacity(temp.size()); 129 b.reserveCapacity(temp.size());
133 for (auto item : temp) { 130 for (auto item : temp) {
134 b.push_back(item.get()); 131 b.push_back(item.get());
135 } 132 }
136 } 133 }
137 134
138 } // namespace blink 135 } // namespace blink
139 136
140 #endif // TraceWrapperMember_h 137 #endif // TraceWrapperMember_h
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