Title: [250768] trunk/Source/WebCore
Revision
250768
Author
[email protected]
Date
2019-10-06 02:57:42 -0700 (Sun, 06 Oct 2019)

Log Message

Node::ref/deref should be const
https://bugs.webkit.org/show_bug.cgi?id=202562

Reviewed by Ryosuke Niwa.

This enables RefPtr<const Element> and matches RefCounted.

* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::collectMatchingRules):
(WebCore::ElementRuleCollector::matchAuthorRules):
(WebCore::ElementRuleCollector::matchAuthorShadowPseudoElementRules):
(WebCore::ElementRuleCollector::matchHostPseudoClassRules):
(WebCore::ElementRuleCollector::matchSlottedPseudoElementRules):
(WebCore::ElementRuleCollector::matchPartPseudoElementRules):
(WebCore::ElementRuleCollector::collectMatchingShadowPseudoElementRules):
(WebCore::ElementRuleCollector::collectSlottedPseudoElementRulesForSlot):
(WebCore::ElementRuleCollector::matchUARules):
(WebCore::ElementRuleCollector::ruleMatches):
(WebCore::ElementRuleCollector::matchAllRules):

Use it to ref elements in ElementRuleCollector.

* css/ElementRuleCollector.h:
(WebCore::ElementRuleCollector::element const):
* dom/Node.h:
(WebCore::Node::ref const):
(WebCore::Node::deref const):
(WebCore::Node::ref): Deleted.
(WebCore::Node::deref): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (250767 => 250768)


--- trunk/Source/WebCore/ChangeLog	2019-10-05 17:35:41 UTC (rev 250767)
+++ trunk/Source/WebCore/ChangeLog	2019-10-06 09:57:42 UTC (rev 250768)
@@ -1,3 +1,35 @@
+2019-10-06  Antti Koivisto  <[email protected]>
+
+        Node::ref/deref should be const
+        https://bugs.webkit.org/show_bug.cgi?id=202562
+
+        Reviewed by Ryosuke Niwa.
+
+        This enables RefPtr<const Element> and matches RefCounted.
+
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::collectMatchingRules):
+        (WebCore::ElementRuleCollector::matchAuthorRules):
+        (WebCore::ElementRuleCollector::matchAuthorShadowPseudoElementRules):
+        (WebCore::ElementRuleCollector::matchHostPseudoClassRules):
+        (WebCore::ElementRuleCollector::matchSlottedPseudoElementRules):
+        (WebCore::ElementRuleCollector::matchPartPseudoElementRules):
+        (WebCore::ElementRuleCollector::collectMatchingShadowPseudoElementRules):
+        (WebCore::ElementRuleCollector::collectSlottedPseudoElementRulesForSlot):
+        (WebCore::ElementRuleCollector::matchUARules):
+        (WebCore::ElementRuleCollector::ruleMatches):
+        (WebCore::ElementRuleCollector::matchAllRules):
+
+        Use it to ref elements in ElementRuleCollector.
+
+        * css/ElementRuleCollector.h:
+        (WebCore::ElementRuleCollector::element const):
+        * dom/Node.h:
+        (WebCore::Node::ref const):
+        (WebCore::Node::deref const):
+        (WebCore::Node::ref): Deleted.
+        (WebCore::Node::deref): Deleted.
+
 2019-10-05  Zalan Bujtas  <[email protected]>
 
         [LFC] LayoutChildtIteratorAdapter -> LayoutChildIteratorAdapter

Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (250767 => 250768)


--- trunk/Source/WebCore/css/ElementRuleCollector.cpp	2019-10-05 17:35:41 UTC (rev 250767)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp	2019-10-06 09:57:42 UTC (rev 250768)
@@ -142,25 +142,25 @@
     ASSERT(matchRequest.ruleSet);
     ASSERT_WITH_MESSAGE(!(m_mode == SelectorChecker::Mode::CollectingRulesIgnoringVirtualPseudoElements && m_pseudoStyleRequest.pseudoId != PseudoId::None), "When in StyleInvalidation or SharingRules, SelectorChecker does not try to match the pseudo ID. While ElementRuleCollector supports matching a particular pseudoId in this case, this would indicate a error at the call site since matching a particular element should be unnecessary.");
 
-    auto* shadowRoot = m_element.containingShadowRoot();
+    auto* shadowRoot = element().containingShadowRoot();
     if (shadowRoot && shadowRoot->mode() == ShadowRootMode::UserAgent)
         collectMatchingShadowPseudoElementRules(matchRequest, ruleRange);
 
     // We need to collect the rules for id, class, tag, and everything else into a buffer and
     // then sort the buffer.
-    auto& id = m_element.idForStyleResolution();
+    auto& id = element().idForStyleResolution();
     if (!id.isNull())
         collectMatchingRulesForList(matchRequest.ruleSet->idRules(id), matchRequest, ruleRange);
-    if (m_element.hasClass()) {
-        for (size_t i = 0; i < m_element.classNames().size(); ++i)
-            collectMatchingRulesForList(matchRequest.ruleSet->classRules(m_element.classNames()[i]), matchRequest, ruleRange);
+    if (element().hasClass()) {
+        for (size_t i = 0; i < element().classNames().size(); ++i)
+            collectMatchingRulesForList(matchRequest.ruleSet->classRules(element().classNames()[i]), matchRequest, ruleRange);
     }
 
-    if (m_element.isLink())
+    if (element().isLink())
         collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, ruleRange);
-    if (SelectorChecker::matchesFocusPseudoClass(m_element))
+    if (SelectorChecker::matchesFocusPseudoClass(element()))
         collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, ruleRange);
-    collectMatchingRulesForList(matchRequest.ruleSet->tagRules(m_element.localName(), m_element.isHTMLElement() && m_element.document().isHTMLDocument()), matchRequest, ruleRange);
+    collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element().localName(), element().isHTMLElement() && element().document().isHTMLDocument()), matchRequest, ruleRange);
     collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), matchRequest, ruleRange);
 }
 
@@ -194,18 +194,18 @@
         collectMatchingRules(matchRequest, ruleRange);
     }
 
-    auto* parent = m_element.parentElement();
+    auto* parent = element().parentElement();
     if (parent && parent->shadowRoot())
         matchSlottedPseudoElementRules(includeEmptyRules, ruleRange);
 
-    if (m_element.shadowRoot())
+    if (element().shadowRoot())
         matchHostPseudoClassRules(includeEmptyRules, ruleRange);
 
-    if (m_element.isInShadowTree()) {
+    if (element().isInShadowTree()) {
         matchAuthorShadowPseudoElementRules(includeEmptyRules, ruleRange);
 
-        if (!m_element.partNames().isEmpty())
-            matchPartPseudoElementRules(*m_element.containingShadowRoot(), includeEmptyRules, ruleRange);
+        if (!element().partNames().isEmpty())
+            matchPartPseudoElementRules(*element().containingShadowRoot(), includeEmptyRules, ruleRange);
     }
 
     sortAndTransferMatchedRules();
@@ -213,8 +213,8 @@
 
 void ElementRuleCollector::matchAuthorShadowPseudoElementRules(bool includeEmptyRules, StyleResolver::RuleRange& ruleRange)
 {
-    ASSERT(m_element.isInShadowTree());
-    auto& shadowRoot = *m_element.containingShadowRoot();
+    ASSERT(element().isInShadowTree());
+    auto& shadowRoot = *element().containingShadowRoot();
     if (shadowRoot.mode() != ShadowRootMode::UserAgent)
         return;
     // Look up shadow pseudo elements also from the host scope author style as they are web-exposed.
@@ -225,9 +225,9 @@
 
 void ElementRuleCollector::matchHostPseudoClassRules(bool includeEmptyRules, StyleResolver::RuleRange& ruleRange)
 {
-    ASSERT(m_element.shadowRoot());
+    ASSERT(element().shadowRoot());
 
-    auto& shadowAuthorStyle = m_element.shadowRoot()->styleScope().resolver().ruleSets().authorStyle();
+    auto& shadowAuthorStyle = element().shadowRoot()->styleScope().resolver().ruleSets().authorStyle();
     auto& shadowHostRules = shadowAuthorStyle.hostPseudoClassRules();
     if (shadowHostRules.isEmpty())
         return;
@@ -240,7 +240,7 @@
 
 void ElementRuleCollector::matchSlottedPseudoElementRules(bool includeEmptyRules, StyleResolver::RuleRange& ruleRange)
 {
-    auto* slot = m_element.assignedSlot();
+    auto* slot = element().assignedSlot();
     auto styleScopeOrdinal = Style::ScopeOrdinal::FirstSlot;
 
     for (; slot; slot = slot->assignedSlot(), ++styleScopeOrdinal) {
@@ -265,12 +265,12 @@
 
 void ElementRuleCollector::matchPartPseudoElementRules(const ShadowRoot& containingShadowRoot, bool includeEmptyRules, StyleResolver::RuleRange& ruleRange)
 {
-    ASSERT(m_element.isInShadowTree());
-    ASSERT(!m_element.partNames().isEmpty());
+    ASSERT(element().isInShadowTree());
+    ASSERT(!element().partNames().isEmpty());
 
     auto& shadowHost = *containingShadowRoot.host();
     {
-        SetForScope<const Element*> partMatchingScope(m_shadowHostInPartRuleScope, &shadowHost);
+        SetForScope<RefPtr<const Element>> partMatchingScope(m_shadowHostInPartRuleScope, &shadowHost);
 
         auto& hostAuthorRules = Style::Scope::forNode(shadowHost).resolver().ruleSets().authorStyle();
         MatchRequest hostAuthorRequest { &hostAuthorRules, includeEmptyRules, Style::ScopeOrdinal::ContainingHost };
@@ -288,15 +288,15 @@
 void ElementRuleCollector::collectMatchingShadowPseudoElementRules(const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
 {
     ASSERT(matchRequest.ruleSet);
-    ASSERT(m_element.containingShadowRoot()->mode() == ShadowRootMode::UserAgent);
+    ASSERT(element().containingShadowRoot()->mode() == ShadowRootMode::UserAgent);
 
     auto& rules = *matchRequest.ruleSet;
 #if ENABLE(VIDEO_TRACK)
     // FXIME: WebVTT should not be done by styling UA shadow trees like this.
-    if (m_element.isWebVTTElement())
+    if (element().isWebVTTElement())
         collectMatchingRulesForList(rules.cuePseudoRules(), matchRequest, ruleRange);
 #endif
-    auto& pseudoId = m_element.shadowPseudoId();
+    auto& pseudoId = element().shadowPseudoId();
     if (!pseudoId.isEmpty())
         collectMatchingRulesForList(rules.shadowPseudoElementRules(pseudoId), matchRequest, ruleRange);
 }
@@ -303,7 +303,7 @@
 
 std::unique_ptr<RuleSet::RuleDataVector> ElementRuleCollector::collectSlottedPseudoElementRulesForSlot(bool includeEmptyRules)
 {
-    ASSERT(is<HTMLSlotElement>(m_element));
+    ASSERT(is<HTMLSlotElement>(element()));
 
     clearMatchedRules();
 
@@ -350,7 +350,7 @@
     matchUARules(*userAgentStyleSheet);
 
     // In quirks mode, we match rules from the quirks user agent sheet.
-    if (m_element.document().inQuirksMode())
+    if (element().document().inQuirksMode())
         matchUARules(*CSSDefaultStyleSheets::defaultQuirksStyle);
 
     if (m_userAgentMediaQueryStyle)
@@ -385,7 +385,7 @@
     // We know a sufficiently simple single part selector matches simply because we found it from the rule hash when filtering the RuleSet.
     // This is limited to HTML only so we don't need to check the namespace (because of tag name match).
     MatchBasedOnRuleHash matchBasedOnRuleHash = ruleData.matchBasedOnRuleHash();
-    if (matchBasedOnRuleHash != MatchBasedOnRuleHash::None && m_element.isHTMLElement()) {
+    if (matchBasedOnRuleHash != MatchBasedOnRuleHash::None && element().isHTMLElement()) {
         ASSERT_WITH_MESSAGE(m_pseudoStyleRequest.pseudoId == PseudoId::None, "If we match based on the rule hash while collecting for a particular pseudo element ID, we would add incorrect rules for that pseudo element ID. We should never end in ruleMatches() with a pseudo element if the ruleData cannot match any pseudo element.");
 
         switch (matchBasedOnRuleHash) {
@@ -421,12 +421,12 @@
         auto selectorChecker = SelectorCompiler::ruleCollectorSimpleSelectorCheckerFunction(compiledSelectorChecker, compiledSelector.status);
 #if !ASSERT_MSG_DISABLED
         unsigned ignoreSpecificity;
-        ASSERT_WITH_MESSAGE(!selectorChecker(&m_element, &ignoreSpecificity) || m_pseudoStyleRequest.pseudoId == PseudoId::None, "When matching pseudo elements, we should never compile a selector checker without context unless it cannot match anything.");
+        ASSERT_WITH_MESSAGE(!selectorChecker(&element(), &ignoreSpecificity) || m_pseudoStyleRequest.pseudoId == PseudoId::None, "When matching pseudo elements, we should never compile a selector checker without context unless it cannot match anything.");
 #endif
 #if CSS_SELECTOR_JIT_PROFILING
         ruleData.compiledSelectorUsed();
 #endif
-        bool selectorMatches = selectorChecker(&m_element, &specificity);
+        bool selectorMatches = selectorChecker(&element(), &specificity);
 
         if (selectorMatches && ruleData.containsUncommonAttributeSelector())
             m_didMatchUncommonAttributeSelector = true;
@@ -440,7 +440,7 @@
     context.scrollbar = m_pseudoStyleRequest.scrollbar;
     context.scrollbarPart = m_pseudoStyleRequest.scrollbarPart;
     context.isMatchingHostPseudoClass = m_isMatchingHostPseudoClass;
-    context.shadowHostInPartRuleScope = m_shadowHostInPartRuleScope;
+    context.shadowHostInPartRuleScope = m_shadowHostInPartRuleScope.get();
 
     bool selectorMatches;
 #if ENABLE(CSS_SELECTOR_JIT)
@@ -452,7 +452,7 @@
 #if CSS_SELECTOR_JIT_PROFILING
         compiledSelector.useCount++;
 #endif
-        selectorMatches = selectorChecker(&m_element, &context, &specificity);
+        selectorMatches = selectorChecker(&element(), &context, &specificity);
     } else
 #endif // ENABLE(CSS_SELECTOR_JIT)
     {
@@ -463,8 +463,8 @@
                 return false;
         }
         // Slow path.
-        SelectorChecker selectorChecker(m_element.document());
-        selectorMatches = selectorChecker.match(*selector, m_element, context, specificity);
+        SelectorChecker selectorChecker(element().document());
+        selectorMatches = selectorChecker.match(*selector, element(), context, specificity);
     }
 
     if (ruleData.containsUncommonAttributeSelector()) {
@@ -532,8 +532,8 @@
         matchUserRules(false);
 
     // Now check author rules, beginning first with presentational attributes mapped from HTML.
-    if (is<StyledElement>(m_element)) {
-        auto& styledElement = downcast<StyledElement>(m_element);
+    if (is<StyledElement>(element())) {
+        auto& styledElement = downcast<StyledElement>(element());
         addElementStyleProperties(styledElement.presentationAttributeStyle());
 
         // Now we check additional mapped declarations.
@@ -553,8 +553,8 @@
     if (matchAuthorAndUserStyles)
         matchAuthorRules(false);
 
-    if (matchAuthorAndUserStyles && is<StyledElement>(m_element)) {
-        auto& styledElement = downcast<StyledElement>(m_element);
+    if (matchAuthorAndUserStyles && is<StyledElement>(element())) {
+        auto& styledElement = downcast<StyledElement>(element());
         // Now check our inline style attribute.
         if (styledElement.inlineStyle()) {
             // Inline style is immutable as long as there is no CSSOM wrapper.

Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (250767 => 250768)


--- trunk/Source/WebCore/css/ElementRuleCollector.h	2019-10-05 17:35:41 UTC (rev 250767)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h	2019-10-06 09:57:42 UTC (rev 250768)
@@ -89,7 +89,9 @@
 
     void addMatchedRule(const RuleData&, unsigned specificity, Style::ScopeOrdinal, StyleResolver::RuleRange&);
 
-    const Element& m_element;
+    const Element& element() const { return m_element.get(); }
+
+    const Ref<const Element> m_element;
     const RuleSet& m_authorStyle;
     const RuleSet* m_userStyle { nullptr };
     const RuleSet* m_userAgentMediaQueryStyle { nullptr };
@@ -100,7 +102,7 @@
     SelectorChecker::Mode m_mode { SelectorChecker::Mode::ResolvingStyle };
     bool m_isMatchingSlottedPseudoElements { false };
     bool m_isMatchingHostPseudoClass { false };
-    const Element* m_shadowHostInPartRuleScope { nullptr };
+    RefPtr<const Element> m_shadowHostInPartRuleScope;
     Vector<std::unique_ptr<RuleSet::RuleDataVector>> m_keepAliveSlottedPseudoElementRules;
 
     Vector<MatchedRule, 64> m_matchedRules;

Modified: trunk/Source/WebCore/dom/Node.h (250767 => 250768)


--- trunk/Source/WebCore/dom/Node.h	2019-10-05 17:35:41 UTC (rev 250767)
+++ trunk/Source/WebCore/dom/Node.h	2019-10-06 09:57:42 UTC (rev 250768)
@@ -477,14 +477,14 @@
     // Perform the default action for an event.
     virtual void defaultEventHandler(Event&);
 
-    void ref();
-    void deref();
+    void ref() const;
+    void deref() const;
     bool hasOneRef() const;
     unsigned refCount() const;
 
 #ifndef NDEBUG
     bool m_deletionHasBegun { false };
-    bool m_inRemovedLastRefFunction { false };
+    mutable bool m_inRemovedLastRefFunction { false };
     bool m_adoptionIsRequired { true };
 #endif
 
@@ -668,7 +668,7 @@
         void operator()(NodeRareData*) const;
     };
 
-    uint32_t m_refCountAndParentBit { s_refCountIncrement };
+    mutable uint32_t m_refCountAndParentBit { s_refCountIncrement };
     mutable uint32_t m_nodeFlags;
 
     ContainerNode* m_parentNode { nullptr };
@@ -690,7 +690,7 @@
 }
 #endif
 
-ALWAYS_INLINE void Node::ref()
+ALWAYS_INLINE void Node::ref() const
 {
     ASSERT(isMainThread());
     ASSERT(!m_deletionHasBegun);
@@ -699,7 +699,7 @@
     m_refCountAndParentBit += s_refCountIncrement;
 }
 
-ALWAYS_INLINE void Node::deref()
+ALWAYS_INLINE void Node::deref() const
 {
     ASSERT(isMainThread());
     ASSERT(refCount());
@@ -713,7 +713,7 @@
 #ifndef NDEBUG
         m_inRemovedLastRefFunction = true;
 #endif
-        removedLastRef();
+        const_cast<Node&>(*this).removedLastRef();
         return;
     }
     m_refCountAndParentBit = updatedRefCount;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to