Changeset 261818 in webkit


Ignore:
Timestamp:
May 18, 2020 10:16:16 AM (4 years ago)
Author:
Darin Adler
Message:

Add iterator checking to ListHashSet
https://bugs.webkit.org/show_bug.cgi?id=211669

Reviewed by Anders Carlsson.

Source/WebCore:

  • page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call

makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr
now checks the type of the argument. It's possible we could refine it further to
relax this requirement, but it seems OK to include Element.h here.

Source/WTF:

HashSet and HashMap have iterator checking in debug builds.
Add similar checking to ListHashSet, controlled by the same
macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the
implementation simple.

  • wtf/Forward.h: Update to add a second parameter to WeakPtr.

Also rearranged and tweaked the file a bug.

  • wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive

from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to
ListHashSetConstIterator, and assert their values at the appropriate
times so we will get a breakpoint or crash.

  • wtf/WeakHashSet.h: Updated to add a Counter argument for testing.
  • wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and

WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because
using them violated the C++ one-definition rule. Replaced with
a Counter argument, which defaults to EmptyCounter, which is inlines
that do nothing. This required some updates to the classes and
functions to make them work with a second argument.

Tools:

  • TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL

and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the
one-definition rule. Instead, this file parameterizes the WeakPtr family of
class templates with a counter class. To avoid having to rewrite test code, used
alias templates to insert these class template into the TestWebKitAPI namespace,
hiding the class templates from the WTF namespace.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r261764 r261818  
     12020-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
    1302020-05-15  Alex Christensen  <achristensen@webkit.org>
    231
  • trunk/Source/WTF/wtf/Forward.h

    r261013 r261818  
    11/*
    2  *  Copyright (C) 2006-2018 Apple Inc. All rights reserved.
     2 *  Copyright (C) 2006-2020 Apple Inc. All rights reserved.
    33 *
    44 *  This library is free software; you can redistribute it and/or
     
    4848class WallTime;
    4949
     50struct AnyThreadsAccessTraits;
     51struct EmptyCounter;
    5052struct FastMalloc;
     53struct MainThreadAccessTraits;
     54
    5155#if ENABLE(MALLOC_HEAP_BREAKDOWN)
    5256struct VectorMalloc;
     
    5559#endif
    5660
    57 struct AnyThreadsAccessTraits;
    58 struct MainThreadAccessTraits;
     61template<typename> struct DumbPtrTraits;
     62
    5963template<typename> class CompletionHandler;
    60 template<typename T> struct DumbPtrTraits;
    61 template<typename T> struct DumbValueTraits;
    6264template<typename> class Function;
    6365template<typename, typename = AnyThreadsAccessTraits> class LazyNeverDestroyed;
     
    6567template<typename> class OptionSet;
    6668template<typename> class Optional;
    67 template<typename T> class Packed;
     69template<typename> class Packed;
    6870template<typename T, size_t = alignof(T)> class PackedAlignedPtr;
    6971template<typename T, typename = DumbPtrTraits<T>> class Ref;
     
    7173template<typename> class StringBuffer;
    7274template<typename, typename = void> class StringTypeAdapter;
    73 template<typename T> class UniqueRef;
    74 template<typename T> class WeakPtr;
     75template<typename> class UniqueRef;
     76template<typename...> class Variant;
     77template<typename, size_t = 0, typename = CrashOnOverflow, size_t = 16, typename Malloc = VectorMalloc> class Vector;
     78template<typename, typename = EmptyCounter> class WeakPtr;
    7579
    7680template<typename> struct DefaultHash { using Hash = void; };
     81template<typename> struct DumbValueTraits;
     82template<typename> struct EnumTraits;
     83template<typename E, E...> struct EnumValues;
    7784template<typename> struct HashTraits;
    7885
    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;
    8486template<typename Value, typename = typename DefaultHash<Value>::Hash, typename = HashTraits<Value>> class HashCountedSet;
    8587template<typename KeyArg, typename MappedArg, typename = typename DefaultHash<KeyArg>::Hash, typename = HashTraits<KeyArg>, typename = HashTraits<MappedArg>> class HashMap;
    8688template<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&);
    9189
    9290}
  • trunk/Source/WTF/wtf/ListHashSet.h

    r261486 r261818  
    2424#include <wtf/HashSet.h>
    2525
     26#if CHECK_HASHTABLE_ITERATORS
     27#include <wtf/WeakPtr.h>
     28#endif
     29
    2630namespace WTF {
    2731
     
    4650template<typename HashArg> struct ListHashSetTranslator;
    4751
    48 template<typename ValueArg, typename HashArg = typename DefaultHash<ValueArg>::Hash> class ListHashSet final {
     52template<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{
    4957    WTF_MAKE_FAST_ALLOCATED;
    5058private:
     
    165173};
    166174
    167 template<typename ValueArg> struct ListHashSetNode {
    168     WTF_MAKE_FAST_ALLOCATED;
    169 public:
    170     template<typename T>
    171     ListHashSetNode(T&& value)
     175template<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)
    172183        : m_value(std::forward<T>(value))
    173184    {
     
    248259        : m_set(set)
    249260        , m_position(position)
     261#if CHECK_HASHTABLE_ITERATORS
     262        , m_weakSet(makeWeakPtr(set))
     263        , m_weakPosition(makeWeakPtr(position))
     264#endif
    250265    {
    251266    }
     
    264279    const ValueType* get() const
    265280    {
     281#if CHECK_HASHTABLE_ITERATORS
     282        ASSERT(m_weakPosition);
     283#endif
    266284        return std::addressof(m_position->m_value);
    267285    }
     
    272290    const_iterator& operator++()
    273291    {
     292#if CHECK_HASHTABLE_ITERATORS
     293        ASSERT(m_weakPosition);
     294#endif
    274295        ASSERT(m_position);
    275296        m_position = m_position->m_next;
     297#if CHECK_HASHTABLE_ITERATORS
     298        m_weakPosition = makeWeakPtr(m_position);
     299#endif
    276300        return *this;
    277301    }
     
    281305    const_iterator& operator--()
    282306    {
     307#if CHECK_HASHTABLE_ITERATORS
     308        ASSERT(m_weakSet);
     309        m_weakPosition.get();
     310#endif
    283311        ASSERT(m_position != m_set->m_head);
    284312        if (!m_position)
     
    286314        else
    287315            m_position = m_position->m_prev;
     316#if CHECK_HASHTABLE_ITERATORS
     317        m_weakPosition = makeWeakPtr(m_position);
     318#endif
    288319        return *this;
    289320    }
     
    304335    Node* node() { return m_position; }
    305336
    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
    308343};
    309344
  • trunk/Source/WTF/wtf/WeakHashSet.h

    r260241 r261818  
    11/*
    2  * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828#include <wtf/Algorithms.h>
    2929#include <wtf/HashSet.h>
    30 #include <wtf/HashTraits.h>
    3130#include <wtf/WeakPtr.h>
    3231
    3332namespace WTF {
    3433
    35 template<> struct HashTraits<Ref<WeakPtrImpl>> : RefHashTraits<WeakPtrImpl> {
     34template<typename Counter> struct HashTraits<Ref<WeakPtrImpl<Counter>>> : RefHashTraits<WeakPtrImpl<Counter>> {
    3635    static constexpr bool hasIsReleasedWeakValueFunction = true;
    37     static bool isReleasedWeakValue(const Ref<WeakPtrImpl>& value)
     36    static bool isReleasedWeakValue(const Ref<WeakPtrImpl<Counter>>& value)
    3837    {
    3938        return !value.isHashTableDeletedValue() && !value.isHashTableEmptyValue() && !value.get();
     
    4140};
    4241
    43 template <typename T>
     42template<typename T, typename Counter = EmptyCounter>
    4443class WeakHashSet final {
    4544    WTF_MAKE_FAST_ALLOCATED;
    4645public:
    47     typedef HashSet<Ref<WeakPtrImpl>> WeakPtrImplSet;
     46    typedef HashSet<Ref<WeakPtrImpl<Counter>>> WeakPtrImplSet;
    4847    typedef typename WeakPtrImplSet::AddResult AddResult;
    4948
     
    8685
    8786    private:
    88         template <typename> friend class WeakHashSet;
     87        template <typename, typename> friend class WeakHashSet;
    8988
    9089        typename WeakPtrImplSet::const_iterator m_position;
  • trunk/Source/WTF/wtf/WeakPtr.h

    r257997 r261818  
    11/*
    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.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    2727#pragma once
    2828
    29 #include <wtf/MainThread.h>
    30 #include <wtf/Noncopyable.h>
    31 #include <wtf/Ref.h>
    32 #include <wtf/ThreadSafeRefCounted.h>
    3329#include <wtf/Threading.h>
    3430
    3531namespace WTF {
    3632
    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> {
     33template<typename, typename> class WeakHashSet;
     34template<typename, typename> class WeakPtrFactory;
     35
     36struct EmptyCounter {
     37    static void increment() { }
     38    static void decrement() { }
     39};
     40
     41template<typename Counter = EmptyCounter> class WeakPtrImpl : public ThreadSafeRefCounted<WeakPtrImpl<Counter>> {
    5042    WTF_MAKE_NONCOPYABLE(WeakPtrImpl);
    5143    WTF_MAKE_FAST_ALLOCATED;
     
    5850    ~WeakPtrImpl()
    5951    {
    60         WILL_DESTROY_WEAK_PTR_IMPL(m_ptr);
     52        Counter::decrement();
    6153    }
    6254
     
    8072#endif
    8173    {
    82         DID_CREATE_WEAK_PTR_IMPL(ptr);
     74        Counter::increment();
    8375    }
    8476
     
    8981};
    9082
    91 template<typename T>
    92 class WeakPtr {
     83template<typename T, typename Counter> class WeakPtr {
    9384    WTF_MAKE_FAST_ALLOCATED;
    9485public:
    9586    WeakPtr() { }
    9687    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>&&);
    9990
    10091    T* get() const
     
    10293        // FIXME: Our GC threads currently need to get opaque pointers from WeakPtrs and have to be special-cased.
    10394        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;
    10596    }
    10697
     
    109100
    110101    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>&&);
    113104
    114105    T* operator->() const
     
    127118
    128119private:
    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;
    136130};
    137131
    138132// 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>);
     133template<typename T, typename Counter = EmptyCounter> class WeakPtrFactory {
     134    WTF_MAKE_NONCOPYABLE(WeakPtrFactory);
    142135    WTF_MAKE_FAST_ALLOCATED;
    143136public:
     137    using CounterType = Counter;
     138
    144139    WeakPtrFactory()
    145140#if ASSERT_ENABLED
     
    162157
    163158        ASSERT(m_wasConstructedOnMainThread == isMainThread());
    164         m_impl = WeakPtrImpl::create(const_cast<T*>(&object));
    165     }
    166 
    167     WeakPtr<T> createWeakPtr(T& object) const
     159        m_impl = WeakPtrImpl<Counter>::create(const_cast<T*>(&object));
     160    }
     161
     162    template<typename U> WeakPtr<U, Counter> createWeakPtr(U& object) const
    168163    {
    169164        initializeIfNeeded(object);
    170165
    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));
    181168    }
    182169
     
    191178
    192179private:
    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;
    196183#if ASSERT_ENABLED
    197184    bool m_wasConstructedOnMainThread;
     
    203190enum class WeakPtrFactoryInitialization { Lazy, Eager };
    204191
    205 template<typename T, WeakPtrFactoryInitialization initializationMode = WeakPtrFactoryInitialization::Lazy> class CanMakeWeakPtr {
     192template<typename T, WeakPtrFactoryInitialization initializationMode = WeakPtrFactoryInitialization::Lazy, typename Counter = EmptyCounter> class CanMakeWeakPtr {
    206193public:
    207194    using WeakValueType = T;
    208195
    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; }
    211198
    212199protected:
     
    218205
    219206private:
    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
     210template<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");
    226213    return impl;
    227214}
    228215
    229 template<typename T> template<typename U> inline WeakPtr<T>::WeakPtr(const WeakPtr<U>& o)
     216template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>::WeakPtr(const WeakPtr<U, Counter>& o)
    230217    : m_impl(weak_ptr_impl_cast<T, U>(o.m_impl.get()))
    231218{
    232219}
    233220
    234 template<typename T> template<typename U> inline WeakPtr<T>::WeakPtr(WeakPtr<U>&& o)
     221template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>::WeakPtr(WeakPtr<U, Counter>&& o)
    235222    : m_impl(adoptRef(weak_ptr_impl_cast<T, U>(o.m_impl.leakRef())))
    236223{
    237224}
    238225
    239 template<typename T> template<typename U> inline WeakPtr<T>& WeakPtr<T>::operator=(const WeakPtr<U>& o)
     226template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>& WeakPtr<T, Counter>::operator=(const WeakPtr<U, Counter>& o)
    240227{
    241228    m_impl = weak_ptr_impl_cast<T, U>(o.m_impl.get());
     
    243230}
    244231
    245 template<typename T> template<typename U> inline WeakPtr<T>& WeakPtr<T>::operator=(WeakPtr<U>&& o)
     232template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>& WeakPtr<T, Counter>::operator=(WeakPtr<U, Counter>&& o)
    246233{
    247234    m_impl = adoptRef(weak_ptr_impl_cast<T, U>(o.m_impl.leakRef()));
     
    249236}
    250237
    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)
     238template<typename T> inline auto makeWeakPtr(T& object)
     239{
     240    return object.weakPtrFactory().template createWeakPtr<T>(object);
     241}
     242
     243template<typename T> inline auto makeWeakPtr(T* ptr) -> decltype(makeWeakPtr(*ptr))
    257244{
    258245    if (!ptr)
     
    261248}
    262249
    263 template<typename T, typename U> inline bool operator==(const WeakPtr<T>& a, const WeakPtr<U>& b)
     250template<typename T, typename U, typename Counter> inline bool operator==(const WeakPtr<T, Counter>& a, const WeakPtr<U, Counter>& b)
    264251{
    265252    return a.get() == b.get();
    266253}
    267254
    268 template<typename T, typename U> inline bool operator==(const WeakPtr<T>& a, U* b)
     255template<typename T, typename U, typename Counter> inline bool operator==(const WeakPtr<T, Counter>& a, U* b)
    269256{
    270257    return a.get() == b;
    271258}
    272259
    273 template<typename T, typename U> inline bool operator==(T* a, const WeakPtr<U>& b)
     260template<typename T, typename U, typename Counter> inline bool operator==(T* a, const WeakPtr<U, Counter>& b)
    274261{
    275262    return a == b.get();
    276263}
    277264
    278 template<typename T, typename U> inline bool operator!=(const WeakPtr<T>& a, const WeakPtr<U>& b)
     265template<typename T, typename U, typename Counter> inline bool operator!=(const WeakPtr<T, Counter>& a, const WeakPtr<U, Counter>& b)
    279266{
    280267    return a.get() != b.get();
    281268}
    282269
    283 template<typename T, typename U> inline bool operator!=(const WeakPtr<T>& a, U* b)
     270template<typename T, typename U, typename Counter> inline bool operator!=(const WeakPtr<T, Counter>& a, U* b)
    284271{
    285272    return a.get() != b;
    286273}
    287274
    288 template<typename T, typename U> inline bool operator!=(T* a, const WeakPtr<U>& b)
     275template<typename T, typename U, typename Counter> inline bool operator!=(T* a, const WeakPtr<U, Counter>& b)
    289276{
    290277    return a != b.get();
  • trunk/Source/WebCore/ChangeLog

    r261810 r261818  
     12020-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
    1132020-05-18  Zalan Bujtas  <zalan@apple.com>
    214
  • trunk/Source/WebCore/page/ios/ContentChangeObserver.h

    r252022 r261818  
    3030#include "CSSPropertyNames.h"
    3131#include "Document.h"
     32#include "Element.h"
    3233#include "PlatformEvent.h"
    3334#include "RenderStyleConstants.h"
  • trunk/Tools/ChangeLog

    r261816 r261818  
     12020-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
    1152020-05-18  Peng Liu  <peng.liu6@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp

    r251263 r261818  
    2626#include "config.h"
    2727
     28#include "Test.h"
     29#include <wtf/WeakHashSet.h>
     30
     31namespace TestWebKitAPI {
     32
    2833static unsigned s_baseWeakReferences = 0;
    2934
    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 {
     35struct WeakPtrCounter {
     36    static void increment() { ++s_baseWeakReferences; }
     37    static void decrement() { --s_baseWeakReferences; }
     38};
     39
     40template<typename T> using CanMakeWeakPtr = WTF::CanMakeWeakPtr<T, WeakPtrFactoryInitialization::Lazy, WeakPtrCounter>;
     41template<typename T> using WeakHashSet = WTF::WeakHashSet<T, WeakPtrCounter>;
     42template<typename T> using WeakPtr = WTF::WeakPtr<T, WeakPtrCounter>;
     43template<typename T> using WeakPtrFactory = WTF::WeakPtrFactory<T, WeakPtrCounter>;
    4444
    4545struct Int : public CanMakeWeakPtr<Int> {
     
    7474    }
    7575};
    76 
    77 }
    78 
    79 namespace TestWebKitAPI {
    8076
    8177TEST(WTF_WeakPtr, Basic)
Note: See TracChangeset for help on using the changeset viewer.