Title: [174038] trunk/Source/WebCore
Revision
174038
Author
cdu...@apple.com
Date
2014-09-27 21:13:59 -0700 (Sat, 27 Sep 2014)

Log Message

Use the new is<>() / downcast<>() for Attr Nodes
https://bugs.webkit.org/show_bug.cgi?id=137183

Reviewed by Ryosuke Niwa.

Use the new is<>() / downcast<>() for Attr Nodes instead of isAttr() /
toAttr().

No new tests, no behavior change.

* dom/Attr.h:
(WebCore::isAttr):
* dom/Document.cpp:
(WebCore::Document::importNode):
(WebCore::Document::adoptNode):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::setNamedItem):
* dom/Node.cpp:
(WebCore::Node::compareDocumentPosition):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::buildObjectForNode):
* inspector/InspectorNodeFinder.cpp:
(WebCore::InspectorNodeFinder::searchUsingXPath):
* xml/XPathNodeSet.cpp:
(WebCore::XPath::sortBlock):
(WebCore::XPath::NodeSet::sort):
(WebCore::XPath::findRootNode):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174037 => 174038)


--- trunk/Source/WebCore/ChangeLog	2014-09-27 22:17:29 UTC (rev 174037)
+++ trunk/Source/WebCore/ChangeLog	2014-09-28 04:13:59 UTC (rev 174038)
@@ -1,3 +1,33 @@
+2014-09-27  Christophe Dumez  <cdu...@apple.com>
+
+        Use the new is<>() / downcast<>() for Attr Nodes
+        https://bugs.webkit.org/show_bug.cgi?id=137183
+
+        Reviewed by Ryosuke Niwa.
+
+        Use the new is<>() / downcast<>() for Attr Nodes instead of isAttr() /
+        toAttr().
+
+        No new tests, no behavior change.
+
+        * dom/Attr.h:
+        (WebCore::isAttr):
+        * dom/Document.cpp:
+        (WebCore::Document::importNode):
+        (WebCore::Document::adoptNode):
+        * dom/NamedNodeMap.cpp:
+        (WebCore::NamedNodeMap::setNamedItem):
+        * dom/Node.cpp:
+        (WebCore::Node::compareDocumentPosition):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::buildObjectForNode):
+        * inspector/InspectorNodeFinder.cpp:
+        (WebCore::InspectorNodeFinder::searchUsingXPath):
+        * xml/XPathNodeSet.cpp:
+        (WebCore::XPath::sortBlock):
+        (WebCore::XPath::NodeSet::sort):
+        (WebCore::XPath::findRootNode):
+
 2014-09-27  Brian J. Burg  <b...@cs.washington.edu>
 
         Web Replay: Playback position updates should be sent before the next event loop input is dispatched

Modified: trunk/Source/WebCore/dom/Attr.h (174037 => 174038)


--- trunk/Source/WebCore/dom/Attr.h	2014-09-27 22:17:29 UTC (rev 174037)
+++ trunk/Source/WebCore/dom/Attr.h	2014-09-28 04:13:59 UTC (rev 174038)
@@ -99,11 +99,10 @@
     unsigned m_ignoreChildrenChanged;
 };
 
-inline bool isAttr(const Node& node) { return node.isAttributeNode(); }
-void isAttr(const Attr&); // Catch unnecessary runtime check of type known at compile time.
+SPECIALIZE_TYPE_TRAITS_BEGIN(Attr)
+    static bool isAttr(const Node& node) { return node.isAttributeNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
-NODE_TYPE_CASTS(Attr)
-
 } // namespace WebCore
 
 #endif // Attr_h

Modified: trunk/Source/WebCore/dom/Document.cpp (174037 => 174038)


--- trunk/Source/WebCore/dom/Document.cpp	2014-09-27 22:17:29 UTC (rev 174037)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-09-28 04:13:59 UTC (rev 174038)
@@ -966,7 +966,7 @@
         return newElement.release();
     }
     case ATTRIBUTE_NODE:
