| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |