Title: [295196] branches/safari-613-branch/Source/WebCore
Revision
295196
Author
[email protected]
Date
2022-06-02 23:46:05 -0700 (Thu, 02 Jun 2022)

Log 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

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (295195 => 295196)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-06-03 06:46:01 UTC (rev 295195)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-06-03 06:46:05 UTC (rev 295196)
@@ -1,3 +1,23 @@
+2022-04-22  Brandon Stewart  <[email protected]>
+
+        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:
+
 2022-03-15  Gabriel Nava Marino  <[email protected]>
 
         Crash in KeyframeList.cpp:183 in WebCore::KeyframeList::fillImplicitKeyframes

Modified: branches/safari-613-branch/Source/WebCore/css/CSSStyleSheet.cpp (295195 => 295196)


--- branches/safari-613-branch/Source/WebCore/css/CSSStyleSheet.cpp	2022-06-03 06:46:01 UTC (rev 295195)
+++ branches/safari-613-branch/Source/WebCore/css/CSSStyleSheet.cpp	2022-06-03 06:46:05 UTC (rev 295196)
@@ -92,6 +92,9 @@
     : m_contents(WTFMove(contents))
     , m_ownerRule(ownerRule)
 {
+    if (auto* parent = parentStyleSheet())
+        m_styleScope = parent->styleScope();
+
     m_contents->registerClient(this);
 }
 
@@ -99,6 +102,7 @@
     : m_contents(WTFMove(contents))
     , m_isInlineStylesheet(isInlineStylesheet)
     , m_isOriginClean(isOriginClean)
+    , m_styleScope(Style::Scope::forNode(ownerNode))
     , m_ownerNode(&ownerNode)
     , m_startPosition(startPosition)
 {
@@ -379,10 +383,7 @@
 
 Style::Scope* CSSStyleSheet::styleScope()
 {
-    auto* ownerNode = rootStyleSheet().ownerNode();
-    if (!ownerNode)
-        return nullptr;
-    return &Style::Scope::forNode(*ownerNode);
+    return m_styleScope.get();
 }
 
 void CSSStyleSheet::clearChildRuleCSSOMWrappers()

Modified: branches/safari-613-branch/Source/WebCore/css/CSSStyleSheet.h (295195 => 295196)


--- branches/safari-613-branch/Source/WebCore/css/CSSStyleSheet.h	2022-06-03 06:46:01 UTC (rev 295195)
+++ branches/safari-613-branch/Source/WebCore/css/CSSStyleSheet.h	2022-06-03 06:46:05 UTC (rev 295196)
@@ -26,6 +26,7 @@
 #include <memory>
 #include <wtf/Noncopyable.h>
 #include <wtf/TypeCasts.h>
+#include <wtf/WeakPtr.h>
 #include <wtf/text/AtomStringHash.h>
 #include <wtf/text/TextPosition.h>
 
@@ -147,6 +148,7 @@
     std::optional<bool> m_isOriginClean;
     String m_title;
     RefPtr<MediaQuerySet> m_mediaQueries;
+    WeakPtr<Style::Scope> m_styleScope;
 
     Node* m_ownerNode { nullptr };
     CSSImportRule* m_ownerRule { nullptr };

Modified: branches/safari-613-branch/Source/WebCore/style/StyleScope.cpp (295195 => 295196)


--- branches/safari-613-branch/Source/WebCore/style/StyleScope.cpp	2022-06-03 06:46:01 UTC (rev 295195)
+++ branches/safari-613-branch/Source/WebCore/style/StyleScope.cpp	2022-06-03 06:46:05 UTC (rev 295196)
@@ -683,7 +683,7 @@
 
     ResolverScopes resolverScopes;
 
-    resolverScopes.add(*resolverIfExists(), Vector<CheckedPtr<Scope>> { this });
+    resolverScopes.add(*resolverIfExists(), Vector<WeakPtr<Scope>> { this });
 
     for (auto* shadowRoot : m_document.inDocumentShadowRoots()) {
         auto& scope = shadowRoot->styleScope();
@@ -690,7 +690,7 @@
         auto* resolver = scope.resolverIfExists();
         if (!resolver)
             continue;
-        resolverScopes.add(*resolver, Vector<CheckedPtr<Scope>> { }).iterator->value.append(&scope);
+        resolverScopes.add(*resolver, Vector<WeakPtr<Scope>> { }).iterator->value.append(&scope);
     }
     return resolverScopes;
 }

Modified: branches/safari-613-branch/Source/WebCore/style/StyleScope.h (295195 => 295196)


--- branches/safari-613-branch/Source/WebCore/style/StyleScope.h	2022-06-03 06:46:01 UTC (rev 295195)
+++ branches/safari-613-branch/Source/WebCore/style/StyleScope.h	2022-06-03 06:46:05 UTC (rev 295196)
@@ -58,7 +58,7 @@
 
 class Resolver;
 
-class Scope : public CanMakeCheckedPtr {
+class Scope : public CanMakeWeakPtr<Scope> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     explicit Scope(Document&);
@@ -137,7 +137,7 @@
     void updateActiveStyleSheets(UpdateType);
     void scheduleUpdate(UpdateType);
 
-    using ResolverScopes = HashMap<Ref<Resolver>, Vector<CheckedPtr<Scope>>>;
+    using ResolverScopes = HashMap<Ref<Resolver>, Vector<WeakPtr<Scope>>>;
     ResolverScopes collectResolverScopes();
     template <typename TestFunction> void evaluateMediaQueries(TestFunction&&);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to