Drop unnecessary ancestor traversal in Range::selectNode()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Sep 2015 00:33:21 +0000 (00:33 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Sep 2015 00:33:21 +0000 (00:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149482

Reviewed by Ryosuke Niwa.

Drop unnecessary ancestor traversal in Range::selectNode(). It traversed
the ancestors to throw a INVALID_NODE_TYPE_ERR if one of them was a
DocumentType Node. However, it is impossible for a DocumentType Node to
have children.

* dom/Range.cpp:
(WebCore::Range::selectNode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190145 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Range.cpp

index e3d6ca6..e95ee18 100644 (file)
@@ -1,3 +1,18 @@
+2015-09-22  Chris Dumez  <cdumez@apple.com>
+
+        Drop unnecessary ancestor traversal in Range::selectNode()
+        https://bugs.webkit.org/show_bug.cgi?id=149482
+
+        Reviewed by Ryosuke Niwa.
+
+        Drop unnecessary ancestor traversal in Range::selectNode(). It traversed
+        the ancestors to throw a INVALID_NODE_TYPE_ERR if one of them was a
+        DocumentType Node. However, it is impossible for a DocumentType Node to
+        have children.
+
+        * dom/Range.cpp:
+        (WebCore::Range::selectNode):
+
 2015-09-22  Brian Weinstein  <bweinstein@apple.com>
 
         Error message in ContentExtensionError.cpp shouldn't have two spaces between sentences.
index 1ee577f..4e6a8a5 100644 (file)
@@ -1118,27 +1118,7 @@ void Range::selectNode(Node* refNode, ExceptionCode& ec)
         return;
     }
 
-    // INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Entity, or
-    // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, or Entity
-    // node.
-    for (ContainerNode* anc = refNode->parentNode(); anc; anc = anc->parentNode()) {
-        switch (anc->nodeType()) {
-            case Node::ATTRIBUTE_NODE:
-            case Node::CDATA_SECTION_NODE:
-            case Node::COMMENT_NODE:
-            case Node::DOCUMENT_FRAGMENT_NODE:
-            case Node::DOCUMENT_NODE:
-            case Node::ELEMENT_NODE:
-            case Node::PROCESSING_INSTRUCTION_NODE:
-            case Node::TEXT_NODE:
-            case Node::XPATH_NAMESPACE_NODE:
-                break;
-            case Node::DOCUMENT_TYPE_NODE:
-                ec = INVALID_NODE_TYPE_ERR;
-                return;
-        }
-    }
-
+    // INVALID_NODE_TYPE_ERR: Raised if refNode is a Document, DocumentFragment or Attr node.
     switch (refNode->nodeType()) {
         case Node::CDATA_SECTION_NODE:
         case Node::COMMENT_NODE: