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

Changeset 295196 in webkit


Ignore:
Timestamp:
Jun 2, 2022, 11:46:05 PM (4 years ago)
Author:
Alan Coon
Message:

Cherry-pick c8efcc3a72bc. rdar://problem/90913864

Store StyleScope during CSSStyleSheet Creation
​https://bugs.webkit.org/show_bug.cgi?id=239659

Reviewed by Antti Koivisto.

To ensure that we can always access the style scope, we shall ensure we store the style scope
at CSSStyleSheet creation time. It was possible before that a style sheet could become disconnected
and then a rule would later be mutated. This resulted in the unfortunate side effect of being unable to find
the style scope.

  • css/CSSStyleSheet.cpp: (WebCore::CSSStyleSheet::CSSStyleSheet): (WebCore::CSSStyleSheet::styleScope):
  • css/CSSStyleSheet.h:
  • style/StyleScope.cpp: (WebCore::Style::Scope::collectResolverScopes):
  • style/StyleScope.h:

Canonical link: ​https://commits.webkit.org/249896@main
git-svn-id: ​https://svn.webkit.org/repository/webkit/trunk@293232 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-613-branch/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-613-branch/Source/WebCore/ChangeLog

    r295195 r295196  
     12022-04-22  Brandon Stewart  <brandonstewart@apple.com>
     2
     3        Store StyleScope during CSSStyleSheet Creation
     4        https://bugs.webkit.org/show_bug.cgi?id=239659
     5
     6        Reviewed by Antti Koivisto.
     7
     8        To ensure that we can always access the style scope, we shall ensure we store the style scope
     9        at CSSStyleSheet creation time. It was possible before that a style sheet could become disconnected
     10        and then a rule would later be mutated. This resulted in the unfortunate side effect of being unable to find
     11        the style scope.
     12
     13        * css/CSSStyleSheet.cpp:
     14        (WebCore::CSSStyleSheet::CSSStyleSheet):
     15        (WebCore::CSSStyleSheet::styleScope):
     16        * css/CSSStyleSheet.h:
     17        * style/StyleScope.cpp:
     18        (WebCore::Style::Scope::collectResolverScopes):
     19        * style/StyleScope.h:
     20
    1212022-03-15  Gabriel Nava Marino  <gnavamarino@apple.com>
    222
  • branches/safari-613-branch/Source/WebCore/css/CSSStyleSheet.cpp

    r289935 r295196  
    9393    , m_ownerRule(ownerRule)
    9494{
     95    if (auto* parent = parentStyleSheet())
     96        m_styleScope = parent->styleScope();
     97
    9598    m_contents->registerClient(this);
    9699}
    … …  
    100103    , m_isInlineStylesheet(isInlineStylesheet)
    101104    , m_isOriginClean(isOriginClean)
     105    , m_styleScope(Style::Scope::forNode(ownerNode))
    102106    , m_ownerNode(&ownerNode)
    103107    , m_startPosition(startPosition)
    … …  
    380384Style::Scope* CSSStyleSheet::styleScope()
    381385{
    382     auto* ownerNode = rootStyleSheet().ownerNode();
    383     if (!ownerNode)
    384         return nullptr;
    385     return &Style::Scope::forNode(*ownerNode);
     386    return m_styleScope.get();
    386387}
    387388
  • branches/safari-613-branch/Source/WebCore/css/CSSStyleSheet.h

    r289935 r295196  
    2727#include <wtf/Noncopyable.h>
    2828#include <wtf/TypeCasts.h>
     29#include <wtf/WeakPtr.h>
    2930#include <wtf/text/AtomStringHash.h>
    3031#include <wtf/text/TextPosition.h>
    … …  
    148149    String m_title;
    149150    RefPtr<MediaQuerySet> m_mediaQueries;
     151    WeakPtr<Style::Scope> m_styleScope;
    150152
    151153    Node* m_ownerNode { nullptr };
  • branches/safari-613-branch/Source/WebCore/style/StyleScope.cpp

    r287325 r295196  
    684684    ResolverScopes resolverScopes;
    685685
    686     resolverScopes.add(*resolverIfExists(), Vector<CheckedPtr<Scope>> { this });
     686    resolverScopes.add(*resolverIfExists(), Vector<WeakPtr<Scope>> { this });
    687687
    688688    for (auto* shadowRoot : m_document.inDocumentShadowRoots()) {
    … …  
    691691        if (!resolver)
    692692            continue;
    693         resolverScopes.add(*resolver, Vector<CheckedPtr<Scope>> { }).iterator->value.append(&scope);
     693        resolverScopes.add(*resolver, Vector<WeakPtr<Scope>> { }).iterator->value.append(&scope);
    694694    }
    695695    return resolverScopes;
  • branches/safari-613-branch/Source/WebCore/style/StyleScope.h

    r287325 r295196  
    5959class Resolver;
    6060
    61 class Scope : public CanMakeCheckedPtr {
     61class Scope : public CanMakeWeakPtr<Scope> {
    6262    WTF_MAKE_FAST_ALLOCATED;
    6363public:
    … …  
    138138    void scheduleUpdate(UpdateType);
    139139
    140     using ResolverScopes = HashMap<Ref<Resolver>, Vector<CheckedPtr<Scope>>>;
     140    using ResolverScopes = HashMap<Ref<Resolver>, Vector<WeakPtr<Scope>>>;
    141141    ResolverScopes collectResolverScopes();
    142142    template <typename TestFunction> void evaluateMediaQueries(TestFunction&&);
Note: See TracChangeset for help on using the changeset viewer.