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

Changeset 287811 in webkit


Ignore:
Timestamp:
Jan 8, 2022, 8:46:39 AM (5 years ago)
Author:
Tyler Wilcock
Message:

AX: Improve WeakHashSet hygienics in AXObjectCache
https://bugs.webkit.org/show_bug.cgi?id=234961

Reviewed by Andres Gonzalez.

AXObjectCache owns four WeakHashSets. WeakHashSets are not notified
when the objects they hold are deleted[1], so we should be cleaning
them up in AXObjectCache::remove(Node&).

This patch also replaces range-based for loop iteration over these
WeakHashSets with WeakHashSet::forEach, which inherently checks that
each item is valid (non-null and contained in the hashset) before
using the item.

[1]: https://github.com/WebKit/WebKit/blob/main/Introduction.md#weakhashset

  • accessibility/AXObjectCache.cpp:

(WebCore::AXObjectCache::remove):
Delete the removed node from AXObjectCache's owned WeakHashSets.
(WebCore::filterWeakHashSetForRemoval): Added.
(WebCore::AXObjectCache::prepareForDocumentDestruction):
Use filterWeakHashSetForRemoval to remove soon-to-be-deleted nodes
from AXObjectCache's owned WeakHashSets.
(WebCore::AXObjectCache::performDeferredCacheUpdate):
Use WeakHashSet::forEach instead of range-based for loops.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r287810 r287811  
     12022-01-08  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: Improve WeakHashSet hygienics in AXObjectCache
     4        https://bugs.webkit.org/show_bug.cgi?id=234961
     5
     6        Reviewed by Andres Gonzalez.
     7
     8        AXObjectCache owns four WeakHashSets. WeakHashSets are not notified
     9        when the objects they hold are deleted[1], so we should be cleaning
     10        them up in AXObjectCache::remove(Node&).
     11
     12        This patch also replaces range-based for loop iteration over these
     13        WeakHashSets with WeakHashSet::forEach, which inherently checks that
     14        each item is valid (non-null and contained in the hashset) before
     15        using the item.
     16
     17        [1]: https://github.com/WebKit/WebKit/blob/main/Introduction.md#weakhashset
     18
     19        * accessibility/AXObjectCache.cpp:
     20        (WebCore::AXObjectCache::remove):
     21        Delete the removed node from AXObjectCache's owned WeakHashSets.
     22        (WebCore::filterWeakHashSetForRemoval): Added.
     23        (WebCore::AXObjectCache::prepareForDocumentDestruction):
     24        Use filterWeakHashSetForRemoval to remove soon-to-be-deleted nodes
     25        from AXObjectCache's owned WeakHashSets.
     26        (WebCore::AXObjectCache::performDeferredCacheUpdate):
     27        Use WeakHashSet::forEach instead of range-based for loops.
     28
    1292022-01-08  Tyler Wilcock  <tyler_w@apple.com>
    230
  • trunk/Source/WebCore/accessibility/AXObjectCache.cpp

    r287704 r287811  
    864864        m_deferredAttributeChange.remove(downcast<Element>(&node));
    865865        m_modalElementsSet.remove(downcast<Element>(&node));
     866        m_deferredRecomputeIsIgnoredList.remove(downcast<Element>(node));
     867        m_deferredSelectedChildredChangedList.remove(downcast<Element>(node));
     868        m_deferredModalChangedList.remove(downcast<Element>(node));
     869        m_deferredMenuListChange.remove(downcast<Element>(node));
    866870    }
    867871    m_deferredChildrenChangedNodeList.remove(&node);
     
    31623166}
    31633167
     3168static void filterWeakHashSetForRemoval(WeakHashSet<Element>& weakHashSet, const Document& document, HashSet<Ref<Node>>& nodesToRemove)
     3169{
     3170    weakHashSet.forEach([&] (auto& element) {
     3171        conditionallyAddNodeToFilterList(&element, document, nodesToRemove);
     3172    });
     3173}
     3174
    31643175void AXObjectCache::prepareForDocumentDestruction(const Document& document)
    31653176{
     
    31693180    filterListForRemoval(m_deferredTextChangedList, document, nodesToRemove);
    31703181    filterListForRemoval(m_deferredChildrenChangedNodeList, document, nodesToRemove);
     3182    filterWeakHashSetForRemoval(m_deferredRecomputeIsIgnoredList, document, nodesToRemove);
     3183    filterWeakHashSetForRemoval(m_deferredSelectedChildredChangedList, document, nodesToRemove);
     3184    filterWeakHashSetForRemoval(m_deferredModalChangedList, document, nodesToRemove);
     3185    filterWeakHashSetForRemoval(m_deferredMenuListChange, document, nodesToRemove);
    31713186    filterMapForRemoval(m_deferredTextFormControlValue, document, nodesToRemove);
    31723187    filterMapForRemoval(m_deferredAttributeChange, document, nodesToRemove);
     
    32193234    m_deferredTextChangedList.clear();
    32203235
    3221     for (auto& element : m_deferredRecomputeIsIgnoredList) {
     3236    m_deferredRecomputeIsIgnoredList.forEach([this] (auto& element) {
    32223237        if (auto* renderer = element.renderer())
    32233238            recomputeIsIgnored(renderer);
    3224     }
     3239    });
    32253240    m_deferredRecomputeIsIgnoredList.clear();
    3226    
    3227     for (auto& selectElement : m_deferredSelectedChildredChangedList)
     3241
     3242    m_deferredSelectedChildredChangedList.forEach([this] (auto& selectElement) {
    32283243        selectedChildrenChanged(&selectElement);
     3244    });
    32293245    m_deferredSelectedChildredChangedList.clear();
    32303246
     
    32473263    m_deferredFocusedNodeChange.clear();
    32483264
    3249     for (auto& deferredModalChangedElement : m_deferredModalChangedList)
     3265    m_deferredModalChangedList.forEach([this] (auto& deferredModalChangedElement) {
    32503266        handleModalChange(deferredModalChangedElement);
     3267    });
    32513268    m_deferredModalChangedList.clear();
    32523269
    3253     for (auto& deferredMenuListChangeElement : m_deferredMenuListChange)
     3270    m_deferredMenuListChange.forEach([this] (auto& deferredMenuListChangeElement) {
    32543271        postNotification(&deferredMenuListChangeElement, AXObjectCache::AXMenuListValueChanged);
     3272    });
    32553273    m_deferredMenuListChange.clear();
    32563274   
Note: See TracChangeset for help on using the changeset viewer.