-        return Attr::create(*this, QualifiedName(nullAtom, toAttr(*importedNode).name(), nullAtom), toAttr(*importedNode).value());
+        return Attr::create(*this, QualifiedName(nullAtom, downcast<Attr>(*importedNode).name(), nullAtom), downcast<Attr>(*importedNode).value());
     case DOCUMENT_FRAGMENT_NODE: {
         if (importedNode->isShadowRoot()) {
             // ShadowRoot nodes should not be explicitly importable.
@@ -1025,7 +1025,7 @@
         ec = NOT_SUPPORTED_ERR;
         return nullptr;
     case ATTRIBUTE_NODE: {                   
-        Attr& attr = toAttr(*source);
+        Attr& attr = downcast<Attr>(*source);
         if (attr.ownerElement())
             attr.ownerElement()->removeAttributeNode(&attr, ec);
         break;

Modified: trunk/Source/WebCore/dom/NamedNodeMap.cpp (174037 => 174038)


--- trunk/Source/WebCore/dom/NamedNodeMap.cpp	2014-09-27 22:17:29 UTC (rev 174037)
+++ trunk/Source/WebCore/dom/NamedNodeMap.cpp	2014-09-28 04:13:59 UTC (rev 174038)
@@ -82,16 +82,16 @@
 {
     if (!node) {
         ec = NOT_FOUND_ERR;
-        return 0;
+        return nullptr;
     }
 
     // Not mentioned in spec: throw a HIERARCHY_REQUEST_ERROR if the user passes in a non-attribute node
-    if (!node->isAttributeNode()) {
+    if (!is<Attr>(node)) {
         ec = HIERARCHY_REQUEST_ERR;
-        return 0;
+        return nullptr;
     }
 
-    return m_element.setAttributeNode(toAttr(node), ec);
+    return m_element.setAttributeNode(downcast<Attr>(node), ec);
 }
 
 PassRefPtr<Node> NamedNodeMap::setNamedItemNS(Node* node, ExceptionCode& ec)

Modified: trunk/Source/WebCore/dom/Node.cpp (174037 => 174038)


--- trunk/Source/WebCore/dom/Node.cpp	2014-09-27 22:17:29 UTC (rev 174037)
+++ trunk/Source/WebCore/dom/Node.cpp	2014-09-28 04:13:59 UTC (rev 174038)
@@ -1397,15 +1397,15 @@
 
 unsigned short Node::compareDocumentPosition(Node* otherNode)
 {
-    // It is not clear what should be done if |otherNode| is 0.
+    // It is not clear what should be done if |otherNode| is nullptr.
     if (!otherNode)
         return DOCUMENT_POSITION_DISCONNECTED;
 
     if (otherNode == this)
         return DOCUMENT_POSITION_EQUIVALENT;
     
-    Attr* attr1 = isAttributeNode() ? toAttr(this) : nullptr;
-    Attr* attr2 = otherNode->isAttributeNode() ? toAttr(otherNode) : nullptr;
+    Attr* attr1 = is<Attr>(this) ? downcast<Attr>(this) : nullptr;
+    Attr* attr2 = is<Attr>(otherNode) ? downcast<Attr>(otherNode) : nullptr;
     
     Node* start1 = attr1 ? attr1->ownerElement() : this;
     Node* start2 = attr2 ? attr2->ownerElement() : otherNode;

Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp (174037 => 174038)


--- trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp	2014-09-27 22:17:29 UTC (rev 174037)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp	2014-09-28 04:13:59 UTC (rev 174038)
@@ -1311,10 +1311,10 @@
         value->setPublicId(docType->publicId());
         value->setSystemId(docType->systemId());
         value->setInternalSubset(docType->internalSubset());
-    } else if (node->isAttributeNode()) {
-        Attr* attribute = toAttr(node);
-        value->setName(attribute->name());
-        value->setValue(attribute->value());
+    } else if (is<Attr>(node)) {
+        Attr& attribute = downcast<Attr>(*node);
+        value->setName(attribute.name());
+        value->setValue(attribute.value());
     }
 
     // Need to enable AX to get the computed role.

Modified: trunk/Source/WebCore/inspector/InspectorNodeFinder.cpp (174037 => 174038)


--- trunk/Source/WebCore/inspector/InspectorNodeFinder.cpp	2014-09-27 22:17:29 UTC (rev 174037)
+++ trunk/Source/WebCore/inspector/InspectorNodeFinder.cpp	2014-09-28 04:13:59 UTC (rev 174038)
@@ -146,8 +146,8 @@
         if (ec)
             return;
 
-        if (node->isAttributeNode())
-            node = toAttr(node)->ownerElement();
+        if (is<Attr>(node))
+            node = downcast<Attr>(*node).ownerElement();
 
         // XPath can get out of the context node that we pass as the starting point to evaluate, so we need to filter for just the nodes we care about.
         if (node == parentNode || node->isDescendantOf(parentNode))

Modified: trunk/Source/WebCore/xml/XPathNodeSet.cpp (174037 => 174038)


--- trunk/Source/WebCore/xml/XPathNodeSet.cpp	2014-09-27 22:17:29 UTC (rev 174037)
+++ trunk/Source/WebCore/xml/XPathNodeSet.cpp	2014-09-28 04:13:59 UTC (rev 174038)
@@ -94,8 +94,8 @@
         unsigned sortedEnd = from;
         // FIXME: namespace nodes are not implemented.
         for (unsigned i = sortedEnd; i < to; ++i) {
-            Node* n = parentMatrix[i][0];
-            if (n->isAttributeNode() && toAttr(n)->ownerElement() == commonAncestor)
+            Node* node = parentMatrix[i][0];
+            if (is<Attr>(node) && downcast<Attr>(*node).ownerElement() == commonAncestor)
                 parentMatrix[i].swap(parentMatrix[sortedEnd++]);
         }
         if (sortedEnd != from) {
@@ -155,15 +155,15 @@
     Vector<Vector<Node*>> parentMatrix(nodeCount);
     for (unsigned i = 0; i < nodeCount; ++i) {
         Vector<Node*>& parentsVector = parentMatrix[i];
-        Node* n = m_nodes[i].get();
-        parentsVector.append(n);
-        if (n->isAttributeNode()) {
-            n = toAttr(n)->ownerElement();
-            parentsVector.append(n);
+        Node* node = m_nodes[i].get();
+        parentsVector.append(node);
+        if (is<Attr>(node)) {
+            node = downcast<Attr>(*node).ownerElement();
+            parentsVector.append(node);
             containsAttributeNodes = true;
         }
-        while ((n = n->parentNode()))
-            parentsVector.append(n);
+        while ((node = node->parentNode()))
+            parentsVector.append(node);
     }
     sortBlock(0, nodeCount, parentMatrix, containsAttributeNodes);
     
@@ -179,8 +179,8 @@
 
 static Node* findRootNode(Node* node)
 {
-    if (node->isAttributeNode())
-        node = toAttr(node)->ownerElement();
+    if (is<Attr>(node))
+        node = downcast<Attr>(*node).ownerElement();
     if (node->inDocument())
         node = &node->document();
     else {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to