Title: [266776] trunk/Source
Revision
266776
Author
[email protected]
Date
2020-09-09 02:03:48 -0700 (Wed, 09 Sep 2020)

Log Message

Node flags should be an OptionSet
https://bugs.webkit.org/show_bug.cgi?id=216305

Reviewed by Antti Koivisto.

Source/WebCore:

This patch renames NodeFlags to NodeFlag and turns into an enum class and changes the type of
m_nodeFlags from uint32_t to OptionSet<NodeFlag> as there is no state stored there after r266769.

This patch also introduces two new NodeFlag for identifying CharacterData and DocumentFragment
to simplify the type check conditions for these nodes now that we have plenty of free bits.

No new tests since there should be no behavioral change.

* dom/CharacterData.h:
(WebCore::CharacterData::CharacterData): Sets NodeFlag::IsContainerNode via CreateCharacterData.
(WebCore::CharacterData::virtualIsCharacterData): Deleted.
* dom/Comment.cpp:
(WebCore::Comment::Comment): Ditto.
* dom/Element.cpp:
(WebCore::Element::setHasFocusWithin):
(WebCore::Element::removedFromAncestor):
(WebCore::Element::setContainsFullScreenElement):
(WebCore::Element::createElementIdentifier):
* dom/Element.h:
(WebCore::Element::hasFocusWithin const):
(WebCore::Element::hasPendingResources const):
(WebCore::Element::setHasPendingResources):
(WebCore::Element::clearHasPendingResources):
(WebCore::Element::hasCSSAnimation const):
(WebCore::Element::setHasCSSAnimation):
(WebCore::Element::clearHasCSSAnimation):
(WebCore::Element::containsFullScreenElement const):
* dom/Node.cpp:
(WebCore::Node::insertedIntoAncestor):
(WebCore::Node::removedFromAncestor):
* dom/Node.h:
(WebCore::Node::isElementNode const):
(WebCore::Node::isContainerNode const):
(WebCore::Node::isTextNode const):
(WebCore::Node::isHTMLElement const):
(WebCore::Node::isSVGElement const):
(WebCore::Node::isMathMLElement const):
(WebCore::Node::isStyledElement const):
(WebCore::Node::isCharacterDataNode const): Check the newly added NodeFlag::IsContainerNode.
(WebCore::Node::isDocumentNode const):
(WebCore::Node::isTreeScope const):
(WebCore::Node::isDocumentFragment const):: Check the newly added NodeFlag::IsDocumentFragment.
(WebCore::Node::isShadowRoot const):
(WebCore::Node::hasCustomStyleResolveCallbacks const):
(WebCore::Node::hasSyntheticAttrChildNodes const):
(WebCore::Node::setHasSyntheticAttrChildNodes):
(WebCore::Node::selfOrAncestorHasDirAutoAttribute const):
(WebCore::Node::setSelfOrAncestorHasDirAutoAttribute):
(WebCore::Node::isUserActionElement const):
(WebCore::Node::setUserActionElement):
(WebCore::Node::isEditingText const): Removed the check for IsTextFlag since this is no longer needed
after r266769 as no longer share the bit for IsEditingText with an unknown custom element.
(WebCore::Node::isLink const):
(WebCore::Node::setIsLink):
(WebCore::Node::hasEventTargetData const):
(WebCore::Node::setHasEventTargetData):
(WebCore::Node::isConnected const):
(WebCore::Node::isInShadowTree const):
(WebCore::Node::isInTreeScope const):
(WebCore::Node::flagIsText):
(WebCore::Node::flagIsContainer):
(WebCore::Node::flagIsElement):
(WebCore::Node::flagIsShadowRoot):
(WebCore::Node::flagIsHTML):
(WebCore::Node::flagIsLink):
(WebCore::Node::flagHasFocusWithin):
(WebCore::Node::flagIsParsingChildrenFinished):
(WebCore::Node::NodeFlag): Renamed from NodeFlags and made it an enum class, and introduced IsCharacterData
and IsDocumentFragment and removed "Flag" suffix from various flags.
(WebCore::Node::hasNodeFlag const): Renamed from getFlag for clarity.
(WebCore::Node::setNodeFlag const): Ditto from setFlag. Also merge the two versions of setFlag one of which
took a boolean arugment as the first argument by making this a second optional argument.
(WebCore::Node::clearNodeFlag const): Ditto.
(WebCore::Node::isParsingChildrenFinished const):
(WebCore::Node::setIsParsingChildrenFinished):
(WebCore::Node::clearIsParsingChildrenFinished):
(WebCore::Node::ConstructionType): This is now an alias to OptionSet<NodeFlag> instead of a separate enum.
(WebCore::Node::setHasCustomStyleResolveCallbacks):
(WebCore::Node::virtualIsCharacterData const): Deleted.
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::ProcessingInstruction): Sets NodeFlag::IsContainerNode via CharacterData's
constructor's default argument value.

Source/WTF:

* wtf/OptionSet.h:
(WTF::OptionSet::set): Added.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (266775 => 266776)


