⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245857 in webkit


Ignore:
Timestamp:
May 29, 2019, 11:22:00 AM (7 years ago)
Author:
ggaren@apple.com
Message:

WeakPtr breaks vtables when upcasting to base classes
https://bugs.webkit.org/show_bug.cgi?id=188799

Reviewed by Youenn Fablet.

Source/WebCore:

  • Modules/encryptedmedia/MediaKeySession.cpp:

(WebCore::MediaKeySession::MediaKeySession):

  • Modules/encryptedmedia/MediaKeySession.h: Adopted modern WeakPtr APIs.

Removed redundant WeakPtrFactory.

  • css/CSSFontFace.cpp:

(WebCore::CSSFontFace::existingWrapper):

  • css/CSSFontFace.h: Moved functions out of line to avoid #include

explosion for .get().

  • dom/ContainerNode.h:
  • dom/Document.h:
  • dom/Element.h: Moved CanMakeWeakPtr to ContainerNode because all

subclasses except for DocumentFragment were already so, and we have
code that uses WeakPtr<ContainerNode>, which, now that WeakPtr is
type-safe, is awkward to do when ContainerNode isn't CanMakeWeakPtr.

  • dom/FullscreenManager.cpp:

(WebCore::FullscreenManager::fullscreenRenderer const):

  • dom/FullscreenManager.h:

(WebCore::FullscreenManager::fullscreenRenderer const): Deleted.

  • html/FormAssociatedElement.cpp:

(WebCore::FormAssociatedElement::form const):

  • html/FormAssociatedElement.h:

(WebCore::FormAssociatedElement::form const): Deleted. Moved functions
out of line to avoid #include explosion for .get().

  • html/HTMLMediaElement.h: It takes an extra using declaration

to disambiguate multiple CanMakeWeakPtr base classes now.

  • loader/MediaResourceLoader.cpp:

(WebCore::MediaResourceLoader::requestResource): Removed redundant .get().

  • page/DOMWindowProperty.cpp:

(WebCore::DOMWindowProperty::window const):

  • page/DOMWindowProperty.h:

(WebCore::DOMWindowProperty::window const): Deleted.

  • page/FrameViewLayoutContext.cpp:

(WebCore::FrameViewLayoutContext::subtreeLayoutRoot const):

  • page/FrameViewLayoutContext.h:

(WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): Deleted.

  • page/UndoItem.cpp:

(WebCore::UndoItem::undoManager const):

  • page/UndoItem.h:

(WebCore::UndoItem::undoManager const): Deleted. Moved functions out of
line to avoid #include explosion for .get().

  • platform/ScrollView.h: It takes an extra using declaration

to disambiguate multiple CanMakeWeakPtr base classes now.

  • platform/Widget.cpp:

(WebCore::Widget::parent const):

  • platform/Widget.h:

(WebCore::Widget::parent const): Deleted. Moved functions out of line to avoid #include
explosion for .get().

  • platform/encryptedmedia/CDMInstanceSession.h: Made

CDMInstanceSessionClient CanMakeWeakPtr because we use WeakPtr<CDMInstanceSessionClient>.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:

CanMakeWeakPtr is inherited now.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:

(WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
(WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC):

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:

(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): Deleted.
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): Deleted.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:

(WebCore::CMTimebaseEffectiveRateChangedCallback):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::durationChanged):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const):

  • platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
  • platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:

(WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC):
(WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled):
(WebCore::SourceBufferPrivateAVFObjC::setCDMSession):
(WebCore::SourceBufferPrivateAVFObjC::flushVideo):
(WebCore::SourceBufferPrivateAVFObjC::enqueueSample):
(WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples):
(WebCore::SourceBufferPrivateAVFObjC::setVideoLayer):
(WebCore::SourceBufferPrivateAVFObjC::setDecompressionSession): Modernized WeakPtr API usage.

  • rendering/RenderBlockFlow.cpp:

(WebCore::RenderBlockFlow::multiColumnFlowSlowCase const):

  • rendering/RenderBlockFlow.h:

(WebCore::RenderBlockFlow::multiColumnFlow const):

  • rendering/RenderMultiColumnFlow.cpp:

(WebCore::RenderMultiColumnFlow::findColumnSpannerPlaceholder const):

  • rendering/RenderMultiColumnFlow.h:
  • rendering/RenderTable.cpp:

(WebCore::RenderTable::header const):
(WebCore::RenderTable::footer const):
(WebCore::RenderTable::firstBody const):
(WebCore::RenderTable::topSection const):

  • rendering/RenderTable.h:

(WebCore::RenderTable::header const): Deleted.
(WebCore::RenderTable::footer const): Deleted.
(WebCore::RenderTable::firstBody const): Deleted.
(WebCore::RenderTable::topSection const): Deleted. Moved functions out
of line to avoid #include explosion for .get().

Source/WebKit:

  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::networkSession):

  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
  • Shared/WebBackForwardListItem.cpp:

(WebKit::WebBackForwardListItem::suspendedPage const):

  • Shared/WebBackForwardListItem.h:

(WebKit::WebBackForwardListItem::suspendedPage const): Deleted. Moved
functions out of line to avoid #include explosion for .get().

  • UIProcess/Authentication/cocoa/SecKeyProxyStore.h:

(WebKit::SecKeyProxyStore::get const):
(WebKit::SecKeyProxyStore::weakPtrFactory const): Deleted. Adopted
CanMakeWeakPtr.

  • UIProcess/WebAuthentication/AuthenticatorManager.h:
  • UIProcess/WebProcessProxy.cpp: It takes an extra using declaration

to disambiguate multiple CanMakeWeakPtr base classes now.

(WebKit::WebProcessProxy::processPool const):

  • UIProcess/WebProcessProxy.h:

(WebKit::WebProcessProxy::processPool const): Deleted. Moved
functions out of line to avoid #include explosion for .get().

Source/WTF:

This patch switches from reinterpret_cast to static_cast when loading
from WeakReference storage.

We know which type to cast *to* because it's specified by the type of
the calling WeakPtr.

We know which type to cast *from* because it's specified by a typedef
in CanMakeWeakPtr.

(Our convention is that we store a pointer to the class that derives
from CanMakeWeakPtr. We cast from that pointer to derived pointers when
we get(). This means that #include of the derived type header is now
required in order to get() the pointer.)

  • wtf/WeakHashSet.h:

(WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Definition
is now eagerly required because WeakReference is not a template anymore.

(WTF::WeakHashSet::WeakHashSetConstIterator::get const):
(WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets):
(WTF::WeakHashSet::remove):
(WTF::WeakHashSet::contains const):
(WTF::WeakHashSet::computesEmpty const):
(WTF::WeakHashSet::hasNullReferences const):
(WTF::WeakHashSet::computeSize const):
(WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): Deleted.
Updated for new WeakReference get() API.

  • wtf/WeakPtr.h: Use a macro for TestAPI support. We can't use template

specialization because WeakReference is not a class template anymore.
(Or maybe we could have kept it working with a dummy template argument?
Felt weird, so I switched.)

(WTF::WeakReference::create):
(WTF::WeakReference::~WeakReference):
(WTF::WeakReference::get const):
(WTF::WeakReference::operator bool const):
(WTF::WeakReference::WeakReference): WeakReference is just a void* now.
It's the caller's responsibility, when creating and getting, to use
a consistent storage type. We ensure a canonical storage type using a
typedef inside CanMakeWeakPtr.

(WTF::WeakPtr::WeakPtr):
(WTF::WeakPtr::get const):
(WTF::WeakPtr::operator bool const):
(WTF::WeakPtr::operator-> const):
(WTF::WeakPtr::operator* const): Adopted new WeakReference API.

(WTF::WeakPtrFactory::createWeakPtr const): No need for reinterpret_cast.

(WTF::weak_reference_cast): This isn't required for correctness, but it's
nice to show a complier error at WeakPtr construction sites when you know
that the types won't work. Otherwise, you get compiler errors at
dereference sites, which are slightly more mysterious ways of saying that
you constructed your WeakPtr incorrectly.

(WTF::WeakPtr<T>::WeakPtr):
(WTF::=):
(WTF::makeWeakPtr):
(WTF::weak_reference_upcast): Deleted.
(WTF::weak_reference_downcast): Deleted.

Tools:

  • TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Adopt the new macro API instead

of template specialization for observing weak references.

(TestWebKitAPI::Int::Int):
(TestWebKitAPI::Int::operator int const):
(TestWebKitAPI::Int::operator== const): Use a class for integer tests
because WeakPtr doesn't naturally support pointing to non-class objects
now.

(TestWebKitAPI::Base::foo):
(TestWebKitAPI::Derived::foo): Inherit from CanMakeWeakPtr to enable
deduction of the weak pointer type.

(TestWebKitAPI::TEST): Updated to use Int.

(TestWebKitAPI::Base::weakPtrFactory const): Deleted.
(WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): Deleted.
(WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): Deleted.

Location:
trunk
Files:
53 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r245796 r245857  
     12019-05-28  Geoffrey Garen  <ggaren@apple.com>
     2
     3        WeakPtr breaks vtables when upcasting to base classes
     4        https://bugs.webkit.org/show_bug.cgi?id=188799
     5
     6        Reviewed by Youenn Fablet.
     7
     8        This patch switches from reinterpret_cast to static_cast when loading
     9        from WeakReference storage.
     10
     11        We know which type to cast *to* because it's specified by the type of
     12        the calling WeakPtr.
     13
     14        We know which type to cast *from* because it's specified by a typedef
     15        in CanMakeWeakPtr.
     16
     17        (Our convention is that we store a pointer to the class that derives
     18        from CanMakeWeakPtr. We cast from that pointer to derived pointers when
     19        we get(). This means that #include of the derived type header is now
     20        required in order to get() the pointer.)
     21
     22        * wtf/WeakHashSet.h:
     23        (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Definition
     24        is now eagerly required because WeakReference is not a template anymore.
     25
     26        (WTF::WeakHashSet::WeakHashSetConstIterator::get const):
     27        (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets):
     28        (WTF::WeakHashSet::remove):
     29        (WTF::WeakHashSet::contains const):
     30        (WTF::WeakHashSet::computesEmpty const):
     31        (WTF::WeakHashSet::hasNullReferences const):
     32        (WTF::WeakHashSet::computeSize const):
     33        (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): Deleted.
     34        Updated for new WeakReference get() API.
     35
     36        * wtf/WeakPtr.h: Use a macro for TestAPI support. We can't use template
     37        specialization because WeakReference is not a class template anymore.
     38        (Or maybe we could have kept it working with a dummy template argument?
     39        Felt weird, so I switched.)
     40
     41        (WTF::WeakReference::create):
     42        (WTF::WeakReference::~WeakReference):
     43        (WTF::WeakReference::get const):
     44        (WTF::WeakReference::operator bool const):
     45        (WTF::WeakReference::WeakReference): WeakReference is just a void* now.
     46        It's the caller's responsibility, when creating and getting, to use
     47        a consistent storage type. We ensure a canonical storage type using a
     48        typedef inside CanMakeWeakPtr.
     49
     50        (WTF::WeakPtr::WeakPtr):
     51        (WTF::WeakPtr::get const):
     52        (WTF::WeakPtr::operator bool const):
     53        (WTF::WeakPtr::operator-> const):
     54        (WTF::WeakPtr::operator* const): Adopted new WeakReference API.
     55
     56        (WTF::WeakPtrFactory::createWeakPtr const): No need for reinterpret_cast.
     57
     58        (WTF::weak_reference_cast): This isn't required for correctness, but it's
     59        nice to show a complier error at WeakPtr construction sites when you know
     60        that the types won't work. Otherwise, you get compiler errors at
     61        dereference sites, which are slightly more mysterious ways of saying that
     62        you constructed your WeakPtr incorrectly.
     63
     64        (WTF::WeakPtr<T>::WeakPtr):
     65        (WTF::=):
     66        (WTF::makeWeakPtr):
     67        (WTF::weak_reference_upcast): Deleted.
     68        (WTF::weak_reference_downcast): Deleted.
     69
    1702019-05-27  Chris Dumez  <cdumez@apple.com>
    271
  • trunk/Source/WTF/wtf/WeakHashSet.h

    r244815 r245857  
    3333namespace WTF {
    3434
     35template<> struct HashTraits<Ref<WeakReference>> : RefHashTraits<WeakReference> {
     36    static const bool hasIsReleasedWeakValueFunction = true;
     37    static bool isReleasedWeakValue(const Ref<WeakReference>& value)
     38    {
     39        return !value.isHashTableDeletedValue() && !value.isHashTableEmptyValue() && !value.get();
     40    }
     41};
     42
    3543template <typename T>
    3644class WeakHashSet {
    3745public:
    38     typedef HashSet<Ref<WeakReference<T>>> WeakReferenceSet;
     46    typedef HashSet<Ref<WeakReference>> WeakReferenceSet;
    3947
    4048    class WeakHashSetConstIterator : public std::iterator<std::forward_iterator_tag, T, std::ptrdiff_t, const T*, const T&> {
     
    4755
    4856    public:
    49         T* get() const { return m_position->get().get(); }
     57        T* get() const { return m_position->get().template get<T, typename T::WeakValueType>(); }
    5058        T& operator*() const { return *get(); }
    5159        T* operator->() const { return get(); }
     
    6169        void skipEmptyBuckets()
    6270        {
    63             while (m_position != m_endPosition && !m_position->get().get())
     71            while (m_position != m_endPosition && !get())
    6472                ++m_position;
    6573        }
     
    97105    bool remove(const U& value)
    98106    {
    99         auto* weakReference = weak_reference_downcast<T>(value.weakPtrFactory().m_ref.get());
    100         if (!weakReference)
     107        auto& weakReference = value.weakPtrFactory().m_ref;
     108        if (!weakReference || !*weakReference)
    101109            return false;
    102         return m_set.remove(weakReference);
     110        return m_set.remove(*weakReference);
    103111    }
    104112
     
    106114    bool contains(const U& value) const
    107115    {
    108         auto* weakReference = weak_reference_downcast<T>(value.weakPtrFactory().m_ref.get());
    109         if (!weakReference)
     116        auto& weakReference = value.weakPtrFactory().m_ref;
     117        if (!weakReference || !*weakReference)
    110118            return false;
    111         return m_set.contains(weakReference);
     119        return m_set.contains(*weakReference);
    112120    }
    113121
    114122    unsigned capacity() const { return m_set.capacity(); }
    115123
    116     bool computesEmpty() const
    117     {
    118         if (m_set.isEmpty())
    119             return true;
    120         for (auto& value : m_set) {
    121             if (value->get())
    122                 return false;
    123         }
    124         return true;
    125     }
     124    bool computesEmpty() const { return begin() == end(); }
    126125
    127126    bool hasNullReferences() const
    128127    {
    129         return WTF::anyOf(m_set, [] (auto& value) { return !value->get(); });
     128        return WTF::anyOf(m_set, [] (auto& value) { return !value.get(); });
    130129    }
    131130
    132131    unsigned computeSize() const
    133132    {
    134         const_cast<WeakReferenceSet&>(m_set).removeIf([] (auto& value) { return !value->get(); });
     133        const_cast<WeakReferenceSet&>(m_set).removeIf([] (auto& value) { return !value.get(); });
    135134        return m_set.size();
    136135    }
     
    146145};
    147146
    148 template<typename T> struct HashTraits<Ref<WeakReference<T>>> : RefHashTraits<WeakReference<T>> {
    149     static const bool hasIsReleasedWeakValueFunction = true;
    150     static bool isReleasedWeakValue(const Ref<WeakReference<T>>& value)
    151     {
    152         return !value.isHashTableDeletedValue() && !value.isHashTableEmptyValue() && !value.get().get();
    153     }
    154 };
    155 
    156147} // namespace WTF
    157148
  • trunk/Source/WTF/wtf/WeakPtr.h

    r243965 r245857  
    3434namespace WTF {
    3535
     36// Testing interface for TestWebKitAPI
     37#ifndef DID_CREATE_WEAK_REFERENCE
     38#define DID_CREATE_WEAK_REFERENCE(p)
     39#endif
     40#ifndef WILL_DESTROY_WEAK_REFERENCE
     41#define WILL_DESTROY_WEAK_REFERENCE(p)
     42#endif
     43
    3644template<typename> class WeakHashSet;
    3745template<typename> class WeakPtr;
     
    3947
    4048// Note: WeakReference is an implementation detail, and should not be used directly.
    41 template<typename T>
    42 class WeakReference : public ThreadSafeRefCounted<WeakReference<T>> {
    43     WTF_MAKE_NONCOPYABLE(WeakReference<T>);
     49class WeakReference : public ThreadSafeRefCounted<WeakReference> {
     50    WTF_MAKE_NONCOPYABLE(WeakReference);
    4451    WTF_MAKE_FAST_ALLOCATED;
    4552public:
    46     ~WeakReference() { } // So that we can use a template specialization for testing purposes to detect leaks.
    47 
    48     T* get() const { return m_ptr; }
     53    template<typename T> static Ref<WeakReference> create(T* ptr) { return adoptRef(*new WeakReference(ptr)); }
     54
     55    ~WeakReference()
     56    {
     57        WILL_DESTROY_WEAK_REFERENCE(m_ptr);
     58    }
     59
     60    template<typename T, typename WeakValueType> T* get() const { return static_cast<T*>(static_cast<WeakValueType*>(m_ptr)); }
     61    explicit operator bool() const { return m_ptr; }
    4962
    5063    void clear() { m_ptr = nullptr; }
    5164
    5265private:
    53     friend class WeakPtr<T>;
    54     friend class WeakPtrFactory<T>;
    55 
    56     static Ref<WeakReference<T>> create(T* ptr) { return adoptRef(*new WeakReference(ptr)); }
    57 
    58     explicit WeakReference(T* ptr)
     66    template<typename T> explicit WeakReference(T* ptr)
    5967        : m_ptr(ptr)
    6068    {
    61     }
    62 
    63     T* m_ptr;
     69        DID_CREATE_WEAK_REFERENCE(ptr);
     70    }
     71
     72    void* m_ptr;
    6473};
    6574
     
    7079    WeakPtr() { }
    7180    WeakPtr(std::nullptr_t) { }
    72     WeakPtr(Ref<WeakReference<T>>&& ref) : m_ref(std::forward<Ref<WeakReference<T>>>(ref)) { }
    7381    template<typename U> WeakPtr(const WeakPtr<U>&);
    7482    template<typename U> WeakPtr(WeakPtr<U>&&);
    7583
    76     T* get() const { return m_ref ? m_ref->get() : nullptr; }
    77     explicit operator bool() const { return m_ref && m_ref->get(); }
     84    T* get() const { return m_ref ? m_ref->template get<T, typename T::WeakValueType>() : nullptr; }
     85    explicit operator bool() const { return m_ref && *m_ref; }
    7886
    7987    WeakPtr& operator=(std::nullptr_t) { m_ref = nullptr; return *this; }
     
    8189    template<typename U> WeakPtr& operator=(WeakPtr<U>&&);
    8290
    83     T* operator->() const { return m_ref->get(); }
    84     T& operator*() const { return *m_ref->get(); }
     91    T* operator->() const { return get(); }
     92    T& operator*() const { return *get(); }
    8593
    8694    void clear() { m_ref = nullptr; }
    8795
    8896private:
     97    explicit WeakPtr(Ref<WeakReference>&& ref) : m_ref(std::move(ref)) { }
    8998    template<typename> friend class WeakHashSet;
    9099    template<typename> friend class WeakPtr;
     100    template<typename> friend class WeakPtrFactory;
    91101    template<typename U> friend WeakPtr<U> makeWeakPtr(U&);
    92102
    93     RefPtr<WeakReference<T>> m_ref;
     103    RefPtr<WeakReference> m_ref;
    94104};
    95105
     
    111121    {
    112122        if (!m_ref)
    113             m_ref = WeakReference<T>::create(&ptr);
    114         return { makeRef(*m_ref) };
     123            m_ref = WeakReference::create(&ptr);
     124        return WeakPtr<T>(makeRef(*m_ref));
    115125    }
    116126
     
    118128    {
    119129        if (!m_ref)
    120             m_ref = WeakReference<T>::create(const_cast<T*>(&ptr));
    121         return { makeRef(reinterpret_cast<WeakReference<const T>&>(*m_ref)) };
     130            m_ref = WeakReference::create(const_cast<T*>(&ptr));
     131        return WeakPtr<T>(makeRef(*m_ref));
    122132    }
    123133
     
    134144    template<typename> friend class WeakHashSet;
    135145
    136     mutable RefPtr<WeakReference<T>> m_ref;
     146    mutable RefPtr<WeakReference> m_ref;
    137147};
    138148
    139149template<typename T> class CanMakeWeakPtr {
    140150public:
     151    typedef T WeakValueType;
     152
    141153    const WeakPtrFactory<T>& weakPtrFactory() const { return m_weakFactory; }
    142154    WeakPtrFactory<T>& weakPtrFactory() { return m_weakFactory; }
     
    146158};
    147159
    148 template<typename T, typename U> inline WeakReference<T>* weak_reference_upcast(WeakReference<U>* weakReference)
    149 {
    150     static_assert(std::is_convertible<U*, T*>::value, "U* must be convertible to T*");
    151     return reinterpret_cast<WeakReference<T>*>(weakReference);
    152 }
    153 
    154 template<typename T, typename U> inline WeakReference<T>* weak_reference_downcast(WeakReference<U>* weakReference)
    155 {
    156     static_assert(std::is_convertible<T*, U*>::value, "T* must be convertible to U*");
    157     return reinterpret_cast<WeakReference<T>*>(weakReference);
     160template<typename T, typename U> inline WeakReference* weak_reference_cast(WeakReference* weakReference)
     161{
     162    UNUSED_VARIABLE(static_cast<T*>(static_cast<typename U::WeakValueType*>(nullptr))); // Verify that casting is valid.
     163    return weakReference;
    158164}
    159165
    160166template<typename T> template<typename U> inline WeakPtr<T>::WeakPtr(const WeakPtr<U>& o)
    161     : m_ref(weak_reference_upcast<T>(o.m_ref.get()))
     167    : m_ref(weak_reference_cast<T, U>(o.m_ref.get()))
    162168{
    163169}
    164170
    165171template<typename T> template<typename U> inline WeakPtr<T>::WeakPtr(WeakPtr<U>&& o)
    166     : m_ref(adoptRef(weak_reference_upcast<T>(o.m_ref.leakRef())))
     172    : m_ref(adoptRef(weak_reference_cast<T, U>(o.m_ref.leakRef())))
    167173{
    168174}
     
    170176template<typename T> template<typename U> inline WeakPtr<T>& WeakPtr<T>::operator=(const WeakPtr<U>& o)
    171177{
    172     m_ref = weak_reference_upcast<T>(o.m_ref.get());
     178    m_ref = weak_reference_cast<T, U>(o.m_ref.get());
    173179    return *this;
    174180}
     
    176182template<typename T> template<typename U> inline WeakPtr<T>& WeakPtr<T>::operator=(WeakPtr<U>&& o)
    177183{
    178     m_ref = adoptRef(weak_reference_upcast<T>(o.m_ref.leakRef()));
     184    m_ref = adoptRef(weak_reference_cast<T, U>(o.m_ref.leakRef()));
    179185    return *this;
    180186}
     
    182188template<typename T> inline WeakPtr<T> makeWeakPtr(T& ref)
    183189{
    184     return { adoptRef(*weak_reference_downcast<T>(ref.weakPtrFactory().createWeakPtr(ref).m_ref.leakRef())) };
     190    return { ref.weakPtrFactory().createWeakPtr(ref) };
    185191}
    186192
  • trunk/Source/WebCore/ChangeLog

    r245854 r245857  
     12019-05-28  Geoffrey Garen  <ggaren@apple.com>
     2
     3        WeakPtr breaks vtables when upcasting to base classes
     4        https://bugs.webkit.org/show_bug.cgi?id=188799
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * Modules/encryptedmedia/MediaKeySession.cpp:
     9        (WebCore::MediaKeySession::MediaKeySession):
     10        * Modules/encryptedmedia/MediaKeySession.h: Adopted modern WeakPtr APIs.
     11        Removed redundant WeakPtrFactory.
     12
     13        * css/CSSFontFace.cpp:
     14        (WebCore::CSSFontFace::existingWrapper):
     15        * css/CSSFontFace.h: Moved functions out of line to avoid #include
     16        explosion for .get().
     17
     18        * dom/ContainerNode.h:
     19        * dom/Document.h:
     20        * dom/Element.h: Moved CanMakeWeakPtr to ContainerNode because all
     21        subclasses except for DocumentFragment were already so, and we have
     22        code that uses WeakPtr<ContainerNode>, which, now that WeakPtr is
     23        type-safe, is awkward to do when ContainerNode isn't CanMakeWeakPtr.
     24
     25        * dom/FullscreenManager.cpp:
     26        (WebCore::FullscreenManager::fullscreenRenderer const):
     27        * dom/FullscreenManager.h:
     28        (WebCore::FullscreenManager::fullscreenRenderer const): Deleted.
     29        * html/FormAssociatedElement.cpp:
     30        (WebCore::FormAssociatedElement::form const):
     31        * html/FormAssociatedElement.h:
     32        (WebCore::FormAssociatedElement::form const): Deleted. Moved functions
     33        out of line to avoid #include explosion for .get().
     34
     35        * html/HTMLMediaElement.h: It takes an extra using declaration
     36        to disambiguate multiple CanMakeWeakPtr base classes now.
     37
     38        * loader/MediaResourceLoader.cpp:
     39        (WebCore::MediaResourceLoader::requestResource): Removed redundant .get().
     40
     41        * page/DOMWindowProperty.cpp:
     42        (WebCore::DOMWindowProperty::window const):
     43        * page/DOMWindowProperty.h:
     44        (WebCore::DOMWindowProperty::window const): Deleted.
     45        * page/FrameViewLayoutContext.cpp:
     46        (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const):
     47        * page/FrameViewLayoutContext.h:
     48        (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): Deleted.
     49        * page/UndoItem.cpp:
     50        (WebCore::UndoItem::undoManager const):
     51        * page/UndoItem.h:
     52        (WebCore::UndoItem::undoManager const): Deleted. Moved functions out of
     53        line to avoid #include explosion for .get().
     54
     55        * platform/ScrollView.h: It takes an extra using declaration
     56        to disambiguate multiple CanMakeWeakPtr base classes now.
     57
     58        * platform/Widget.cpp:
     59        (WebCore::Widget::parent const):
     60        * platform/Widget.h:
     61        (WebCore::Widget::parent const): Deleted. Moved functions out of line to avoid #include
     62        explosion for .get().
     63
     64        * platform/encryptedmedia/CDMInstanceSession.h: Made
     65        CDMInstanceSessionClient CanMakeWeakPtr because we use WeakPtr<CDMInstanceSessionClient>.
     66
     67        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
     68        CanMakeWeakPtr is inherited now.
     69
     70        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     71        (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
     72        (WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC):
     73        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
     74        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): Deleted.
     75        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): Deleted.
     76        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
     77        (WebCore::CMTimebaseEffectiveRateChangedCallback):
     78        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC):
     79        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play):
     80        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause):
     81        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance):
     82        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::durationChanged):
     83        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const):
     84        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
     85        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
     86        (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC):
     87        (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled):
     88        (WebCore::SourceBufferPrivateAVFObjC::setCDMSession):
     89        (WebCore::SourceBufferPrivateAVFObjC::flushVideo):
     90        (WebCore::SourceBufferPrivateAVFObjC::enqueueSample):
     91        (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples):
     92        (WebCore::SourceBufferPrivateAVFObjC::setVideoLayer):
     93        (WebCore::SourceBufferPrivateAVFObjC::setDecompressionSession): Modernized WeakPtr API usage.
     94
     95        * rendering/RenderBlockFlow.cpp:
     96        (WebCore::RenderBlockFlow::multiColumnFlowSlowCase const):
     97        * rendering/RenderBlockFlow.h:
     98        (WebCore::RenderBlockFlow::multiColumnFlow const):
     99        * rendering/RenderMultiColumnFlow.cpp:
     100        (WebCore::RenderMultiColumnFlow::findColumnSpannerPlaceholder const):
     101        * rendering/RenderMultiColumnFlow.h:
     102        * rendering/RenderTable.cpp:
     103        (WebCore::RenderTable::header const):
     104        (WebCore::RenderTable::footer const):
     105        (WebCore::RenderTable::firstBody const):
     106        (WebCore::RenderTable::topSection const):
     107        * rendering/RenderTable.h:
     108        (WebCore::RenderTable::header const): Deleted.
     109        (WebCore::RenderTable::footer const): Deleted.
     110        (WebCore::RenderTable::firstBody const): Deleted.
     111        (WebCore::RenderTable::topSection const): Deleted. Moved functions out
     112        of line to avoid #include explosion for .get().
     113
    11142019-05-29  Antti Koivisto  <antti@apple.com>
    2115
  • trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp

    r243887 r245857  
    9595    UNUSED_PARAM(m_uninitialized);
    9696
    97     m_instanceSession->setClient(m_cdmInstanceSessionClientWeakPtrFactory.createWeakPtr(*this));
     97    m_instanceSession->setClient(makeWeakPtr(*this));
    9898}
    9999
  • trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h

    r243887 r245857  
    5353class SharedBuffer;
    5454
    55 class MediaKeySession final : public RefCounted<MediaKeySession>, public EventTargetWithInlineData, public ActiveDOMObject, public CanMakeWeakPtr<MediaKeySession>, public CDMInstanceSessionClient {
     55class MediaKeySession final : public RefCounted<MediaKeySession>, public EventTargetWithInlineData, public ActiveDOMObject, public CDMInstanceSessionClient {
    5656    WTF_MAKE_ISO_ALLOCATED(MediaKeySession);
    5757public:
     
    121121    double m_latestDecryptTime { 0 };
    122122    Vector<std::pair<Ref<SharedBuffer>, MediaKeyStatus>> m_statuses;
    123     WeakPtrFactory<CDMInstanceSessionClient> m_cdmInstanceSessionClientWeakPtrFactory;
    124123};
    125124
  • trunk/Source/WebCore/css/CSSFontFace.cpp

    r245190 r245857  
    123123}
    124124
     125FontFace* CSSFontFace::existingWrapper()
     126{
     127    return m_wrapper.get();
     128}
     129
    125130static FontSelectionRange calculateWeightRange(CSSValue& value)
    126131{
  • trunk/Source/WebCore/css/CSSFontFace.h

    r243828 r245857  
    151151    Ref<FontFace> wrapper();
    152152    void setWrapper(FontFace&);
    153     FontFace* existingWrapper() { return m_wrapper.get(); }
     153    FontFace* existingWrapper();
    154154
    155155    struct FontLoadTiming {
  • trunk/Source/WebCore/css/parser/CSSDeferredParser.cpp

    r232613 r245857  
    4040}
    4141
     42StyleSheetContents* CSSDeferredParser::styleSheet() const
     43{
     44    return m_styleSheet.get();
     45}
     46
    4247Ref<ImmutableStyleProperties> CSSDeferredParser::parseDeclaration(const CSSParserTokenRange& range)
    4348{
  • trunk/Source/WebCore/css/parser/CSSDeferredParser.h

    r233520 r245857  
    4848
    4949    const CSSParserContext& context() const { return m_context; }
    50     StyleSheetContents* styleSheet() const { return m_styleSheet.get(); }
     50    StyleSheetContents* styleSheet() const;
    5151
    5252    Ref<ImmutableStyleProperties> parseDeclaration(const CSSParserTokenRange&);
  • trunk/Source/WebCore/dom/ContainerNode.h

    r235780 r245857  
    2626#include "CollectionType.h"
    2727#include "Node.h"
     28#include <wtf/WeakPtr.h>
    2829
    2930namespace WebCore {
     
    3637typedef Vector<Ref<Node>, initialNodeVectorSize> NodeVector;
    3738
    38 class ContainerNode : public Node {
     39class ContainerNode : public CanMakeWeakPtr<ContainerNode>, public Node {
    3940    WTF_MAKE_ISO_ALLOCATED(ContainerNode);
    4041public:
  • trunk/Source/WebCore/dom/Document.h

    r245796 r245857  
    348348    , public ScriptExecutionContext
    349349    , public FontSelectorClient
    350     , public CanMakeWeakPtr<Document>
    351350    , public FrameDestructionObserver
    352351    , public Supplementable<Document>
  • trunk/Source/WebCore/dom/Element.h

    r245642 r245857  
    7878#endif
    7979
    80 class Element : public ContainerNode , public CanMakeWeakPtr<Element> {
     80class Element : public ContainerNode {
    8181    WTF_MAKE_ISO_ALLOCATED(Element);
    8282public:
  • trunk/Source/WebCore/dom/FullscreenManager.cpp

    r244440 r245857  
    440440}
    441441
     442RenderFullScreen* FullscreenManager::fullscreenRenderer() const
     443{
     444    return m_fullscreenRenderer.get();
     445}
     446
    442447void FullscreenManager::dispatchFullscreenChangeEvents()
    443448{
  • trunk/Source/WebCore/dom/FullscreenManager.h

    r244440 r245857  
    8080
    8181    void setFullscreenRenderer(RenderTreeBuilder&, RenderFullScreen&);
    82     RenderFullScreen* fullscreenRenderer() const { return m_fullscreenRenderer.get(); }
     82    RenderFullScreen* fullscreenRenderer() const;
    8383
    8484    void dispatchFullscreenChangeEvents();
  • trunk/Source/WebCore/html/FormAssociatedElement.cpp

    r243954 r245857  
    120120}
    121121
     122HTMLFormElement* FormAssociatedElement::form() const
     123{
     124    return m_form.get();
     125}
     126
    122127void FormAssociatedElement::formOwnerRemovedFromTree(const Node& formRoot)
    123128{
  • trunk/Source/WebCore/html/FormAssociatedElement.h

    r243954 r245857  
    4949
    5050    static HTMLFormElement* findAssociatedForm(const HTMLElement*, HTMLFormElement*);
    51     HTMLFormElement* form() const { return m_form.get(); }
     51    WEBCORE_EXPORT HTMLFormElement* form() const;
    5252    ValidityState* validity();
    5353
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r245712 r245857  
    150150    WTF_MAKE_ISO_ALLOCATED(HTMLMediaElement);
    151151public:
     152    typedef HTMLElement::WeakValueType WeakValueType;
     153    using HTMLElement::weakPtrFactory;
     154
    152155    RefPtr<MediaPlayer> player() const { return m_player; }
    153156
     
    575578
    576579    enum class AutoplayEventPlaybackState { None, PreventedAutoplay, StartedWithUserGesture, StartedWithoutUserGesture };
    577 
    578     using HTMLElement::weakPtrFactory;
    579580
    580581protected:
  • trunk/Source/WebCore/loader/MediaResourceLoader.cpp

    r243459 r245857  
    9898    auto cachedRequest = createPotentialAccessControlRequest(WTFMove(request), *m_document, m_crossOriginMode, WTFMove(loaderOptions));
    9999    if (m_mediaElement)
    100         cachedRequest.setInitiator(*m_mediaElement.get());
     100        cachedRequest.setInitiator(*m_mediaElement);
    101101
    102102    auto resource = m_document->cachedResourceLoader().requestMedia(WTFMove(cachedRequest)).value_or(nullptr);
  • trunk/Source/WebCore/page/DOMWindowProperty.cpp

    r242676 r245857  
    4343}
    4444
     45DOMWindow* DOMWindowProperty::window() const
     46{
     47    return m_window.get();
    4548}
     49
     50}
  • trunk/Source/WebCore/page/DOMWindowProperty.h

    r242676 r245857  
    3636public:
    3737    Frame* frame() const;
    38     DOMWindow* window() const { return m_window.get(); }
     38    DOMWindow* window() const;
    3939
    4040protected:
  • trunk/Source/WebCore/page/FrameViewLayoutContext.cpp

    r245838 r245857  
    459459}
    460460
     461RenderElement* FrameViewLayoutContext::subtreeLayoutRoot() const
     462{
     463    return m_subtreeLayoutRoot.get();
     464}
     465
    461466void FrameViewLayoutContext::convertSubtreeLayoutToFullLayout()
    462467{
  • trunk/Source/WebCore/page/FrameViewLayoutContext.h

    r240968 r245857  
    2828#include "LayoutUnit.h"
    2929#include "Timer.h"
    30 
    3130#include <wtf/WeakPtr.h>
    3231
     
    8382    unsigned layoutCount() const { return m_layoutCount; }
    8483
    85     RenderElement* subtreeLayoutRoot() const { return m_subtreeLayoutRoot.get(); }
     84    RenderElement* subtreeLayoutRoot() const;
    8685    void clearSubtreeLayoutRoot() { m_subtreeLayoutRoot.clear(); }
    8786    void convertSubtreeLayoutToFullLayout();
  • trunk/Source/WebCore/page/UndoItem.cpp

    r240315 r245857  
    3434WTF_MAKE_ISO_ALLOCATED_IMPL(UndoItem);
    3535
     36UndoManager* UndoItem::undoManager() const
     37{
     38    return m_undoManager.get();
     39}
     40
    3641void UndoItem::setUndoManager(UndoManager* undoManager)
    3742{
  • trunk/Source/WebCore/page/UndoItem.h

    r240476 r245857  
    5656    Document* document() const;
    5757
    58     UndoManager* undoManager() const { return m_undoManager.get(); }
     58    UndoManager* undoManager() const;
    5959    void setUndoManager(UndoManager*);
    6060
  • trunk/Source/WebCore/platform/ScrollView.h

    r245320 r245857  
    6666    virtual ~ScrollView();
    6767
     68    typedef Widget::WeakValueType WeakValueType;
     69    using Widget::weakPtrFactory;
     70
    6871    // ScrollableArea functions.
    6972    int scrollSize(ScrollbarOrientation) const final;
     
    7477
    7578    virtual void notifyPageThatContentAreaWillPaint() const;
    76 
    77     using Widget::weakPtrFactory;
    7879
    7980    IntPoint locationOfContents() const;
  • trunk/Source/WebCore/platform/Widget.cpp

    r245320 r245857  
    4343}
    4444
     45ScrollView* Widget::parent() const
     46{
     47    return m_parent.get();
     48}
     49
    4550void Widget::setParent(ScrollView* view)
    4651{
  • trunk/Source/WebCore/platform/Widget.h

    r245320 r245857  
    141141    WEBCORE_EXPORT void removeFromParent();
    142142    WEBCORE_EXPORT virtual void setParent(ScrollView* view);
    143     ScrollView* parent() const { return m_parent.get(); }
     143    WEBCORE_EXPORT ScrollView* parent() const;
    144144    FrameView* root() const;
    145145
  • trunk/Source/WebCore/platform/encryptedmedia/CDMInstanceSession.h

    r240746 r245857  
    4040class SharedBuffer;
    4141
    42 class CDMInstanceSessionClient {
     42class CDMInstanceSessionClient : public CanMakeWeakPtr<CDMInstanceSessionClient> {
    4343public:
    4444    virtual ~CDMInstanceSessionClient() = default;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h

    r245039 r245857  
    338338    void setShouldObserveTimeControlStatus(bool);
    339339
    340     WeakPtrFactory<MediaPlayerPrivateAVFoundationObjC> m_weakPtrFactory;
    341340    RetainPtr<AVURLAsset> m_avAsset;
    342341    RetainPtr<AVPlayer> m_avPlayer;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r245701 r245857  
    360360    , m_videoFullscreenLayerManager(std::make_unique<VideoFullscreenLayerManagerObjC>())
    361361    , m_videoFullscreenGravity(MediaPlayer::VideoGravityResizeAspect)
    362     , m_objcObserver(adoptNS([[WebCoreAVFMovieObserver alloc] initWithPlayer:m_weakPtrFactory.createWeakPtr(*this)]))
     362    , m_objcObserver(adoptNS([[WebCoreAVFMovieObserver alloc] initWithPlayer:makeWeakPtr(*this)]))
    363363    , m_videoFrameHasDrawn(false)
    364364    , m_haveCheckedPlayability(false)
    365365#if HAVE(AVFOUNDATION_VIDEO_OUTPUT)
    366     , m_videoOutputDelegate(adoptNS([[WebCoreAVFPullDelegate alloc] initWithPlayer:m_weakPtrFactory.createWeakPtr(*this)]))
     366    , m_videoOutputDelegate(adoptNS([[WebCoreAVFPullDelegate alloc] initWithPlayer:makeWeakPtr(*this)]))
    367367#endif
    368368#if HAVE(AVFOUNDATION_LOADER_DELEGATE)
    369     , m_loaderDelegate(adoptNS([[WebCoreAVFLoaderDelegate alloc] initWithPlayer:m_weakPtrFactory.createWeakPtr(*this)]))
     369    , m_loaderDelegate(adoptNS([[WebCoreAVFLoaderDelegate alloc] initWithPlayer:makeWeakPtr(*this)]))
    370370#endif
    371371    , m_currentTextTrack(0)
     
    388388MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC()
    389389{
    390     m_weakPtrFactory.revokeAll();
     390    weakPtrFactory().revokeAll();
    391391
    392392#if HAVE(AVFOUNDATION_LOADER_DELEGATE)
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h

    r242720 r245857  
    6060
    6161class MediaPlayerPrivateMediaSourceAVFObjC
    62     : public MediaPlayerPrivateInterface
     62    : public CanMakeWeakPtr<MediaPlayerPrivateMediaSourceAVFObjC>
     63    , public MediaPlayerPrivateInterface
    6364#if !RELEASE_LOG_DISABLED
    6465    , private LoggerHelper
     
    122123#endif
    123124    void setCDMSession(LegacyCDMSession*) override;
    124     CDMSessionMediaSourceAVFObjC* cdmSession() const { return m_session.get(); }
     125    CDMSessionMediaSourceAVFObjC* cdmSession() const;
    125126#endif
    126127
     
    147148    const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const;
    148149    bool shouldCheckHardwareSupport() const;
    149 
    150     WeakPtr<MediaPlayerPrivateMediaSourceAVFObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(*this); }
    151150
    152151#if !RELEASE_LOG_DISABLED
     
    283282
    284283    MediaPlayer* m_player;
    285     WeakPtrFactory<MediaPlayerPrivateMediaSourceAVFObjC> m_weakPtrFactory;
    286284    WeakPtrFactory<MediaPlayerPrivateMediaSourceAVFObjC> m_sizeChangeObserverWeakPtrFactory;
    287285    RefPtr<MediaSourcePrivateAVFObjC> m_mediaSourcePrivate;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm

    r244980 r245857  
    5353#import <wtf/MainThread.h>
    5454#import <wtf/NeverDestroyed.h>
     55#import <wtf/WeakPtr.h>
    5556
    5657#import "CoreVideoSoftLink.h"
     
    8889{
    8990    MediaPlayerPrivateMediaSourceAVFObjC* player = (MediaPlayerPrivateMediaSourceAVFObjC*)const_cast<void*>(listener);
    90     callOnMainThread([weakThis = player->createWeakPtr()] {
     91    callOnMainThread([weakThis = makeWeakPtr(player)] {
    9192        if (!weakThis)
    9293            return;
    93         weakThis.get()->effectiveRateChanged();
     94        weakThis->effectiveRateChanged();
    9495    });
    9596}
     
    121122    // addPeriodicTimeObserverForInterval: throws an exception if you pass a non-numeric CMTime, so just use
    122123    // an arbitrarily large time value of once an hour:
    123     __block auto weakThis = createWeakPtr();
     124    __block auto weakThis = makeWeakPtr(*this);
    124125    m_timeJumpedObserver = [m_synchronizer addPeriodicTimeObserverForInterval:PAL::toCMTime(MediaTime::createWithDouble(3600)) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {
    125126#if LOG_DISABLED
     
    287288{
    288289    ALWAYS_LOG(LOGIDENTIFIER);
    289     callOnMainThread([weakThis = createWeakPtr()] {
     290    callOnMainThread([weakThis = makeWeakPtr(*this)] {
    290291        if (!weakThis)
    291292            return;
     
    308309{
    309310    ALWAYS_LOG(LOGIDENTIFIER);
    310     callOnMainThread([weakThis = createWeakPtr()] {
     311    callOnMainThread([weakThis = makeWeakPtr(*this)] {
    311312        if (!weakThis)
    312313            return;
     
    408409
    409410    m_seeking = true;
    410     auto weakThis = createWeakPtr();
    411411    m_pendingSeek = std::make_unique<PendingSeek>(time, negativeThreshold, positiveThreshold);
    412412
     
    859859
    860860    MediaTime duration = m_mediaSourcePrivate->duration();
    861     auto weakThis = createWeakPtr();
    862861    NSArray* times = @[[NSValue valueWithCMTime:PAL::toCMTime(duration)]];
    863862
     
    866865    UNUSED_PARAM(logSiteIdentifier);
    867866
    868     m_durationObserver = [m_synchronizer addBoundaryTimeObserverForTimes:times queue:dispatch_get_main_queue() usingBlock:[weakThis, duration, logSiteIdentifier, this] {
     867    m_durationObserver = [m_synchronizer addBoundaryTimeObserverForTimes:times queue:dispatch_get_main_queue() usingBlock:[weakThis = makeWeakPtr(*this), duration, logSiteIdentifier, this] {
    869868        if (!weakThis)
    870869            return;
     
    956955#endif
    957956
     957CDMSessionMediaSourceAVFObjC* MediaPlayerPrivateMediaSourceAVFObjC::cdmSession() const
     958{
     959    return m_session.get();
     960}
     961
    958962void MediaPlayerPrivateMediaSourceAVFObjC::setCDMSession(LegacyCDMSession* session)
    959963{
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h

    r242720 r245857  
    176176    ALLOW_NEW_API_WITHOUT_GUARDS_END
    177177
    178     WeakPtr<SourceBufferPrivateAVFObjC> createWeakPtr() { return m_weakFactory.createWeakPtr(*this); }
    179 
    180178    Vector<RefPtr<VideoTrackPrivateMediaSourceAVFObjC>> m_videoTracks;
    181179    Vector<RefPtr<AudioTrackPrivateMediaSourceAVFObjC>> m_audioTracks;
    182180    Vector<SourceBufferPrivateAVFObjCErrorClient*> m_errorClients;
    183181
    184     WeakPtrFactory<SourceBufferPrivateAVFObjC> m_weakFactory;
    185182    WeakPtrFactory<SourceBufferPrivateAVFObjC> m_appendWeakFactory;
    186183
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm

    r244716 r245857  
    466466SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC(MediaSourcePrivateAVFObjC* parent)
    467467    : m_parser(adoptNS([PAL::allocAVStreamDataParserInstance() init]))
    468     , m_delegate(adoptNS([[WebAVStreamDataParserListener alloc] initWithParser:m_parser.get() parent:createWeakPtr()]))
    469     , m_errorListener(adoptNS([[WebAVSampleBufferErrorListener alloc] initWithParent:createWeakPtr()]))
     468    , m_delegate(adoptNS([[WebAVStreamDataParserListener alloc] initWithParser:m_parser.get() parent:makeWeakPtr(*this)]))
     469    , m_errorListener(adoptNS([[WebAVSampleBufferErrorListener alloc] initWithParent:makeWeakPtr(*this)]))
    470470    , m_isAppendingGroup(adoptOSObject(dispatch_group_create()))
    471471    , m_mediaSource(parent)
     
    885885        if (!m_audioRenderers.contains(trackID)) {
    886886            renderer = adoptNS([PAL::allocAVSampleBufferAudioRendererInstance() init]);
    887             auto weakThis = createWeakPtr();
     887            auto weakThis = makeWeakPtr(*this);
    888888            [renderer requestMediaDataWhenReadyOnQueue:dispatch_get_main_queue() usingBlock:^{
    889889                if (weakThis)
     
    921921
    922922        if (m_hdcpError) {
    923             WeakPtr<SourceBufferPrivateAVFObjC> weakThis = createWeakPtr();
    924             callOnMainThread([weakThis] {
     923            callOnMainThread([weakThis = makeWeakPtr(*this)] {
    925924                if (!weakThis || !weakThis->m_session || !weakThis->m_hdcpError)
    926925                    return;
     
    10661065    if (m_decompressionSession) {
    10671066        m_decompressionSession->flush();
    1068         m_decompressionSession->notifyWhenHasAvailableVideoFrame([weakThis = createWeakPtr()] {
     1067        m_decompressionSession->notifyWhenHasAvailableVideoFrame([weakThis = makeWeakPtr(*this)] {
    10691068            if (weakThis && weakThis->m_mediaSource)
    10701069                weakThis->m_mediaSource->player()->setHasAvailableVideoFrame(true);
     
    11391138            } else {
    11401139                [m_displayLayer enqueueSampleBuffer:platformSample.sample.cmSampleBuffer];
    1141                 [m_displayLayer prerollDecodeWithCompletionHandler:[weakThis = createWeakPtr()] (BOOL success) mutable {
     1140                [m_displayLayer prerollDecodeWithCompletionHandler:[weakThis = makeWeakPtr(*this)] (BOOL success) mutable {
    11421141                    if (!success || !weakThis)
    11431142                        return;
     
    12381237        }
    12391238        if (m_displayLayer) {
    1240             auto weakThis = createWeakPtr();
     1239            auto weakThis = makeWeakPtr(*this);
    12411240            [m_displayLayer requestMediaDataWhenReadyOnQueue:dispatch_get_main_queue() usingBlock:^ {
    12421241                if (weakThis)
     
    12451244        }
    12461245    } else if (m_audioRenderers.contains(trackID)) {
    1247         auto weakThis = createWeakPtr();
     1246        auto weakThis = makeWeakPtr(*this);
    12481247        [m_audioRenderers.get(trackID) requestMediaDataWhenReadyOnQueue:dispatch_get_main_queue() usingBlock:^ {
    12491248            if (weakThis)
     
    12791278
    12801279    if (m_displayLayer) {
    1281         auto weakThis = createWeakPtr();
     1280        auto weakThis = makeWeakPtr(*this);
    12821281        [m_displayLayer requestMediaDataWhenReadyOnQueue:dispatch_get_main_queue() usingBlock:^ {
    12831282            if (weakThis)
     
    13071306        return;
    13081307
    1309     WeakPtr<SourceBufferPrivateAVFObjC> weakThis = createWeakPtr();
    1310     m_decompressionSession->requestMediaDataWhenReady([weakThis] {
     1308    m_decompressionSession->requestMediaDataWhenReady([weakThis = makeWeakPtr(*this)] {
    13111309        if (weakThis)
    13121310            weakThis->didBecomeReadyForMoreSamples(weakThis->m_enabledVideoTrackID);
    13131311    });
    1314     m_decompressionSession->notifyWhenHasAvailableVideoFrame([weakThis = createWeakPtr()] {
     1312    m_decompressionSession->notifyWhenHasAvailableVideoFrame([weakThis = makeWeakPtr(*this)] {
    13151313        if (weakThis && weakThis->m_mediaSource)
    13161314            weakThis->m_mediaSource->player()->setHasAvailableVideoFrame(true);
  • trunk/Source/WebCore/rendering/RenderBlockFlow.cpp

    r245838 r245857  
    160160}
    161161
     162RenderMultiColumnFlow* RenderBlockFlow::multiColumnFlowSlowCase() const
     163{
     164    return rareBlockFlowData()->m_multiColumnFlow.get();
     165}
     166
    162167RenderBlockFlow* RenderBlockFlow::previousSiblingWithOverhangingFloats(bool& parentHasFloats) const
    163168{
  • trunk/Source/WebCore/rendering/RenderBlockFlow.h

    r245838 r245857  
    265265    void layoutLineGridBox();
    266266
    267     RenderMultiColumnFlow* multiColumnFlow() const { return hasRareBlockFlowData() ? rareBlockFlowData()->m_multiColumnFlow.get() : nullptr; }
     267    RenderMultiColumnFlow* multiColumnFlow() const { return hasRareBlockFlowData() ? multiColumnFlowSlowCase() : nullptr; }
     268    RenderMultiColumnFlow* multiColumnFlowSlowCase() const;
    268269    void setMultiColumnFlow(RenderMultiColumnFlow&);
    269270    void clearMultiColumnFlow();
  • trunk/Source/WebCore/rendering/RenderMultiColumnFlow.cpp

    r242919 r245857  
    108108}
    109109
     110RenderMultiColumnSpannerPlaceholder* RenderMultiColumnFlow::findColumnSpannerPlaceholder(RenderBox* spanner) const
     111{
     112    return m_spannerMap->get(spanner).get();
     113}
     114
    110115void RenderMultiColumnFlow::layout()
    111116{
  • trunk/Source/WebCore/rendering/RenderMultiColumnFlow.h

    r234215 r245857  
    4949    static RenderBox* previousColumnSetOrSpannerSiblingOf(const RenderBox*);
    5050
    51     RenderMultiColumnSpannerPlaceholder* findColumnSpannerPlaceholder(RenderBox* spanner) const { return m_spannerMap->get(spanner).get(); }
     51    RenderMultiColumnSpannerPlaceholder* findColumnSpannerPlaceholder(RenderBox* spanner) const;
    5252
    5353    void layout() override;
  • trunk/Source/WebCore/rendering/RenderTable.cpp

    r245543 r245857  
    9696
    9797RenderTable::~RenderTable() = default;
     98
     99RenderTableSection* RenderTable::header() const
     100{
     101    return m_head.get();
     102}
     103
     104RenderTableSection* RenderTable::footer() const
     105{
     106    return m_foot.get();
     107}
     108
     109RenderTableSection* RenderTable::firstBody() const
     110{
     111    return m_firstBody.get();
     112}
     113
     114RenderTableSection* RenderTable::topSection() const
     115{
     116    ASSERT(!needsSectionRecalc());
     117    if (m_head)
     118        return m_head.get();
     119    if (m_firstBody)
     120        return m_firstBody.get();
     121    return m_foot.get();
     122}
    98123
    99124void RenderTable::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
  • trunk/Source/WebCore/rendering/RenderTable.h

    r239427 r245857  
    153153    }
    154154
    155     RenderTableSection* header() const { return m_head.get(); }
    156     RenderTableSection* footer() const { return m_foot.get(); }
    157     RenderTableSection* firstBody() const { return m_firstBody.get(); }
     155    RenderTableSection* header() const;
     156    RenderTableSection* footer() const;
     157    RenderTableSection* firstBody() const;
    158158
    159159    // This function returns 0 if the table has no section.
     
    371371};
    372372
    373 inline RenderTableSection* RenderTable::topSection() const
    374 {
    375     ASSERT(!needsSectionRecalc());
    376     if (m_head)
    377         return m_head.get();
    378     if (m_firstBody)
    379         return m_firstBody.get();
    380     return m_foot.get();
    381 }
    382 
    383373inline bool isDirectionSame(const RenderBox* tableItem, const RenderBox* otherTableItem) { return tableItem && otherTableItem ? tableItem->style().direction() == otherTableItem->style().direction() : true; }
    384374
  • trunk/Source/WebKit/ChangeLog

    r245856 r245857  
     12019-05-28  Geoffrey Garen  <ggaren@apple.com>
     2
     3        WeakPtr breaks vtables when upcasting to base classes
     4        https://bugs.webkit.org/show_bug.cgi?id=188799
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
     9        (WebKit::WebResourceLoadStatisticsStore::networkSession):
     10        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
     11        * Shared/WebBackForwardListItem.cpp:
     12        (WebKit::WebBackForwardListItem::suspendedPage const):
     13        * Shared/WebBackForwardListItem.h:
     14        (WebKit::WebBackForwardListItem::suspendedPage const): Deleted. Moved
     15        functions out of line to avoid #include explosion for .get().
     16
     17        * UIProcess/Authentication/cocoa/SecKeyProxyStore.h:
     18        (WebKit::SecKeyProxyStore::get const):
     19        (WebKit::SecKeyProxyStore::weakPtrFactory const): Deleted. Adopted
     20        CanMakeWeakPtr.
     21
     22        * UIProcess/WebAuthentication/AuthenticatorManager.h:
     23        * UIProcess/WebProcessProxy.cpp: It takes an extra using declaration
     24        to disambiguate multiple CanMakeWeakPtr base classes now.
     25
     26        (WebKit::WebProcessProxy::processPool const):
     27        * UIProcess/WebProcessProxy.h:
     28        (WebKit::WebProcessProxy::processPool const): Deleted. Moved
     29        functions out of line to avoid #include explosion for .get().
     30
    1312019-05-29  Youenn Fablet  <youenn@apple.com>
    232
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp

    r245796 r245857  
    10171017}
    10181018
     1019NetworkSession* WebResourceLoadStatisticsStore::networkSession()
     1020{
     1021    return m_networkSession.get();
     1022}
     1023
    10191024void WebResourceLoadStatisticsStore::deleteWebsiteDataForRegistrableDomains(OptionSet<WebsiteDataType> dataTypes, HashMap<RegistrableDomain, WebsiteDataToRemove>&& domainsToRemoveWebsiteDataFor, bool shouldNotifyPage, CompletionHandler<void(const HashSet<RegistrableDomain>&)>&& completionHandler)
    10201025{
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h

    r245796 r245857  
    176176    void notifyResourceLoadStatisticsProcessed();
    177177
    178     NetworkSession* networkSession() { return m_networkSession.get(); }
     178    NetworkSession* networkSession();
    179179
    180180    void sendDiagnosticMessageWithValue(const String& message, const String& description, unsigned value, unsigned sigDigits, WebCore::ShouldSample) const;
  • trunk/Source/WebKit/Shared/WebBackForwardListItem.cpp

    r245796 r245857  
    169169}
    170170
     171SuspendedPageProxy* WebBackForwardListItem::suspendedPage() const
     172{
     173    return m_suspendedPage.get();
     174}
     175
    171176void WebBackForwardListItem::removeSuspendedPageFromProcessPool()
    172177{
  • trunk/Source/WebKit/Shared/WebBackForwardListItem.h

    r245796 r245857  
    7676#endif
    7777    void setSuspendedPage(SuspendedPageProxy*);
    78     SuspendedPageProxy* suspendedPage() const { return m_suspendedPage.get(); }
     78    SuspendedPageProxy* suspendedPage() const;
    7979
    8080#if !LOG_DISABLED
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitWebResource.cpp

    r243608 r245857  
    2525#include "WebKitURIRequest.h"
    2626#include "WebKitWebResourcePrivate.h"
     27#include "WebPageProxy.h"
    2728#include <glib/gi18n-lib.h>
    2829#include <wtf/glib/GRefPtr.h>
  • trunk/Source/WebKit/UIProcess/Authentication/cocoa/SecKeyProxyStore.h

    r241658 r245857  
    4040namespace WebKit {
    4141
    42 class SecKeyProxyStore : public RefCounted<SecKeyProxyStore> {
     42class SecKeyProxyStore : public RefCounted<SecKeyProxyStore>, public CanMakeWeakPtr<SecKeyProxyStore> {
    4343public:
    4444    static Ref<SecKeyProxyStore> create() { return adoptRef(* new SecKeyProxyStore()); }
     
    4848
    4949    auto* get() const { return m_secKeyProxy.get(); }
    50     auto& weakPtrFactory() const { return m_weakPtrFactory; }
    5150
    5251private:
    5352    SecKeyProxyStore() = default;
    5453
    55     WeakPtrFactory<SecKeyProxyStore> m_weakPtrFactory;
    5654    RetainPtr<SecKeyProxy> m_secKeyProxy;
    5755};
  • trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.h

    r245500 r245857  
    5050
    5151    using AuthenticatorTransportService::Observer::weakPtrFactory;
     52    typedef AuthenticatorTransportService::Observer::WeakValueType WeakValueType;
    5253
    5354    AuthenticatorManager();
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp

    r245796 r245857  
    15141514}
    15151515
     1516WebProcessPool& WebProcessProxy::processPool() const
     1517{
     1518    ASSERT(m_processPool);
     1519    return *m_processPool.get();
     1520}
     1521
    15161522#if PLATFORM(WATCHOS)
    15171523
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.h

    r245796 r245857  
    120120    void decrementSuspendedPageCount();
    121121
    122     WebProcessPool& processPool() const { ASSERT(m_processPool); return *m_processPool.get(); }
     122    WebProcessPool& processPool() const;
    123123
    124124    WebCore::RegistrableDomain registrableDomain() const { return m_registrableDomain.valueOr(WebCore::RegistrableDomain { }); }
  • trunk/Tools/ChangeLog

    r245851 r245857  
     12019-05-28  Geoffrey Garen  <ggaren@apple.com>
     2
     3        WeakPtr breaks vtables when upcasting to base classes
     4        https://bugs.webkit.org/show_bug.cgi?id=188799
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Adopt the new macro API instead
     9        of template specialization for observing weak references.
     10
     11        (TestWebKitAPI::Int::Int):
     12        (TestWebKitAPI::Int::operator int const):
     13        (TestWebKitAPI::Int::operator== const): Use a class for integer tests
     14        because WeakPtr doesn't naturally support pointing to non-class objects
     15        now.
     16
     17        (TestWebKitAPI::Base::foo):
     18        (TestWebKitAPI::Derived::foo): Inherit from CanMakeWeakPtr to enable
     19        deduction of the weak pointer type.
     20
     21        (TestWebKitAPI::TEST): Updated to use Int.
     22
     23        (TestWebKitAPI::Base::weakPtrFactory const): Deleted.
     24        (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): Deleted.
     25        (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): Deleted.
     26
    1272019-05-29  Aakash Jain  <aakash_jain@apple.com>
    228
  • trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp

    r243965 r245857  
    2626#include "config.h"
    2727
     28static unsigned s_baseWeakReferences = 0;
     29
     30#define DID_CREATE_WEAK_REFERENCE(p) do { \
     31    ++s_baseWeakReferences; \
     32} while (0);
     33
     34#define WILL_DESTROY_WEAK_REFERENCE(p) do { \
     35    --s_baseWeakReferences; \
     36} while (0);
     37
    2838#include "Test.h"
    2939#include <wtf/HashSet.h>
     
    3141#include <wtf/WeakPtr.h>
    3242
    33 static unsigned s_baseWeakReferences = 0;
    34 
    3543namespace TestWebKitAPI {
    3644
    37 class Base {
     45struct Int : public CanMakeWeakPtr<Int> {
     46    Int(int i) : m_i(i) { }
     47    operator int() const { return m_i; }
     48    bool operator==(const Int& other) const { return m_i == other.m_i; }
     49    int m_i;
     50};
     51
     52class Base : public CanMakeWeakPtr<Base> {
    3853public:
    3954    Base() { }
     
    4459    }
    4560
    46     auto& weakPtrFactory() const { return m_weakPtrFactory; }
    47 
    48 private:
    49     WeakPtrFactory<Base> m_weakPtrFactory;
     61    int dummy; // Prevent empty base class optimization, to make testing more interesting.
    5062};
    5163
     
    5466    Derived() { }
    5567
     68    virtual ~Derived() { } // Force a pointer fixup when casting Base <-> Derived
     69
    5670    int foo()
    5771    {
     
    6276}
    6377
    64 namespace WTF {
    65 
    66 template<>
    67 WeakReference<TestWebKitAPI::Base>::WeakReference(TestWebKitAPI::Base* ptr)
    68     : m_ptr(ptr)
    69 {
    70     ++s_baseWeakReferences;
    71 }
    72 template<>
    73 WeakReference<TestWebKitAPI::Base>::~WeakReference()
    74 {
    75     --s_baseWeakReferences;
    76 }
    77 
    78 }
    79 
    8078namespace TestWebKitAPI {
    8179
    8280TEST(WTF_WeakPtr, Basic)
    8381{
    84     int dummy = 5;
    85     WeakPtrFactory<int>* factory = new WeakPtrFactory<int>();
    86     WeakPtr<int> weakPtr1 = factory->createWeakPtr(dummy);
    87     WeakPtr<int> weakPtr2 = factory->createWeakPtr(dummy);
    88     WeakPtr<int> weakPtr3 = factory->createWeakPtr(dummy);
     82    Int dummy(5);
     83    WeakPtrFactory<Int>* factory = new WeakPtrFactory<Int>();
     84    WeakPtr<Int> weakPtr1 = factory->createWeakPtr(dummy);
     85    WeakPtr<Int> weakPtr2 = factory->createWeakPtr(dummy);
     86    WeakPtr<Int> weakPtr3 = factory->createWeakPtr(dummy);
    8987    EXPECT_EQ(weakPtr1.get(), &dummy);
    9088    EXPECT_EQ(weakPtr2.get(), &dummy);
     
    107105TEST(WTF_WeakPtr, Assignment)
    108106{
    109     int dummy = 5;
    110     WeakPtr<int> weakPtr;
    111     {
    112         WeakPtrFactory<int> factory;
     107    Int dummy(5);
     108    WeakPtr<Int> weakPtr;
     109    {
     110        WeakPtrFactory<Int> factory;
    113111        EXPECT_NULL(weakPtr.get());
    114112        weakPtr = factory.createWeakPtr(dummy);
     
    120118TEST(WTF_WeakPtr, MultipleFactories)
    121119{
    122     int dummy1 = 5;
    123     int dummy2 = 7;
    124     WeakPtrFactory<int>* factory1 = new WeakPtrFactory<int>();
    125     WeakPtrFactory<int>* factory2 = new WeakPtrFactory<int>();
    126     WeakPtr<int> weakPtr1 = factory1->createWeakPtr(dummy1);
    127     WeakPtr<int> weakPtr2 = factory2->createWeakPtr(dummy2);
     120    Int dummy1(5);
     121    Int dummy2(7);
     122    WeakPtrFactory<Int>* factory1 = new WeakPtrFactory<Int>();
     123    WeakPtrFactory<Int>* factory2 = new WeakPtrFactory<Int>();
     124    WeakPtr<Int> weakPtr1 = factory1->createWeakPtr(dummy1);
     125    WeakPtr<Int> weakPtr2 = factory2->createWeakPtr(dummy2);
    128126    EXPECT_EQ(weakPtr1.get(), &dummy1);
    129127    EXPECT_EQ(weakPtr2.get(), &dummy2);
     
    140138TEST(WTF_WeakPtr, RevokeAll)
    141139{
    142     int dummy = 5;
    143     WeakPtrFactory<int> factory;
    144     WeakPtr<int> weakPtr1 = factory.createWeakPtr(dummy);
    145     WeakPtr<int> weakPtr2 = factory.createWeakPtr(dummy);
    146     WeakPtr<int> weakPtr3 = factory.createWeakPtr(dummy);
     140    Int dummy(5);
     141    WeakPtrFactory<Int> factory;
     142    WeakPtr<Int> weakPtr1 = factory.createWeakPtr(dummy);
     143    WeakPtr<Int> weakPtr2 = factory.createWeakPtr(dummy);
     144    WeakPtr<Int> weakPtr3 = factory.createWeakPtr(dummy);
    147145    EXPECT_EQ(weakPtr1.get(), &dummy);
    148146    EXPECT_EQ(weakPtr2.get(), &dummy);
     
    154152}
    155153
    156 struct Foo {
     154struct Foo : public CanMakeWeakPtr<Foo> {
    157155    void bar() { };
    158156};
     
    186184TEST(WTF_WeakPtr, Forget)
    187185{
    188     int dummy = 5;
    189     int dummy2 = 7;
    190 
    191     WeakPtrFactory<int> outerFactory;
    192     WeakPtr<int> weakPtr1, weakPtr2, weakPtr3, weakPtr4;
    193     {
    194         WeakPtrFactory<int> innerFactory;
     186    Int dummy(5);
     187    Int dummy2(7);
     188
     189    WeakPtrFactory<Int> outerFactory;
     190    WeakPtr<Int> weakPtr1, weakPtr2, weakPtr3, weakPtr4;
     191    {
     192        WeakPtrFactory<Int> innerFactory;
    195193        weakPtr1 = innerFactory.createWeakPtr(dummy);
    196194        weakPtr2 = innerFactory.createWeakPtr(dummy);
     
    218216        EXPECT_EQ(weakPtr4.get(), &dummy);
    219217
    220         WeakPtr<int> weakPtr5 = weakPtr2;
     218        WeakPtr<Int> weakPtr5 = weakPtr2;
    221219        EXPECT_EQ(weakPtr2.get(), &dummy);
    222220        EXPECT_EQ(weakPtr5.get(), &dummy);
     
    234232    EXPECT_EQ(weakPtr4.get(), &dummy2);
    235233
    236     WeakPtr<int> weakPtr5 = weakPtr4;
     234    WeakPtr<Int> weakPtr5 = weakPtr4;
    237235    EXPECT_EQ(weakPtr4.get(), &dummy2);
    238236    EXPECT_EQ(weakPtr5.get(), &dummy2);
    239237    weakPtr5.clear();
    240238    EXPECT_NULL(weakPtr5.get());
    241     WeakPtr<int> weakPtr6 = weakPtr5;
     239    WeakPtr<Int> weakPtr6 = weakPtr5;
    242240    EXPECT_NULL(weakPtr6.get());
    243241    EXPECT_EQ(weakPtr5.get(), weakPtr6.get());
    244242
    245     WeakPtr<int> weakPtr7 = outerFactory.createWeakPtr(dummy2);
     243    WeakPtr<Int> weakPtr7 = outerFactory.createWeakPtr(dummy2);
    246244    EXPECT_EQ(weakPtr7.get(), &dummy2);
    247245    weakPtr7 = nullptr;
     
    251249TEST(WTF_WeakPtr, Downcasting)
    252250{
    253     int dummy0 = 0;
    254     int dummy1 = 1;
     251    int dummy0(0);
     252    int dummy1(1);
    255253
    256254    WeakPtr<Base> baseWeakPtr;
Note: See TracChangeset for help on using the changeset viewer.