Title: [293232] trunk/Source/WebCore
Revision
293232
Author
[email protected]
Date
2022-04-22 11:02:38 -0700 (Fri, 22 Apr 2022)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293231 => 293232)


--- trunk/Source/WebCore/ChangeLog	2022-04-22 17:46:54 UTC (rev 293231)
+++ trunk/Source/WebCore/ChangeLog	2022-04-22 18:02:38 UTC (rev 293232)
@@ -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-04-22  Alan Bujtas  <[email protected]>
 
         [LFC][Integration] BoxTree should be able to build non-inline content tree

Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (293231 => 293232)


--- trunk/Source/WebCore/css/CSSStyleSheet.cpp	2022-04-22 17:46:54 UTC (rev 293231)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp	2022-04-22 18:02:38 UTC (rev 293232)
@@ -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: trunk/Source/WebCore/css/CSSStyleSheet.h (293231 => 293232)


--- trunk/Source/WebCore/css/CSSStyleSheet.h	2022-04-22 17:46:54 UTC (rev 293231)
+++ trunk/Source/WebCore/css/CSSStyleSheet.h	2022-04-22 18:02:38 UTC (rev 293232)
@@ -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: trunk/Source/WebCore/style/StyleScope.cpp (293231 => 293232)


--- trunk/Source/WebCore/style/StyleScope.cpp	2022-04-22 17:46:54 UTC (rev 293231)
+++ trunk/Source/WebCore/style/StyleScope.cpp	2022-04-22 18:02:38 UTC (rev 293232)
@@ -685,7 +685,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();
@@ -692,7 +692,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: trunk/Source/WebCore/style/StyleScope.h (293231 => 293232)


--- trunk/Source/WebCore/style/StyleScope.h	2022-04-22 17:46:54 UTC (rev 293231)
+++ trunk/Source/WebCore/style/StyleScope.h	2022-04-22 18:02:38 UTC (rev 293232)
@@ -60,7 +60,7 @@
 
 class Resolver;
 
-class Scope : public CanMakeCheckedPtr {
+class Scope : public CanMakeWeakPtr<Scope> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     explicit Scope(Document&);
@@ -144,7 +144,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