Changeset 261818 in webkit
- Timestamp:
- May 18, 2020 10:16:16 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r261764 r261818 1 2020-05-18 Darin Adler <darin@apple.com> 2 3 Add iterator checking to ListHashSet 4 https://bugs.webkit.org/show_bug.cgi?id=211669 5 6 Reviewed by Anders Carlsson. 7 8 HashSet and HashMap have iterator checking in debug builds. 9 Add similar checking to ListHashSet, controlled by the same 10 macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the 11 implementation simple. 12 13 * wtf/Forward.h: Update to add a second parameter to WeakPtr. 14 Also rearranged and tweaked the file a bug. 15 16 * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive 17 from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to 18 ListHashSetConstIterator, and assert their values at the appropriate 19 times so we will get a breakpoint or crash. 20 21 * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. 22 23 * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and 24 WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because 25 using them violated the C++ one-definition rule. Replaced with 26 a Counter argument, which defaults to EmptyCounter, which is inlines 27 that do nothing. This required some updates to the classes and 28 functions to make them work with a second argument. 29 1 30 2020-05-15 Alex Christensen <achristensen@webkit.org> 2 31 -
trunk/Source/WTF/wtf/Forward.h
r261013 r261818 1 1 /* 2 * Copyright (C) 2006-20 18Apple Inc. All rights reserved.2 * Copyright (C) 2006-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 48 48 class WallTime; 49 49 50 struct AnyThreadsAccessTraits; 51 struct EmptyCounter; 50 52 struct FastMalloc; 53 struct MainThreadAccessTraits; 54 51 55 #if ENABLE(MALLOC_HEAP_BREAKDOWN) 52 56 struct VectorMalloc; … … 55 59 #endif 56 60 57 struct AnyThreadsAccessTraits;58 struct MainThreadAccessTraits; 61 template<typename> struct DumbPtrTraits; 62 59 63 template<typename> class CompletionHandler; 60 template<typename T> struct DumbPtrTraits;61 template<typename T> struct DumbValueTraits;62 64 template<typename> class Function; 63 65 template<typename, typename = AnyThreadsAccessTraits> class LazyNeverDestroyed; … … 65 67 template<typename> class OptionSet; 66 68 template<typename> class Optional; 67 template<typename T> class Packed;69 template<typename> class Packed; 68 70 template<typename T, size_t = alignof(T)> class PackedAlignedPtr; 69 71 template<typename T, typename = DumbPtrTraits<T>> class Ref; … … 71 73 template<typename> class StringBuffer; 72 74 template<typename, typename = void> class StringTypeAdapter; 73 template<typename T> class UniqueRef; 74 template<typename T> class WeakPtr; 75 template<typename> class UniqueRef; 76 template<typename...> class Variant; 77 template<typename, size_t = 0, typename = CrashOnOverflow, size_t = 16, typename Malloc = VectorMalloc> class Vector; 78 template<typename, typename = EmptyCounter> class WeakPtr; 75 79 76 80 template<typename> struct DefaultHash { using Hash = void; }; 81 template<typename> struct DumbValueTraits; 82 template<typename> struct EnumTraits; 83 template<typename E, E...> struct EnumValues; 77 84 template<typename> struct HashTraits; 78 85 79 template<typename> struct EnumTraits;80 template<typename E, E...> struct EnumValues;81 82 template<typename...> class Variant;83 template<typename, size_t = 0, typename = CrashOnOverflow, size_t = 16, typename Malloc = VectorMalloc> class Vector;84 86 template<typename Value, typename = typename DefaultHash<Value>::Hash, typename = HashTraits<Value>> class HashCountedSet; 85 87 template<typename KeyArg, typename MappedArg, typename = typename DefaultHash<KeyArg>::Hash, typename = HashTraits<KeyArg>, typename = HashTraits<MappedArg>> class HashMap; 86 88 template<typename ValueArg, typename = typename DefaultHash<ValueArg>::Hash, typename = HashTraits<ValueArg>> class HashSet; 87 88 template<size_t, typename> struct variant_alternative;89 template<ptrdiff_t, typename...> struct __indexed_type;90 template<ptrdiff_t _Index, typename... _Types> constexpr typename __indexed_type<_Index, _Types...>::__type const& get(Variant<_Types...> const&);91 89 92 90 } -
trunk/Source/WTF/wtf/ListHashSet.h
r261486 r261818 24 24 #include <wtf/HashSet.h> 25 25 26 #if CHECK_HASHTABLE_ITERATORS 27 #include <wtf/WeakPtr.h> 28 #endif 29 26 30 namespace WTF { 27 31 … … 46 50 template<typename HashArg> struct ListHashSetTranslator; 47 51 48 template<typename ValueArg, typename HashArg = typename DefaultHash<ValueArg>::Hash> class ListHashSet final { 52 template<typename ValueArg, typename HashArg = typename DefaultHash<ValueArg>::Hash> class ListHashSet final 53 #if CHECK_HASHTABLE_ITERATORS 54 : public CanMakeWeakPtr<ListHashSet<ValueArg, HashArg>, WeakPtrFactoryInitialization::Eager> 55 #endif 56 { 49 57 WTF_MAKE_FAST_ALLOCATED; 50 58 private: … … 165 173 }; 166 174 167 template<typename ValueArg> struct ListHashSetNode { 168 WTF_MAKE_FAST_ALLOCATED; 169 public: 170 template<typename T> 171 ListHashSetNode(T&& value) 175 template<typename ValueArg> struct ListHashSetNode 176 #if CHECK_HASHTABLE_ITERATORS 177 : CanMakeWeakPtr<ListHashSetNode<ValueArg>, WeakPtrFactoryInitialization::Eager> 178 #endif 179 { 180 WTF_MAKE_STRUCT_FAST_ALLOCATED; 181 182 template<typename T> ListHashSetNode(T&& value) 172 183 : m_value(std::forward<T>(value)) 173 184 { … … 248 259 : m_set(set) 249 260 , m_position(position) 261 #if CHECK_HASHTABLE_ITERATORS 262 , m_weakSet(makeWeakPtr(set)) 263 , m_weakPosition(makeWeakPtr(position)) 264 #endif 250 265 { 251 266 } … … 264 279 const ValueType* get() const 265 280 { 281 #if CHECK_HASHTABLE_ITERATORS 282 ASSERT(m_weakPosition); 283 #endif 266 284 return std::addressof(m_position->m_value); 267 285 } … … 272 290 const_iterator& operator++() 273 291 { 292 #if CHECK_HASHTABLE_ITERATORS 293 ASSERT(m_weakPosition); 294 #endif 274 295 ASSERT(m_position); 275 296 m_position = m_position->m_next; 297 #if CHECK_HASHTABLE_ITERATORS 298 m_weakPosition = makeWeakPtr(m_position); 299 #endif 276 300 return *this; 277 301 } … … 281 305 const_iterator& operator--() 282 306 { 307 #if CHECK_HASHTABLE_ITERATORS 308 ASSERT(m_weakSet); 309 m_weakPosition.get(); 310 #endif 283 311 ASSERT(m_position != m_set->m_head); 284 312 if (!m_position) … … 286 314 else 287 315 m_position = m_position->m_prev; 316 #if CHECK_HASHTABLE_ITERATORS 317 m_weakPosition = makeWeakPtr(m_position); 318 #endif 288 319 return *this; 289 320 } … … 304 335 Node* node() { return m_position; } 305 336 306 const ListHashSetType* m_set; 307 Node* m_position; 337 const ListHashSetType* m_set { nullptr }; 338 Node* m_position { nullptr }; 339 #if CHECK_HASHTABLE_ITERATORS 340 WeakPtr<const ListHashSetType> m_weakSet; 341 WeakPtr<Node> m_weakPosition; 342 #endif 308 343 }; 309 344 -
trunk/Source/WTF/wtf/WeakHashSet.h
r260241 r261818 1 1 /* 2 * Copyright (C) 2017-20 19Apple Inc. All rights reserved.2 * Copyright (C) 2017-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #include <wtf/Algorithms.h> 29 29 #include <wtf/HashSet.h> 30 #include <wtf/HashTraits.h>31 30 #include <wtf/WeakPtr.h> 32 31 33 32 namespace WTF { 34 33 35 template< > struct HashTraits<Ref<WeakPtrImpl>> : RefHashTraits<WeakPtrImpl> {34 template<typename Counter> struct HashTraits<Ref<WeakPtrImpl<Counter>>> : RefHashTraits<WeakPtrImpl<Counter>> { 36 35 static constexpr bool hasIsReleasedWeakValueFunction = true; 37 static bool isReleasedWeakValue(const Ref<WeakPtrImpl >& value)36 static bool isReleasedWeakValue(const Ref<WeakPtrImpl<Counter>>& value) 38 37 { 39 38 return !value.isHashTableDeletedValue() && !value.isHashTableEmptyValue() && !value.get(); … … 41 40 }; 42 41 43 template <typename T>42 template<typename T, typename Counter = EmptyCounter> 44 43 class WeakHashSet final { 45 44 WTF_MAKE_FAST_ALLOCATED; 46 45 public: 47 typedef HashSet<Ref<WeakPtrImpl >> WeakPtrImplSet;46 typedef HashSet<Ref<WeakPtrImpl<Counter>>> WeakPtrImplSet; 48 47 typedef typename WeakPtrImplSet::AddResult AddResult; 49 48 … … 86 85 87 86 private: 88 template <typename > friend class WeakHashSet;87 template <typename, typename> friend class WeakHashSet; 89 88 90 89 typename WeakPtrImplSet::const_iterator m_position; -
trunk/Source/WTF/wtf/WeakPtr.h
r257997 r261818 1 1 /* 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved.3 * Copyright (C) 2015 , 2017 Apple Inc. All Rights Reserved.2 * Copyright (C) 2013 Google, Inc. All rights reserved. 3 * Copyright (C) 2015-2020 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 27 27 #pragma once 28 28 29 #include <wtf/MainThread.h>30 #include <wtf/Noncopyable.h>31 #include <wtf/Ref.h>32 #include <wtf/ThreadSafeRefCounted.h>33 29 #include <wtf/Threading.h> 34 30 35 31 namespace WTF { 36 32 37 // Testing interface for TestWebKitAPI 38 #ifndef DID_CREATE_WEAK_PTR_IMPL 39 #define DID_CREATE_WEAK_PTR_IMPL(p) 40 #endif 41 #ifndef WILL_DESTROY_WEAK_PTR_IMPL 42 #define WILL_DESTROY_WEAK_PTR_IMPL(p) 43 #endif 44 45 template<typename> class WeakHashSet; 46 template<typename> class WeakPtr; 47 template<typename> class WeakPtrFactory; 48 49 class WeakPtrImpl : public ThreadSafeRefCounted<WeakPtrImpl> { 33 template<typename, typename> class WeakHashSet; 34 template<typename, typename> class WeakPtrFactory; 35 36 struct EmptyCounter { 37 static void increment() { } 38 static void decrement() { } 39 }; 40 41 template<typename Counter = EmptyCounter> class WeakPtrImpl : public ThreadSafeRefCounted<WeakPtrImpl<Counter>> { 50 42 WTF_MAKE_NONCOPYABLE(WeakPtrImpl); 51 43 WTF_MAKE_FAST_ALLOCATED; … … 58 50 ~WeakPtrImpl() 59 51 { 60 WILL_DESTROY_WEAK_PTR_IMPL(m_ptr);52 Counter::decrement(); 61 53 } 62 54 … … 80 72 #endif 81 73 { 82 DID_CREATE_WEAK_PTR_IMPL(ptr);74 Counter::increment(); 83 75 } 84 76 … … 89 81 }; 90 82 91 template<typename T> 92 class WeakPtr { 83 template<typename T, typename Counter> class WeakPtr { 93 84 WTF_MAKE_FAST_ALLOCATED; 94 85 public: 95 86 WeakPtr() { } 96 87 WeakPtr(std::nullptr_t) { } 97 template<typename U> WeakPtr(const WeakPtr<U >&);98 template<typename U> WeakPtr(WeakPtr<U >&&);88 template<typename U> WeakPtr(const WeakPtr<U, Counter>&); 89 template<typename U> WeakPtr(WeakPtr<U, Counter>&&); 99 90 100 91 T* get() const … … 102 93 // FIXME: Our GC threads currently need to get opaque pointers from WeakPtrs and have to be special-cased. 103 94 ASSERT(!m_impl || Thread::mayBeGCThread() || m_impl->wasConstructedOnMainThread() == isMainThread()); 104 return m_impl ? static_cast<T*>(m_impl-> get<T>()) : nullptr;95 return m_impl ? static_cast<T*>(m_impl->template get<T>()) : nullptr; 105 96 } 106 97 … … 109 100 110 101 WeakPtr& operator=(std::nullptr_t) { m_impl = nullptr; return *this; } 111 template<typename U> WeakPtr& operator=(const WeakPtr<U >&);112 template<typename U> WeakPtr& operator=(WeakPtr<U >&&);102 template<typename U> WeakPtr& operator=(const WeakPtr<U, Counter>&); 103 template<typename U> WeakPtr& operator=(WeakPtr<U, Counter>&&); 113 104 114 105 T* operator->() const … … 127 118 128 119 private: 129 explicit WeakPtr(Ref<WeakPtrImpl>&& ref) : m_impl(WTFMove(ref)) { } 130 template<typename> friend class WeakHashSet; 131 template<typename> friend class WeakPtr; 132 template<typename> friend class WeakPtrFactory; 133 template<typename U> friend WeakPtr<U> makeWeakPtr(U&); 134 135 RefPtr<WeakPtrImpl> m_impl; 120 template<typename, typename> friend class WeakHashSet; 121 template<typename, typename> friend class WeakPtr; 122 template<typename, typename> friend class WeakPtrFactory; 123 124 explicit WeakPtr(Ref<WeakPtrImpl<Counter>>&& ref) 125 : m_impl(WTFMove(ref)) 126 { 127 } 128 129 RefPtr<WeakPtrImpl<Counter>> m_impl; 136 130 }; 137 131 138 132 // Note: you probably want to inherit from CanMakeWeakPtr rather than use this directly. 139 template<typename T> 140 class WeakPtrFactory { 141 WTF_MAKE_NONCOPYABLE(WeakPtrFactory<T>); 133 template<typename T, typename Counter = EmptyCounter> class WeakPtrFactory { 134 WTF_MAKE_NONCOPYABLE(WeakPtrFactory); 142 135 WTF_MAKE_FAST_ALLOCATED; 143 136 public: 137 using CounterType = Counter; 138 144 139 WeakPtrFactory() 145 140 #if ASSERT_ENABLED … … 162 157 163 158 ASSERT(m_wasConstructedOnMainThread == isMainThread()); 164 m_impl = WeakPtrImpl ::create(const_cast<T*>(&object));165 } 166 167 WeakPtr<T> createWeakPtr(T& object) const159 m_impl = WeakPtrImpl<Counter>::create(const_cast<T*>(&object)); 160 } 161 162 template<typename U> WeakPtr<U, Counter> createWeakPtr(U& object) const 168 163 { 169 164 initializeIfNeeded(object); 170 165 171 ASSERT(&object == m_impl->get<T>()); 172 return WeakPtr<T>(makeRef(*m_impl)); 173 } 174 175 WeakPtr<const T> createWeakPtr(const T& object) const 176 { 177 initializeIfNeeded(object); 178 179 ASSERT(&object == m_impl->get<T>()); 180 return WeakPtr<T>(makeRef(*m_impl)); 166 ASSERT(&object == m_impl->template get<T>()); 167 return WeakPtr<U, Counter>(makeRef(*m_impl)); 181 168 } 182 169 … … 191 178 192 179 private: 193 template<typename > friend class WeakHashSet;194 195 mutable RefPtr<WeakPtrImpl > m_impl;180 template<typename, typename> friend class WeakHashSet; 181 182 mutable RefPtr<WeakPtrImpl<Counter>> m_impl; 196 183 #if ASSERT_ENABLED 197 184 bool m_wasConstructedOnMainThread; … … 203 190 enum class WeakPtrFactoryInitialization { Lazy, Eager }; 204 191 205 template<typename T, WeakPtrFactoryInitialization initializationMode = WeakPtrFactoryInitialization::Lazy > class CanMakeWeakPtr {192 template<typename T, WeakPtrFactoryInitialization initializationMode = WeakPtrFactoryInitialization::Lazy, typename Counter = EmptyCounter> class CanMakeWeakPtr { 206 193 public: 207 194 using WeakValueType = T; 208 195 209 const WeakPtrFactory<T >& weakPtrFactory() const { return m_weakPtrFactory; }210 WeakPtrFactory<T >& weakPtrFactory() { return m_weakPtrFactory; }196 const WeakPtrFactory<T, Counter>& weakPtrFactory() const { return m_weakPtrFactory; } 197 WeakPtrFactory<T, Counter>& weakPtrFactory() { return m_weakPtrFactory; } 211 198 212 199 protected: … … 218 205 219 206 private: 220 WeakPtrFactory<T > m_weakPtrFactory;221 }; 222 223 template<typename T, typename U > inline WeakPtrImpl* weak_ptr_impl_cast(WeakPtrImpl* impl)224 { 225 static_assert(std::is_same <typename T::WeakValueType, typename U::WeakValueType>::value, "Invalid weak pointer cast");207 WeakPtrFactory<T, Counter> m_weakPtrFactory; 208 }; 209 210 template<typename T, typename U, typename Counter> inline WeakPtrImpl<Counter>* weak_ptr_impl_cast(WeakPtrImpl<Counter>* impl) 211 { 212 static_assert(std::is_same_v<typename T::WeakValueType, typename U::WeakValueType>, "Invalid weak pointer cast"); 226 213 return impl; 227 214 } 228 215 229 template<typename T > template<typename U> inline WeakPtr<T>::WeakPtr(const WeakPtr<U>& o)216 template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>::WeakPtr(const WeakPtr<U, Counter>& o) 230 217 : m_impl(weak_ptr_impl_cast<T, U>(o.m_impl.get())) 231 218 { 232 219 } 233 220 234 template<typename T > template<typename U> inline WeakPtr<T>::WeakPtr(WeakPtr<U>&& o)221 template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>::WeakPtr(WeakPtr<U, Counter>&& o) 235 222 : m_impl(adoptRef(weak_ptr_impl_cast<T, U>(o.m_impl.leakRef()))) 236 223 { 237 224 } 238 225 239 template<typename T > template<typename U> inline WeakPtr<T>& WeakPtr<T>::operator=(const WeakPtr<U>& o)226 template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>& WeakPtr<T, Counter>::operator=(const WeakPtr<U, Counter>& o) 240 227 { 241 228 m_impl = weak_ptr_impl_cast<T, U>(o.m_impl.get()); … … 243 230 } 244 231 245 template<typename T > template<typename U> inline WeakPtr<T>& WeakPtr<T>::operator=(WeakPtr<U>&& o)232 template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>& WeakPtr<T, Counter>::operator=(WeakPtr<U, Counter>&& o) 246 233 { 247 234 m_impl = adoptRef(weak_ptr_impl_cast<T, U>(o.m_impl.leakRef())); … … 249 236 } 250 237 251 template<typename T> inline WeakPtr<T>makeWeakPtr(T& object)252 { 253 return { object.weakPtrFactory().createWeakPtr(object) };254 } 255 256 template<typename T> inline WeakPtr<T> makeWeakPtr(T* ptr)238 template<typename T> inline auto makeWeakPtr(T& object) 239 { 240 return object.weakPtrFactory().template createWeakPtr<T>(object); 241 } 242 243 template<typename T> inline auto makeWeakPtr(T* ptr) -> decltype(makeWeakPtr(*ptr)) 257 244 { 258 245 if (!ptr) … … 261 248 } 262 249 263 template<typename T, typename U > inline bool operator==(const WeakPtr<T>& a, const WeakPtr<U>& b)250 template<typename T, typename U, typename Counter> inline bool operator==(const WeakPtr<T, Counter>& a, const WeakPtr<U, Counter>& b) 264 251 { 265 252 return a.get() == b.get(); 266 253 } 267 254 268 template<typename T, typename U > inline bool operator==(const WeakPtr<T>& a, U* b)255 template<typename T, typename U, typename Counter> inline bool operator==(const WeakPtr<T, Counter>& a, U* b) 269 256 { 270 257 return a.get() == b; 271 258 } 272 259 273 template<typename T, typename U > inline bool operator==(T* a, const WeakPtr<U>& b)260 template<typename T, typename U, typename Counter> inline bool operator==(T* a, const WeakPtr<U, Counter>& b) 274 261 { 275 262 return a == b.get(); 276 263 } 277 264 278 template<typename T, typename U > inline bool operator!=(const WeakPtr<T>& a, const WeakPtr<U>& b)265 template<typename T, typename U, typename Counter> inline bool operator!=(const WeakPtr<T, Counter>& a, const WeakPtr<U, Counter>& b) 279 266 { 280 267 return a.get() != b.get(); 281 268 } 282 269 283 template<typename T, typename U > inline bool operator!=(const WeakPtr<T>& a, U* b)270 template<typename T, typename U, typename Counter> inline bool operator!=(const WeakPtr<T, Counter>& a, U* b) 284 271 { 285 272 return a.get() != b; 286 273 } 287 274 288 template<typename T, typename U > inline bool operator!=(T* a, const WeakPtr<U>& b)275 template<typename T, typename U, typename Counter> inline bool operator!=(T* a, const WeakPtr<U, Counter>& b) 289 276 { 290 277 return a != b.get(); -
trunk/Source/WebCore/ChangeLog
r261810 r261818 1 2020-05-18 Darin Adler <darin@apple.com> 2 3 Add iterator checking to ListHashSet 4 https://bugs.webkit.org/show_bug.cgi?id=211669 5 6 Reviewed by Anders Carlsson. 7 8 * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call 9 makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr 10 now checks the type of the argument. It's possible we could refine it further to 11 relax this requirement, but it seems OK to include Element.h here. 12 1 13 2020-05-18 Zalan Bujtas <zalan@apple.com> 2 14 -
trunk/Source/WebCore/page/ios/ContentChangeObserver.h
r252022 r261818 30 30 #include "CSSPropertyNames.h" 31 31 #include "Document.h" 32 #include "Element.h" 32 33 #include "PlatformEvent.h" 33 34 #include "RenderStyleConstants.h" -
trunk/Tools/ChangeLog
r261816 r261818 1 2020-05-18 Darin Adler <darin@apple.com> 2 3 Add iterator checking to ListHashSet 4 https://bugs.webkit.org/show_bug.cgi?id=211669 5 6 Reviewed by Anders Carlsson. 7 8 * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL 9 and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the 10 one-definition rule. Instead, this file parameterizes the WeakPtr family of 11 class templates with a counter class. To avoid having to rewrite test code, used 12 alias templates to insert these class template into the TestWebKitAPI namespace, 13 hiding the class templates from the WTF namespace. 14 1 15 2020-05-18 Peng Liu <peng.liu6@apple.com> 2 16 -
trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp
r251263 r261818 26 26 #include "config.h" 27 27 28 #include "Test.h" 29 #include <wtf/WeakHashSet.h> 30 31 namespace TestWebKitAPI { 32 28 33 static unsigned s_baseWeakReferences = 0; 29 34 30 #define DID_CREATE_WEAK_PTR_IMPL(p) do { \ 31 ++s_baseWeakReferences; \ 32 } while (0); 33 34 #define WILL_DESTROY_WEAK_PTR_IMPL(p) do { \ 35 --s_baseWeakReferences; \ 36 } while (0); 37 38 #include "Test.h" 39 #include <wtf/HashSet.h> 40 #include <wtf/WeakHashSet.h> 41 #include <wtf/WeakPtr.h> 42 43 namespace TestWebKitAPI { 35 struct WeakPtrCounter { 36 static void increment() { ++s_baseWeakReferences; } 37 static void decrement() { --s_baseWeakReferences; } 38 }; 39 40 template<typename T> using CanMakeWeakPtr = WTF::CanMakeWeakPtr<T, WeakPtrFactoryInitialization::Lazy, WeakPtrCounter>; 41 template<typename T> using WeakHashSet = WTF::WeakHashSet<T, WeakPtrCounter>; 42 template<typename T> using WeakPtr = WTF::WeakPtr<T, WeakPtrCounter>; 43 template<typename T> using WeakPtrFactory = WTF::WeakPtrFactory<T, WeakPtrCounter>; 44 44 45 45 struct Int : public CanMakeWeakPtr<Int> { … … 74 74 } 75 75 }; 76 77 }78 79 namespace TestWebKitAPI {80 76 81 77 TEST(WTF_WeakPtr, Basic)
Note: See TracChangeset
for help on using the changeset viewer.