--- trunk/Source/WTF/ChangeLog	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WTF/ChangeLog	2020-09-09 09:03:48 UTC (rev 266776)
@@ -1,3 +1,13 @@
+2020-09-08  Ryosuke Niwa  <[email protected]>
+
+        Node flags should be an OptionSet
+        https://bugs.webkit.org/show_bug.cgi?id=216305
+
+        Reviewed by Antti Koivisto.
+
+        * wtf/OptionSet.h:
+        (WTF::OptionSet::set): Added.
+
 2020-09-06  Ryosuke Niwa  <[email protected]>
 
         Make CompactUniquePtrTuple actually work with subclassing and custom deleter

Modified: trunk/Source/WTF/wtf/OptionSet.h (266775 => 266776)


--- trunk/Source/WTF/wtf/OptionSet.h	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WTF/wtf/OptionSet.h	2020-09-09 09:03:48 UTC (rev 266776)
@@ -193,6 +193,11 @@
         m_storage &= ~optionSet.m_storage;
     }
 
+    constexpr void set(OptionSet optionSet, bool value)
+    {
+        m_storage = (m_storage & ~optionSet.m_storage) | (-static_cast<StorageType>(value) & optionSet.m_storage);
+    }
+
     constexpr bool hasExactlyOneBitSet() const
     {
         return m_storage && !(m_storage & (m_storage - 1));

Modified: trunk/Source/WebCore/ChangeLog (266775 => 266776)


--- trunk/Source/WebCore/ChangeLog	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WebCore/ChangeLog	2020-09-09 09:03:48 UTC (rev 266776)
@@ -1,5 +1,95 @@
 2020-09-08  Ryosuke Niwa  <[email protected]>
 
+        Node flags should be an OptionSet
+        https://bugs.webkit.org/show_bug.cgi?id=216305
+
+        Reviewed by Antti Koivisto.
+
+        This patch renames NodeFlags to NodeFlag and turns into an enum class and changes the type of
+        m_nodeFlags from uint32_t to OptionSet<NodeFlag> as there is no state stored there after r266769.
+
+        This patch also introduces two new NodeFlag for identifying CharacterData and DocumentFragment
+        to simplify the type check conditions for these nodes now that we have plenty of free bits.
+
+        No new tests since there should be no behavioral change.
+
+        * dom/CharacterData.h:
+        (WebCore::CharacterData::CharacterData): Sets NodeFlag::IsContainerNode via CreateCharacterData.
+        (WebCore::CharacterData::virtualIsCharacterData): Deleted.
+        * dom/Comment.cpp:
+        (WebCore::Comment::Comment): Ditto.
+        * dom/Element.cpp:
+        (WebCore::Element::setHasFocusWithin):
+        (WebCore::Element::removedFromAncestor):
+        (WebCore::Element::setContainsFullScreenElement):
+        (WebCore::Element::createElementIdentifier):
+        * dom/Element.h:
+        (WebCore::Element::hasFocusWithin const):
+        (WebCore::Element::hasPendingResources const):
+        (WebCore::Element::setHasPendingResources):
+        (WebCore::Element::clearHasPendingResources):
+        (WebCore::Element::hasCSSAnimation const):
+        (WebCore::Element::setHasCSSAnimation):
+        (WebCore::Element::clearHasCSSAnimation):
+        (WebCore::Element::containsFullScreenElement const):
+        * dom/Node.cpp:
+        (WebCore::Node::insertedIntoAncestor):
+        (WebCore::Node::removedFromAncestor):
+        * dom/Node.h:
+        (WebCore::Node::isElementNode const):
+        (WebCore::Node::isContainerNode const):
+        (WebCore::Node::isTextNode const):
+        (WebCore::Node::isHTMLElement const):
+        (WebCore::Node::isSVGElement const):
+        (WebCore::Node::isMathMLElement const):
+        (WebCore::Node::isStyledElement const):
+        (WebCore::Node::isCharacterDataNode const): Check the newly added NodeFlag::IsContainerNode.
+        (WebCore::Node::isDocumentNode const):
+        (WebCore::Node::isTreeScope const):
+        (WebCore::Node::isDocumentFragment const):: Check the newly added NodeFlag::IsDocumentFragment.
+        (WebCore::Node::isShadowRoot const):
+        (WebCore::Node::hasCustomStyleResolveCallbacks const):
+        (WebCore::Node::hasSyntheticAttrChildNodes const):
+        (WebCore::Node::setHasSyntheticAttrChildNodes):
+        (WebCore::Node::selfOrAncestorHasDirAutoAttribute const):
+        (WebCore::Node::setSelfOrAncestorHasDirAutoAttribute):
+        (WebCore::Node::isUserActionElement const):
+        (WebCore::Node::setUserActionElement):
+        (WebCore::Node::isEditingText const): Removed the check for IsTextFlag since this is no longer needed
+        after r266769 as no longer share the bit for IsEditingText with an unknown custom element.
+        (WebCore::Node::isLink const):
+        (WebCore::Node::setIsLink):
+        (WebCore::Node::hasEventTargetData const):
+        (WebCore::Node::setHasEventTargetData):
+        (WebCore::Node::isConnected const):
+        (WebCore::Node::isInShadowTree const):
+        (WebCore::Node::isInTreeScope const):
+        (WebCore::Node::flagIsText):
+        (WebCore::Node::flagIsContainer):
+        (WebCore::Node::flagIsElement):
+        (WebCore::Node::flagIsShadowRoot):
+        (WebCore::Node::flagIsHTML):
+        (WebCore::Node::flagIsLink):
+        (WebCore::Node::flagHasFocusWithin):
+        (WebCore::Node::flagIsParsingChildrenFinished):
+        (WebCore::Node::NodeFlag): Renamed from NodeFlags and made it an enum class, and introduced IsCharacterData
+        and IsDocumentFragment and removed "Flag" suffix from various flags.
+        (WebCore::Node::hasNodeFlag const): Renamed from getFlag for clarity.
+        (WebCore::Node::setNodeFlag const): Ditto from setFlag. Also merge the two versions of setFlag one of which
+        took a boolean arugment as the first argument by making this a second optional argument.
+        (WebCore::Node::clearNodeFlag const): Ditto.
+        (WebCore::Node::isParsingChildrenFinished const):
+        (WebCore::Node::setIsParsingChildrenFinished):
+        (WebCore::Node::clearIsParsingChildrenFinished):
+        (WebCore::Node::ConstructionType): This is now an alias to OptionSet<NodeFlag> instead of a separate enum.
+        (WebCore::Node::setHasCustomStyleResolveCallbacks):
+        (WebCore::Node::virtualIsCharacterData const): Deleted.
+        * dom/ProcessingInstruction.cpp:
+        (WebCore::ProcessingInstruction::ProcessingInstruction): Sets NodeFlag::IsContainerNode via CharacterData's
+        constructor's default argument value.
+
+2020-09-08  Ryosuke Niwa  <[email protected]>
+
         Having an iframe as a descendent node shouldn't require ElementRareData
         https://bugs.webkit.org/show_bug.cgi?id=216264
 

Modified: trunk/Source/WebCore/dom/CharacterData.h (266775 => 266776)


--- trunk/Source/WebCore/dom/CharacterData.h	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WebCore/dom/CharacterData.h	2020-09-09 09:03:48 UTC (rev 266776)
@@ -46,11 +46,11 @@
     unsigned parserAppendData(const String& string, unsigned offset, unsigned lengthLimit);
 
 protected:
-    CharacterData(Document& document, const String& text, ConstructionType type)
+    CharacterData(Document& document, const String& text, ConstructionType type = CreateCharacterData)
         : Node(document, type)
         , m_data(!text.isNull() ? text : emptyString())
     {
-        ASSERT(type == CreateOther || type == CreateText || type == CreateEditingText);
+        ASSERT(type == CreateCharacterData || type == CreateText || type == CreateEditingText);
     }
 
     void setDataWithoutUpdate(const String& data)
@@ -63,7 +63,6 @@
 private:
     String nodeValue() const final;
     ExceptionOr<void> setNodeValue(const String&) final;
-    bool virtualIsCharacterData() const final { return true; }
     void notifyParentAfterChange(ContainerNode::ChildChangeSource);
 
     String m_data;

Modified: trunk/Source/WebCore/dom/Comment.cpp (266775 => 266776)


--- trunk/Source/WebCore/dom/Comment.cpp	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WebCore/dom/Comment.cpp	2020-09-09 09:03:48 UTC (rev 266776)
@@ -30,7 +30,7 @@
 WTF_MAKE_ISO_ALLOCATED_IMPL(Comment);
 
 inline Comment::Comment(Document& document, const String& text)
-    : CharacterData(document, text, CreateOther)
+    : CharacterData(document, text)
 {
 }
 

Modified: trunk/Source/WebCore/dom/Element.cpp (266775 => 266776)


--- trunk/Source/WebCore/dom/Element.cpp	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WebCore/dom/Element.cpp	2020-09-09 09:03:48 UTC (rev 266776)
@@ -741,7 +741,7 @@
         return;
     {
         Style::PseudoClassChangeInvalidation styleInvalidation(*this, CSSSelector::PseudoClassFocusWithin);
-        setFlag(flag, HasFocusWithin);
+        setNodeFlag(NodeFlag::HasFocusWithin, flag);
     }
 }
 
