Range.deleteContents cannot delete DocType
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Sep 2015 15:51:08 +0000 (15:51 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Sep 2015 15:51:08 +0000 (15:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148773
<rdar://problem/22571280>

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline W3C DOM test now that more checks are passing.

* web-platform-tests/dom/ranges/Range-deleteContents-expected.txt:

Source/WebCore:

Range.deleteContents() was not able to delete a DocumentType Node, and
was throwing a HIERARCHY_REQUEST_ERR. The DOM specification does not
say we should throw in such case:
https://dom.spec.whatwg.org/#dom-range-deletecontents

However, Range.extractContents() should still throw an exception
if any of the contained children in a DocumentType Node:
https://dom.spec.whatwg.org/#concept-range-extract (Step 12)

No new tests, already covered by existing test.

* dom/Range.cpp:
(WebCore::Range::deleteContents):
(WebCore::Range::extractContents):
(WebCore::Range::checkDeleteExtract):
* dom/Range.h:

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

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-deleteContents-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/Range.h

index 2a7d052d8843a5a91b3307d58cb4ee62210bc860..b246674d95b211e91ae412d8b9db4181c8bdb3fe 100644 (file)
@@ -1,3 +1,15 @@
+2015-09-17  Chris Dumez  <cdumez@apple.com>
+
+        Range.deleteContents cannot delete DocType
+        https://bugs.webkit.org/show_bug.cgi?id=148773
+        <rdar://problem/22571280>
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline W3C DOM test now that more checks are passing.
+
+        * web-platform-tests/dom/ranges/Range-deleteContents-expected.txt:
+
 2015-09-16  Chris Dumez  <cdumez@apple.com>
 
         Element's attribute NS API should treat defined undefined namespace as null
index 66600d955052e44ecf802d61f48c2a98c2a63135..bf5c7cadfee9a6ab8e86646b98001994d6264c2d 100644 (file)
@@ -48,10 +48,10 @@ PASS Resulting DOM for range 21 [paras[0], 0, paras[0].firstChild, 7]
 PASS Resulting cursor position for range 21 [paras[0], 0, paras[0].firstChild, 7] 
 PASS Resulting DOM for range 22 [testDiv, 2, paras[4], 1] 
 PASS Resulting cursor position for range 22 [testDiv, 2, paras[4], 1] 
-FAIL Resulting DOM for range 23 [document, 0, document, 1] HierarchyRequestError: DOM Exception 3
-FAIL Resulting cursor position for range 23 [document, 0, document, 1] undefined is not an object (evaluating 'actualRoots')
-FAIL Resulting DOM for range 24 [document, 0, document, 2] HierarchyRequestError: DOM Exception 3
-FAIL Resulting cursor position for range 24 [document, 0, document, 2] undefined is not an object (evaluating 'actualRoots')
+PASS Resulting DOM for range 23 [document, 0, document, 1] 
+PASS Resulting cursor position for range 23 [document, 0, document, 1] 
+PASS Resulting DOM for range 24 [document, 0, document, 2] 
+PASS Resulting cursor position for range 24 [document, 0, document, 2] 
 PASS Resulting DOM for range 25 [comment, 2, comment, 3] 
 PASS Resulting cursor position for range 25 [comment, 2, comment, 3] 
 PASS Resulting DOM for range 26 [testDiv, 0, comment, 5] 
index addca698faa69931f89fdc8c6320c0a15b715f90..c1f7d23d6e9cf57427ffb31bdf15d29501c9927d 100644 (file)
@@ -1,3 +1,28 @@
+2015-09-17  Chris Dumez  <cdumez@apple.com>
+
+        Range.deleteContents cannot delete DocType
+        https://bugs.webkit.org/show_bug.cgi?id=148773
+        <rdar://problem/22571280>
+
+        Reviewed by Ryosuke Niwa.
+
+        Range.deleteContents() was not able to delete a DocumentType Node, and
+        was throwing a HIERARCHY_REQUEST_ERR. The DOM specification does not
+        say we should throw in such case:
+        https://dom.spec.whatwg.org/#dom-range-deletecontents
+
+        However, Range.extractContents() should still throw an exception
+        if any of the contained children in a DocumentType Node:
+        https://dom.spec.whatwg.org/#concept-range-extract (Step 12)
+
+        No new tests, already covered by existing test.
+
+        * dom/Range.cpp:
+        (WebCore::Range::deleteContents):
+        (WebCore::Range::extractContents):
+        (WebCore::Range::checkDeleteExtract):
+        * dom/Range.h:
+
 2015-09-17  Eric Carlson  <eric.carlson@apple.com>
 
         [Mac MediaStream] Cleanup capture source classes
index 26508cf0472d4f0edefa5d3557ce923c78b1b925..f1aa22150729598a937b6ecaafc4c6f8aa7263ee 100644 (file)
@@ -489,7 +489,7 @@ bool Range::boundaryPointsValid() const
 
 void Range::deleteContents(ExceptionCode& ec)
 {
-    checkDeleteExtract(ec);
+    checkDeleteExtract(Delete, ec);
     if (ec)
         return;
 
@@ -836,7 +836,7 @@ RefPtr<Node> Range::processAncestorsAndTheirSiblings(ActionType action, Node* co
 
 RefPtr<DocumentFragment> Range::extractContents(ExceptionCode& ec)
 {
-    checkDeleteExtract(ec);
+    checkDeleteExtract(Extract, ec);
     if (ec)
         return nullptr;
 
@@ -1334,7 +1334,7 @@ void Range::setStartBefore(Node* refNode, ExceptionCode& ec)
     setStart(refNode->parentNode(), refNode->computeNodeIndex(), ec);
 }
 
-void Range::checkDeleteExtract(ExceptionCode& ec)
+void Range::checkDeleteExtract(ActionType action, ExceptionCode& ec)
 {
     ec = 0;
     if (!commonAncestorContainer())
@@ -1346,7 +1346,8 @@ void Range::checkDeleteExtract(ExceptionCode& ec)
             ec = NO_MODIFICATION_ALLOWED_ERR;
             return;
         }
-        if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) {
+
+        if (action == Extract && n->nodeType() == Node::DOCUMENT_TYPE_NODE) {
             ec = HIERARCHY_REQUEST_ERR;
             return;
         }
index 6f7e388ebae911b0dd9e67d221f465e5e01fd2d2..c8f2993add0d159fac52bdac7f1cc930bde5f6ee 100644 (file)
@@ -161,10 +161,10 @@ private:
 
     Node* checkNodeWOffset(Node*, int offset, ExceptionCode&) const;
     void checkNodeBA(Node*, ExceptionCode&) const;
-    void checkDeleteExtract(ExceptionCode&);
     bool containedByReadOnly() const;
 
     enum ActionType { Delete, Extract, Clone };
+    void checkDeleteExtract(ActionType, ExceptionCode&);
     RefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&);
     static RefPtr<Node> processContentsBetweenOffsets(ActionType, PassRefPtr<DocumentFragment>, Node*, unsigned startOffset, unsigned endOffset, ExceptionCode&);
     static void processNodes(ActionType, Vector<RefPtr<Node>>&, PassRefPtr<Node> oldContainer, PassRefPtr<Node> newContainer, ExceptionCode&);