@@ -2291,9 +2291,9 @@
     }
 #endif
 
-    if (getFlag(HasElementIdentifierFlag)) {
+    if (hasNodeFlag(NodeFlag::HasElementIdentifier)) {
         document().identifiedElementWasRemovedFromDocument(*this);
-        clearFlag(HasElementIdentifierFlag);
+        clearNodeFlag(NodeFlag::HasElementIdentifier);
     }
 }
 
@@ -3749,9 +3749,9 @@
 void Element::setContainsFullScreenElement(bool flag)
 {
     if (flag)
-        setFlag(ContainsFullScreenElementFlag);
+        setNodeFlag(NodeFlag::ContainsFullScreenElement);
     else
-        clearFlag(ContainsFullScreenElementFlag);
+        clearNodeFlag(NodeFlag::ContainsFullScreenElement);
     invalidateStyleAndLayerComposition();
 }
 
@@ -4605,8 +4605,8 @@
 
 ElementIdentifier Element::createElementIdentifier()
 {
-    ASSERT(!getFlag(HasElementIdentifierFlag));
-    setFlag(HasElementIdentifierFlag);
+    ASSERT(!hasNodeFlag(NodeFlag::HasElementIdentifier));
+    setNodeFlag(NodeFlag::HasElementIdentifier);
     return ElementIdentifier::generate();
 }
 

Modified: trunk/Source/WebCore/dom/Element.h (266775 => 266776)


--- trunk/Source/WebCore/dom/Element.h	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WebCore/dom/Element.h	2020-09-09 09:03:48 UTC (rev 266776)
@@ -320,7 +320,7 @@
     bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
     bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
     bool isBeingDragged() const { return isUserActionElement() && isUserActionElementDragged(); }
-    bool hasFocusWithin() const { return getFlag(HasFocusWithin); };
+    bool hasFocusWithin() const { return hasNodeFlag(NodeFlag::HasFocusWithin); };
 
     virtual void setActive(bool = true, bool pause = false);
     virtual void setHovered(bool = true);
@@ -481,14 +481,14 @@
 
     virtual bool childShouldCreateRenderer(const Node&) const;
 
-    bool hasPendingResources() const { return getFlag(HasPendingResourcesFlag); }
-    void setHasPendingResources() { setFlag(HasPendingResourcesFlag); }
-    void clearHasPendingResources() { clearFlag(HasPendingResourcesFlag); }
+    bool hasPendingResources() const { return hasNodeFlag(NodeFlag::HasPendingResources); }
+    void setHasPendingResources() { setNodeFlag(NodeFlag::HasPendingResources); }
+    void clearHasPendingResources() { clearNodeFlag(NodeFlag::HasPendingResources); }
     virtual void buildPendingResource() { };
 
-    bool hasCSSAnimation() const { return getFlag(HasCSSAnimationFlag); }
-    void setHasCSSAnimation() { setFlag(HasCSSAnimationFlag); }
-    void clearHasCSSAnimation() { clearFlag(HasCSSAnimationFlag); }
+    bool hasCSSAnimation() const { return hasNodeFlag(NodeFlag::HasCSSAnimation); }
+    void setHasCSSAnimation() { setNodeFlag(NodeFlag::HasCSSAnimation); }
+    void clearHasCSSAnimation() { clearNodeFlag(NodeFlag::HasCSSAnimation); }
 
     KeyframeEffectStack* keyframeEffectStack() const;
     KeyframeEffectStack& ensureKeyframeEffectStack();
@@ -513,7 +513,7 @@
     void setLastStyleChangeEventStyle(std::unique_ptr<const RenderStyle>&&);
 
 #if ENABLE(FULLSCREEN_API)
-    bool containsFullScreenElement() const { return getFlag(ContainsFullScreenElementFlag); }
+    bool containsFullScreenElement() const { return hasNodeFlag(NodeFlag::ContainsFullScreenElement); }
     void setContainsFullScreenElement(bool);
     void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
     WEBCORE_EXPORT virtual void webkitRequestFullscreen();

Modified: trunk/Source/WebCore/dom/Node.cpp (266775 => 266776)


--- trunk/Source/WebCore/dom/Node.cpp	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WebCore/dom/Node.cpp	2020-09-09 09:03:48 UTC (rev 266776)
@@ -1298,9 +1298,9 @@
 Node::InsertedIntoAncestorResult Node::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree)
 {
     if (insertionType.connectedToDocument)
-        setFlag(IsConnectedFlag);
+        setNodeFlag(NodeFlag::IsConnected);
     if (parentOfInsertedTree.isInShadowTree())
-        setFlag(IsInShadowTreeFlag);
+        setNodeFlag(NodeFlag::IsInShadowTree);
 
     invalidateStyle(Style::Validity::SubtreeAndRenderersInvalid);
 
@@ -1310,9 +1310,9 @@
 void Node::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
 {
     if (removalType.disconnectedFromDocument)
-        clearFlag(IsConnectedFlag);
+        clearNodeFlag(NodeFlag::IsConnected);
     if (isInShadowTree() && !treeScope().rootNode().isShadowRoot())
-        clearFlag(IsInShadowTreeFlag);
+        clearNodeFlag(NodeFlag::IsInShadowTree);
     if (removalType.disconnectedFromDocument) {
         if (auto* cache = oldParentOfRemovedTree.document().existingAXObjectCache())
             cache->remove(*this);

Modified: trunk/Source/WebCore/dom/Node.h (266775 => 266776)


--- trunk/Source/WebCore/dom/Node.h	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WebCore/dom/Node.h	2020-09-09 09:03:48 UTC (rev 266776)
@@ -186,12 +186,12 @@
 
     // Other methods (not part of DOM)
 
-    bool isElementNode() const { return getFlag(IsElementFlag); }
-    bool isContainerNode() const { return getFlag(IsContainerFlag); }
-    bool isTextNode() const { return getFlag(IsTextFlag); }
-    bool isHTMLElement() const { return getFlag(IsHTMLFlag); }
-    bool isSVGElement() const { return getFlag(IsSVGFlag); }
-    bool isMathMLElement() const { return getFlag(IsMathMLFlag); }
+    bool isElementNode() const { return hasNodeFlag(NodeFlag::IsElement); }
+    bool isContainerNode() const { return hasNodeFlag(NodeFlag::IsContainerNode); }
+    bool isTextNode() const { return hasNodeFlag(NodeFlag::IsText); }
+    bool isHTMLElement() const { return hasNodeFlag(NodeFlag::IsHTMLElement); }
+    bool isSVGElement() const { return hasNodeFlag(NodeFlag::IsSVGElement); }
+    bool isMathMLElement() const { return hasNodeFlag(NodeFlag::IsMathMLElement); }
 
     bool isPseudoElement() const { return pseudoId() != PseudoId::None; }
     bool isBeforePseudoElement() const { return pseudoId() == PseudoId::Before; }
@@ -201,9 +201,9 @@
 #if ENABLE(VIDEO)
     virtual bool isWebVTTElement() const { return false; }
 #endif
-    bool isStyledElement() const { return getFlag(IsHTMLFlag) || getFlag(IsSVGFlag) || getFlag(IsMathMLFlag); }
+    bool isStyledElement() const { return hasNodeFlag(NodeFlag::IsHTMLElement) || hasNodeFlag(NodeFlag::IsSVGElement) || hasNodeFlag(NodeFlag::IsMathMLElement); }
     virtual bool isAttributeNode() const { return false; }
-    bool isCharacterDataNode() const { return !isContainerNode() && (isTextNode() || virtualIsCharacterData()); }
+    bool isCharacterDataNode() const { return hasNodeFlag(NodeFlag::IsCharacterData); }
     virtual bool isFrameOwnerElement() const { return false; }
     virtual bool isPluginElement() const { return false; }
 #if ENABLE(SERVICE_CONTROLS)
@@ -211,15 +211,15 @@
     virtual bool isImageControlsButtonElement() const { return false; }
 #endif
 
-    bool isDocumentNode() const { return getFlag(IsDocumentNodeFlag); }
-    bool isTreeScope() const { return getFlag(IsDocumentNodeFlag) || getFlag(IsShadowRootFlag); }
-    bool isDocumentFragment() const { return getFlag(IsContainerFlag) && !(getFlag(IsElementFlag) || getFlag(IsDocumentNodeFlag)); }
-    bool isShadowRoot() const { return getFlag(IsShadowRootFlag); }
+    bool isDocumentNode() const { return hasNodeFlag(NodeFlag::IsDocumentNode); }
+    bool isTreeScope() const { return hasNodeFlag(NodeFlag::IsDocumentNode) || hasNodeFlag(NodeFlag::IsShadowRoot); }
+    bool isDocumentFragment() const { return hasNodeFlag(NodeFlag::IsDocumentFragment); }
+    bool isShadowRoot() const { return hasNodeFlag(NodeFlag::IsShadowRoot); }
 
-    bool hasCustomStyleResolveCallbacks() const { return getFlag(HasCustomStyleResolveCallbacksFlag); }
+    bool hasCustomStyleResolveCallbacks() const { return hasNodeFlag(NodeFlag::HasCustomStyleResolveCallbacks); }
 
-    bool hasSyntheticAttrChildNodes() const { return getFlag(HasSyntheticAttrChildNodesFlag); }
-    void setHasSyntheticAttrChildNodes(bool flag) { setFlag(flag, HasSyntheticAttrChildNodesFlag); }
+    bool hasSyntheticAttrChildNodes() const { return hasNodeFlag(NodeFlag::HasSyntheticAttrChildNodes); }
+    void setHasSyntheticAttrChildNodes(bool flag) { setNodeFlag(NodeFlag::HasSyntheticAttrChildNodes, flag); }
 
     // If this node is in a shadow tree, returns its shadow host. Otherwise, returns null.
     WEBCORE_EXPORT Element* shadowHost() const;
@@ -260,8 +260,8 @@
     // Returns the parent node, but null if the parent node is a ShadowRoot.
     ContainerNode* nonShadowBoundaryParentNode() const;
 
-    bool selfOrAncestorHasDirAutoAttribute() const { return getFlag(SelfOrAncestorHasDirAutoFlag); }
-    void setSelfOrAncestorHasDirAutoAttribute(bool flag) { setFlag(flag, SelfOrAncestorHasDirAutoFlag); }
+    bool selfOrAncestorHasDirAutoAttribute() const { return hasNodeFlag(NodeFlag::SelfOrAncestorHasDirAuto); }
+    void setSelfOrAncestorHasDirAutoAttribute(bool flag) { setNodeFlag(NodeFlag::SelfOrAncestorHasDirAuto, flag); }
 
     // Returns the enclosing event parent Element (or self) that, when clicked, would trigger a navigation.
     Element* enclosingLinkEventParentOrSelf();
@@ -289,8 +289,8 @@
     virtual void notifyLoadedSheetAndAllCriticalSubresources(bool /* error loading subresource */) { }
     virtual void startLoadingDynamicSheet() { ASSERT_NOT_REACHED(); }
 
-    bool isUserActionElement() const { return getFlag(IsUserActionElement); }
-    void setUserActionElement(bool flag) { setFlag(flag, IsUserActionElement); }
+    bool isUserActionElement() const { return hasNodeFlag(NodeFlag::IsUserActionElement); }
+    void setUserActionElement(bool flag) { setNodeFlag(NodeFlag::IsUserActionElement, flag); }
 
     bool inRenderedDocument() const;
     bool needsStyleRecalc() const { return styleValidity() != Style::Validity::Valid; }
@@ -297,7 +297,7 @@
     Style::Validity styleValidity() const { return styleBitfields().styleValidity(); }
     bool styleResolutionShouldRecompositeLayer() const { return hasStyleFlag(NodeStyleFlag::StyleResolutionShouldRecompositeLayer); }
     bool childNeedsStyleRecalc() const { return hasStyleFlag(NodeStyleFlag::DescendantNeedsStyleResolution); }
-    bool isEditingText() const { return getFlag(IsTextFlag) && getFlag(IsEditingText); }
+    bool isEditingText() const { return hasNodeFlag(NodeFlag::IsEditingText); }
 
     void setChildNeedsStyleRecalc() { setStyleFlag(NodeStyleFlag::DescendantNeedsStyleResolution); }
     void clearChildNeedsStyleRecalc();
@@ -304,11 +304,11 @@
 
     void setHasValidStyle();
 
-    bool isLink() const { return getFlag(IsLinkFlag); }
-    void setIsLink(bool flag) { setFlag(flag, IsLinkFlag); }
+    bool isLink() const { return hasNodeFlag(NodeFlag::IsLink); }
+    void setIsLink(bool flag) { setNodeFlag(NodeFlag::IsLink, flag); }
 
-    bool hasEventTargetData() const { return getFlag(HasEventTargetDataFlag); }
-    void setHasEventTargetData(bool flag) { setFlag(flag, HasEventTargetDataFlag); }
+    bool hasEventTargetData() const { return hasNodeFlag(NodeFlag::HasEventTargetData); }
+    void setHasEventTargetData(bool flag) { setNodeFlag(NodeFlag::HasEventTargetData, flag); }
 
     WEBCORE_EXPORT bool isContentEditable();
     bool isContentRichlyEditable();
@@ -356,10 +356,10 @@
 
     // Returns true if this node is associated with a document and is in its associated document's
     // node tree, false otherwise (https://dom.spec.whatwg.org/#connected).
-    bool isConnected() const { return getFlag(IsConnectedFlag); }
+    bool isConnected() const { return hasNodeFlag(NodeFlag::IsConnected); }
     bool isInUserAgentShadowTree() const;
-    bool isInShadowTree() const { return getFlag(IsInShadowTreeFlag); }
-    bool isInTreeScope() const { return getFlag(static_cast<NodeFlags>(IsConnectedFlag | IsInShadowTreeFlag)); }
+    bool isInShadowTree() const { return hasNodeFlag(NodeFlag::IsInShadowTree); }
+    bool isInTreeScope() const { return hasNodeFlag(NodeFlag::IsConnected) || hasNodeFlag(NodeFlag::IsInShadowTree); }
 
     bool isDocumentTypeNode() const { return nodeType() == DOCUMENT_TYPE_NODE; }
     virtual bool childTypeAllowed(NodeType) const { return false; }
@@ -506,31 +506,31 @@
 #else
     static uint32_t rareDataPointerMask() { return -1; }
 #endif
-    static int32_t flagIsText() { return IsTextFlag; }
-    static int32_t flagIsContainer() { return IsContainerFlag; }
-    static int32_t flagIsElement() { return IsElementFlag; }
-    static int32_t flagIsShadowRoot() { return IsShadowRootFlag; }
-    static int32_t flagIsHTML() { return IsHTMLFlag; }
-    static int32_t flagIsLink() { return IsLinkFlag; }
-    static int32_t flagHasFocusWithin() { return HasFocusWithin; }
-    static int32_t flagIsParsingChildrenFinished() { return IsParsingChildrenFinishedFlag; }
+    static int32_t flagIsText() { return static_cast<int32_t>(NodeFlag::IsText); }
+    static int32_t flagIsContainer() { return static_cast<int32_t>(NodeFlag::IsContainerNode); }
+    static int32_t flagIsElement() { return static_cast<int32_t>(NodeFlag::IsElement); }
+    static int32_t flagIsShadowRoot() { return static_cast<int32_t>(NodeFlag::IsShadowRoot); }
+    static int32_t flagIsHTML() { return static_cast<int32_t>(NodeFlag::IsHTMLElement); }
+    static int32_t flagIsLink() { return static_cast<int32_t>(NodeFlag::IsLink); }
+    static int32_t flagHasFocusWithin() { return static_cast<int32_t>(NodeFlag::HasFocusWithin); }
+    static int32_t flagIsParsingChildrenFinished() { return static_cast<int32_t>(NodeFlag::IsParsingChildrenFinished); }
 #endif // ENABLE(JIT)
 
 protected:
-    enum NodeFlags {
-        IsTextFlag = 1,
-        IsContainerFlag = 1 << 1,
-        IsElementFlag = 1 << 2,
-        IsHTMLFlag = 1 << 3,
-        IsSVGFlag = 1 << 4,
-        IsMathMLFlag = 1 << 5,
-        IsDocumentNodeFlag = 1 << 6,
-        IsShadowRootFlag = 1 << 7,
-        IsConnectedFlag = 1 << 8,
-        IsInShadowTreeFlag = 1 << 9,
-        // UnusedFlag = 1 << 10,
-        HasEventTargetDataFlag = 1 << 11,
-        // UnusedFlag = 1 << 12,
+    enum class NodeFlag : uint32_t {
+        IsCharacterData = 1 << 0,
+        IsText = 1 << 1,
+        IsContainerNode = 1 << 2,
+        IsElement = 1 << 3,
+        IsHTMLElement = 1 << 4,
+        IsSVGElement = 1 << 5,
+        IsMathMLElement = 1 << 6,
+        IsDocumentNode = 1 << 7,
+        IsDocumentFragment = 1 << 8,
+        IsShadowRoot = 1 << 9,
+        IsConnected = 1 << 10,
+        IsInShadowTree = 1 << 11,
+        HasEventTargetData = 1 << 12,
         // UnusedFlag = 1 << 13,
         // UnusedFlag = 1 << 14,
 
@@ -538,24 +538,22 @@
         // be stored in the same memory word as the Node bits above.
         IsEditingText = 1 << 15, // Text
         HasFocusWithin = 1 << 16, // Element
-        IsLinkFlag = 1 << 17,
+        IsLink = 1 << 17,
         IsUserActionElement = 1 << 18,
-        IsParsingChildrenFinishedFlag = 1 << 19,
-        HasSyntheticAttrChildNodesFlag = 1 << 20,
-        SelfOrAncestorHasDirAutoFlag = 1 << 21,
+        IsParsingChildrenFinished = 1 << 19,
+        HasSyntheticAttrChildNodes = 1 << 20,
+        SelfOrAncestorHasDirAuto = 1 << 21,
 
-        HasCustomStyleResolveCallbacksFlag = 1 << 22,
+        HasCustomStyleResolveCallbacks = 1 << 22,
 
-        HasPendingResourcesFlag = 1 << 23,
-        HasCSSAnimationFlag = 1 << 24,
-        HasElementIdentifierFlag = 1 << 25,
+        HasPendingResources = 1 << 23,
+        HasCSSAnimation = 1 << 24,
+        HasElementIdentifier = 1 << 25,
 #if ENABLE(FULLSCREEN_API)
-        ContainsFullScreenElementFlag = 1 << 26,
+        ContainsFullScreenElement = 1 << 26,
 #endif
 
         // Bits 27-31 are free.
-
-        DefaultNodeFlags = IsParsingChildrenFinishedFlag
     };
 
     enum class TabIndexState : uint8_t {
@@ -578,10 +576,9 @@
         uint16_t customElementState : 2;
     };
 
-    bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
-    void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); } 
-    void setFlag(NodeFlags mask) const { m_nodeFlags |= mask; } 
-    void clearFlag(NodeFlags mask) const { m_nodeFlags &= ~mask; }
+    bool hasNodeFlag(NodeFlag flag) const { return m_nodeFlags.contains(flag); }
+    void setNodeFlag(NodeFlag flag, bool value = true) const { m_nodeFlags.set(flag, value); }
+    void clearNodeFlag(NodeFlag flag) const { m_nodeFlags.remove(flag); }
 
     RareDataBitFields rareDataBitfields() const { return bitwise_cast<RareDataBitFields>(m_rareDataWithBitfields.type()); }
     void setRareDataBitfields(RareDataBitFields bitfields) { m_rareDataWithBitfields.setType(bitwise_cast<uint16_t>(bitfields)); }
@@ -592,24 +589,25 @@
     CustomElementState customElementState() const { return static_cast<CustomElementState>(rareDataBitfields().customElementState); }
     void setCustomElementState(CustomElementState);
 
-    bool isParsingChildrenFinished() const { return getFlag(IsParsingChildrenFinishedFlag); }
-    void setIsParsingChildrenFinished() { setFlag(IsParsingChildrenFinishedFlag); }
-    void clearIsParsingChildrenFinished() { clearFlag(IsParsingChildrenFinishedFlag); }
+    bool isParsingChildrenFinished() const { return hasNodeFlag(NodeFlag::IsParsingChildrenFinished); }
+    void setIsParsingChildrenFinished() { setNodeFlag(NodeFlag::IsParsingChildrenFinished); }
+    void clearIsParsingChildrenFinished() { clearNodeFlag(NodeFlag::IsParsingChildrenFinished); }
 
-    enum ConstructionType {
-        CreateOther = DefaultNodeFlags,
-        CreateText = DefaultNodeFlags | IsTextFlag,
-        CreateContainer = DefaultNodeFlags | IsContainerFlag, 
-        CreateElement = CreateContainer | IsElementFlag, 
-        CreatePseudoElement =  CreateElement | IsConnectedFlag,
-        CreateShadowRoot = CreateContainer | IsShadowRootFlag | IsInShadowTreeFlag,
-        CreateDocumentFragment = CreateContainer,
-        CreateHTMLElement = CreateElement | IsHTMLFlag,
-        CreateSVGElement = CreateElement | IsSVGFlag | HasCustomStyleResolveCallbacksFlag,
-        CreateMathMLElement = CreateElement | IsMathMLFlag,
-        CreateDocument = CreateContainer | IsDocumentNodeFlag | IsConnectedFlag,
-        CreateEditingText = CreateText | IsEditingText,
-    };
+    constexpr static auto DefaultNodeFlags = OptionSet<NodeFlag>(NodeFlag::IsParsingChildrenFinished);
+    constexpr static auto CreateOther = DefaultNodeFlags;
+    constexpr static auto CreateCharacterData = DefaultNodeFlags | NodeFlag::IsCharacterData;
+    constexpr static auto CreateText = CreateCharacterData | NodeFlag::IsText;
+    constexpr static auto CreateContainer = DefaultNodeFlags | NodeFlag::IsContainerNode;
+    constexpr static auto CreateElement = CreateContainer | NodeFlag::IsElement;
+    constexpr static auto CreatePseudoElement = CreateElement | NodeFlag::IsConnected;
+    constexpr static auto CreateDocumentFragment = CreateContainer | NodeFlag::IsDocumentFragment;
+    constexpr static auto CreateShadowRoot = CreateDocumentFragment | NodeFlag::IsShadowRoot | NodeFlag::IsInShadowTree;
+    constexpr static auto CreateHTMLElement = CreateElement | NodeFlag::IsHTMLElement;
+    constexpr static auto CreateSVGElement = CreateElement | NodeFlag::IsSVGElement | NodeFlag::HasCustomStyleResolveCallbacks;
+    constexpr static auto CreateMathMLElement = CreateElement | NodeFlag::IsMathMLElement;
+    constexpr static auto CreateDocument = CreateContainer | NodeFlag::IsDocumentNode | NodeFlag::IsConnected;
+    constexpr static auto CreateEditingText = CreateText | NodeFlag::IsEditingText;
+    using ConstructionType = OptionSet<NodeFlag>;
     Node(Document&, ConstructionType);
 
     static constexpr uint32_t s_refCountIncrement = 2;
@@ -677,7 +675,7 @@
 
     void clearEventTargetData();
 
-    void setHasCustomStyleResolveCallbacks() { setFlag(true, HasCustomStyleResolveCallbacksFlag); }
+    void setHasCustomStyleResolveCallbacks() { setNodeFlag(NodeFlag::HasCustomStyleResolveCallbacks); }
 
     void setTreeScope(TreeScope& scope) { m_treeScope = &scope; }
 
@@ -693,8 +691,6 @@
         return PseudoId::None;
     }
 
-    virtual bool virtualIsCharacterData() const { return false; }
-
     WEBCORE_EXPORT void removedLastRef();
 
     void refEventTarget() final;
@@ -720,7 +716,7 @@
     };
 
     mutable uint32_t m_refCountAndParentBit { s_refCountIncrement };
-    mutable uint32_t m_nodeFlags;
+    mutable OptionSet<NodeFlag> m_nodeFlags;
 
     ContainerNode* m_parentNode { nullptr };
     TreeScope* m_treeScope { nullptr };

Modified: trunk/Source/WebCore/dom/ProcessingInstruction.cpp (266775 => 266776)


--- trunk/Source/WebCore/dom/ProcessingInstruction.cpp	2020-09-09 05:14:14 UTC (rev 266775)
+++ trunk/Source/WebCore/dom/ProcessingInstruction.cpp	2020-09-09 09:03:48 UTC (rev 266776)
@@ -44,7 +44,7 @@
 WTF_MAKE_ISO_ALLOCATED_IMPL(ProcessingInstruction);
 
 inline ProcessingInstruction::ProcessingInstruction(Document& document, const String& target, const String& data)
-    : CharacterData(document, data, CreateOther)
+    : CharacterData(document, data)
     , m_target(target)
 {
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to