<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[189682] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/189682">189682</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-09-13 22:08:39 -0700 (Sun, 13 Sep 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Improve Node pre-insertion validation when the parent is a Document
https://bugs.webkit.org/show_bug.cgi?id=149109
<rdar://problem/22560436>
Reviewed by Ryosuke Niwa.
LayoutTests/imported/w3c:
Rebaseline several W3C tests now that more checks are passing.
* web-platform-tests/dom/nodes/Node-insertBefore-expected.txt:
* web-platform-tests/dom/nodes/Node-replaceChild-expected.txt:
* web-platform-tests/dom/nodes/append-on-Document-expected.txt:
* web-platform-tests/dom/nodes/prepend-on-Document-expected.txt:
Source/WebCore:
Improve Node pre-insertion validation when the parent is a Document to
match the specification:
https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
https://dom.spec.whatwg.org/#concept-node-replace
This affects the following API: Node.insertBefore(), Node.appendChild(),
Node.replaceChild().
WebKit current fails to do the following checks whenever the parent is a
Document from pre-insertion validation:
1. If the inserted Node is a DocumentFragment, we should make sure it
contains only one Element.
-> This is because a Document can have only one child that is an
Element [1].
2.a. If an Element is inserted, we should make sure it is not inserted
before a DocumentType.
2.b. If a DocumentType is inserted, we should make sure it is not
inserted after an Element.
-> This is because the DocType must come before the optional Element
child [1].
Firefox and Chrome already match the specification here. This patch
aligns WebKit's behavior with those browsers and the specification.
[1] https://dom.spec.whatwg.org/#node-trees
No new tests, already covered by existing W3C tests.
* dom/ContainerNode.cpp:
(WebCore::checkAcceptChild):
(WebCore::checkAddChild):
(WebCore::checkReplaceChild):
(WebCore::ContainerNode::insertBefore):
(WebCore::ContainerNode::appendChild):
(WebCore::containsConsideringHostElements): Deleted.
(WebCore::checkAcceptChildGuaranteedNodeTypes): Deleted.
* dom/Document.cpp:
(WebCore::Document::canAcceptChild):
(WebCore::Document::cloneNodeInternal): Deleted.
* dom/Document.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsdomnodesNodeinsertBeforeexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-insertBefore-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsdomnodesNodereplaceChildexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-replaceChild-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsdomnodesappendonDocumentexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/append-on-Document-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsdomnodesprependonDocumentexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/prepend-on-Document-expected.txt</a></li>
<li><a href="#trunkLayoutTestsuserscriptsmixedcasestylesheethtml">trunk/LayoutTests/userscripts/mixed-case-stylesheet.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomContainerNodecpp">trunk/Source/WebCore/dom/ContainerNode.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/LayoutTests/imported/w3c/ChangeLog        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -1,5 +1,20 @@
</span><span class="cx"> 2015-09-13 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><ins>+ Improve Node pre-insertion validation when the parent is a Document
+ https://bugs.webkit.org/show_bug.cgi?id=149109
+ <rdar://problem/22560436>
+
+ Reviewed by Ryosuke Niwa.
+
+ Rebaseline several W3C tests now that more checks are passing.
+
+ * web-platform-tests/dom/nodes/Node-insertBefore-expected.txt:
+ * web-platform-tests/dom/nodes/Node-replaceChild-expected.txt:
+ * web-platform-tests/dom/nodes/append-on-Document-expected.txt:
+ * web-platform-tests/dom/nodes/prepend-on-Document-expected.txt:
+
+2015-09-13 Chris Dumez <cdumez@apple.com>
+
</ins><span class="cx"> Document.adoptNode() should be able to explicitly adopt a DocumentType node
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=149097
</span><span class="cx"> <rdar://problem/22549345>
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsdomnodesNodeinsertBeforeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-insertBefore-expected.txt (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-insertBefore-expected.txt        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-insertBefore-expected.txt        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -11,33 +11,17 @@
</span><span class="cx"> PASS Calling insertBefore with an inclusive ancestor of the context object must throw HIERARCHY_REQUEST_ERR.
</span><span class="cx"> PASS Calling insertBefore with a reference child whose parent is not the context node must throw a NotFoundError.
</span><span class="cx"> PASS If the context node is a document, inserting a document or text node should throw a HierarchyRequestError.
</span><del>-FAIL If the context node is a document, appending a DocumentFragment that contains a text node or too many elements should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.insertBefore(df, null);
- }" did not throw
-FAIL If the context node is a document, inserting a DocumentFragment that contains a text node or too many elements should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.insertBefore(df, doc.firstChild);
- }" did not throw
</del><ins>+PASS If the context node is a document, appending a DocumentFragment that contains a text node or too many elements should throw a HierarchyRequestError.
+PASS If the context node is a document, inserting a DocumentFragment that contains a text node or too many elements should throw a HierarchyRequestError.
</ins><span class="cx"> PASS If the context node is a document, inserting a DocumentFragment with an element if there already is an element child should throw a HierarchyRequestError.
</span><del>-FAIL If the context node is a document and a doctype is following the reference child, inserting a DocumentFragment with an element should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.insertBefore(df, doc.doctype);
- }" did not throw
-FAIL If the context node is a document, inserting a DocumentFragment with an element before the doctype should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.insertBefore(df, comment);
- }" did not throw
</del><ins>+PASS If the context node is a document and a doctype is following the reference child, inserting a DocumentFragment with an element should throw a HierarchyRequestError.
+PASS If the context node is a document, inserting a DocumentFragment with an element before the doctype should throw a HierarchyRequestError.
</ins><span class="cx"> PASS If the context node is a document, inserting an element if there already is an element child should throw a HierarchyRequestError.
</span><del>-FAIL If the context node is a document, inserting an element before the doctype should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.insertBefore(a, doc.doctype);
- }" did not throw
-FAIL If the context node is a document and a doctype is following the reference child, inserting an element should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.insertBefore(a, comment);
- }" did not throw
</del><ins>+PASS If the context node is a document, inserting an element before the doctype should throw a HierarchyRequestError.
+PASS If the context node is a document and a doctype is following the reference child, inserting an element should throw a HierarchyRequestError.
</ins><span class="cx"> PASS If the context node is a document, inserting a doctype if there already is a doctype child should throw a HierarchyRequestError.
</span><del>-FAIL If the context node is a document, inserting a doctype after the document element should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.insertBefore(doctype, comment);
- }" did not throw
-FAIL If the context node is a document with and element child, appending a doctype should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.insertBefore(doctype, null);
- }" did not throw
</del><ins>+PASS If the context node is a document, inserting a doctype after the document element should throw a HierarchyRequestError.
+PASS If the context node is a document with and element child, appending a doctype should throw a HierarchyRequestError.
</ins><span class="cx"> PASS If the context node is a DocumentFragment, inserting a document or a doctype should throw a HierarchyRequestError.
</span><span class="cx"> PASS If the context node is an element, inserting a document or a doctype should throw a HierarchyRequestError.
</span><span class="cx"> PASS Inserting a node before itself should not move the node
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsdomnodesNodereplaceChildexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-replaceChild-expected.txt (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-replaceChild-expected.txt        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-replaceChild-expected.txt        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -9,17 +9,11 @@
</span><span class="cx"> PASS If the context node is a document, inserting a DocumentFragment that contains a text node or too many elements should throw a HierarchyRequestError.
</span><span class="cx"> PASS If the context node is a document (without element children), inserting a DocumentFragment that contains multiple elements should throw a HierarchyRequestError.
</span><span class="cx"> PASS If the context node is a document, inserting a DocumentFragment with an element if there already is an element child should throw a HierarchyRequestError.
</span><del>-FAIL If the context node is a document, inserting a DocumentFragment with an element before the doctype should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.replaceChild(df, comment);
- }" did not throw
</del><ins>+PASS If the context node is a document, inserting a DocumentFragment with an element before the doctype should throw a HierarchyRequestError.
</ins><span class="cx"> PASS If the context node is a document, inserting an element if there already is an element child should throw a HierarchyRequestError.
</span><del>-FAIL If the context node is a document, inserting an element before the doctype should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.replaceChild(a, comment);
- }" did not throw
</del><ins>+PASS If the context node is a document, inserting an element before the doctype should throw a HierarchyRequestError.
</ins><span class="cx"> PASS If the context node is a document, inserting a doctype if there already is a doctype child should throw a HierarchyRequestError.
</span><del>-FAIL If the context node is a document, inserting a doctype after the document element should throw a HierarchyRequestError. assert_throws: function "function () {
- doc.replaceChild(doctype, comment);
- }" did not throw
</del><ins>+PASS If the context node is a document, inserting a doctype after the document element should throw a HierarchyRequestError.
</ins><span class="cx"> PASS If the context node is a DocumentFragment, inserting a document or a doctype should throw a HierarchyRequestError.
</span><span class="cx"> PASS If the context node is an element, inserting a document or a doctype should throw a HierarchyRequestError.
</span><span class="cx"> PASS Replacing a node with its next sibling should work (2 children)
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsdomnodesappendonDocumentexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/append-on-Document-expected.txt (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/append-on-Document-expected.txt        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/append-on-Document-expected.txt        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -3,5 +3,5 @@
</span><span class="cx"> PASS Document.append() with only one element as an argument, on a Document having no child.
</span><span class="cx"> PASS Document.append() with only one element as an argument, on a Document having one child.
</span><span class="cx"> PASS Document.append() with text as an argument, on a Document having no child.
</span><del>-FAIL Document.append() with two elements as the argument, on a Document having no child. assert_throws: function "function () { parent.append(x, y); }" did not throw
</del><ins>+PASS Document.append() with two elements as the argument, on a Document having no child.
</ins><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsdomnodesprependonDocumentexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/prepend-on-Document-expected.txt (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/prepend-on-Document-expected.txt        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/prepend-on-Document-expected.txt        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -3,5 +3,5 @@
</span><span class="cx"> PASS Document.prepend() with only one element as an argument, on a Document having no child.
</span><span class="cx"> PASS Document.append() with only one element as an argument, on a Document having one child.
</span><span class="cx"> PASS Document.prepend() with text as an argument, on a Document having no child.
</span><del>-FAIL Document.prepend() with two elements as the argument, on a Document having no child. assert_throws: function "function () { parent.prepend(x, y); }" did not throw
</del><ins>+PASS Document.prepend() with two elements as the argument, on a Document having no child.
</ins><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsuserscriptsmixedcasestylesheethtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/userscripts/mixed-case-stylesheet.html (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/userscripts/mixed-case-stylesheet.html        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/LayoutTests/userscripts/mixed-case-stylesheet.html        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -9,7 +9,7 @@
</span><span class="cx"> </head>
</span><span class="cx"> <body>
</span><span class="cx"> <script>
</span><del>-document.appendChild(document.implementation.createDocumentType("html", 0, 0));
</del><ins>+document.prepend(document.implementation.createDocumentType("html", 0, 0));
</ins><span class="cx"> </script>
</span><span class="cx"> <div>If the word fail appears below, then test has failed.</div>
</span><span class="cx"> <div id="mixedCase">FAIL</div>
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/Source/WebCore/ChangeLog        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -1,5 +1,54 @@
</span><span class="cx"> 2015-09-13 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><ins>+ Improve Node pre-insertion validation when the parent is a Document
+ https://bugs.webkit.org/show_bug.cgi?id=149109
+ <rdar://problem/22560436>
+
+ Reviewed by Ryosuke Niwa.
+
+ Improve Node pre-insertion validation when the parent is a Document to
+ match the specification:
+ https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
+ https://dom.spec.whatwg.org/#concept-node-replace
+
+ This affects the following API: Node.insertBefore(), Node.appendChild(),
+ Node.replaceChild().
+
+ WebKit current fails to do the following checks whenever the parent is a
+ Document from pre-insertion validation:
+ 1. If the inserted Node is a DocumentFragment, we should make sure it
+ contains only one Element.
+ -> This is because a Document can have only one child that is an
+ Element [1].
+ 2.a. If an Element is inserted, we should make sure it is not inserted
+ before a DocumentType.
+ 2.b. If a DocumentType is inserted, we should make sure it is not
+ inserted after an Element.
+ -> This is because the DocType must come before the optional Element
+ child [1].
+
+ Firefox and Chrome already match the specification here. This patch
+ aligns WebKit's behavior with those browsers and the specification.
+
+ [1] https://dom.spec.whatwg.org/#node-trees
+
+ No new tests, already covered by existing W3C tests.
+
+ * dom/ContainerNode.cpp:
+ (WebCore::checkAcceptChild):
+ (WebCore::checkAddChild):
+ (WebCore::checkReplaceChild):
+ (WebCore::ContainerNode::insertBefore):
+ (WebCore::ContainerNode::appendChild):
+ (WebCore::containsConsideringHostElements): Deleted.
+ (WebCore::checkAcceptChildGuaranteedNodeTypes): Deleted.
+ * dom/Document.cpp:
+ (WebCore::Document::canAcceptChild):
+ (WebCore::Document::cloneNodeInternal): Deleted.
+ * dom/Document.h:
+
+2015-09-13 Chris Dumez <cdumez@apple.com>
+
</ins><span class="cx"> Document.adoptNode() should be able to explicitly adopt a DocumentType node
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=149097
</span><span class="cx"> <rdar://problem/22549345>
</span></span></pre></div>
<a id="trunkSourceWebCoredomContainerNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ContainerNode.cpp        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -176,7 +176,7 @@
</span><span class="cx"> : newChild.contains(&newParent);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static inline ExceptionCode checkAcceptChild(ContainerNode& newParent, Node& newChild, Node* oldChild)
</del><ins>+static inline ExceptionCode checkAcceptChild(ContainerNode& newParent, Node& newChild, const Node* refChild, Document::AcceptChildOperation operation)
</ins><span class="cx"> {
</span><span class="cx"> // Use common case fast path if possible.
</span><span class="cx"> if ((newChild.isElementNode() || newChild.isTextNode()) && newParent.isElementNode()) {
</span><span class="lines">@@ -198,8 +198,8 @@
</span><span class="cx"> if (containsConsideringHostElements(newChild, newParent))
</span><span class="cx"> return HIERARCHY_REQUEST_ERR;
</span><span class="cx">
</span><del>- if (oldChild && is<Document>(newParent)) {
- if (!downcast<Document>(newParent).canReplaceChild(newChild, *oldChild))
</del><ins>+ if (is<Document>(newParent)) {
+ if (!downcast<Document>(newParent).canAcceptChild(newChild, refChild, operation))
</ins><span class="cx"> return HIERARCHY_REQUEST_ERR;
</span><span class="cx"> } else if (!isChildTypeAllowed(newParent, newChild))
</span><span class="cx"> return HIERARCHY_REQUEST_ERR;
</span><span class="lines">@@ -220,15 +220,15 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static inline bool checkAddChild(ContainerNode& newParent, Node& newChild, ExceptionCode& ec)
</del><ins>+static inline bool checkAddChild(ContainerNode& newParent, Node& newChild, Node* refChild, ExceptionCode& ec)
</ins><span class="cx"> {
</span><del>- ec = checkAcceptChild(newParent, newChild, nullptr);
</del><ins>+ ec = checkAcceptChild(newParent, newChild, refChild, Document::AcceptChildOperation::InsertOrAdd);
</ins><span class="cx"> return !ec;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static inline bool checkReplaceChild(ContainerNode& newParent, Node& newChild, Node& oldChild, ExceptionCode& ec)
</span><span class="cx"> {
</span><del>- ec = checkAcceptChild(newParent, newChild, &oldChild);
</del><ins>+ ec = checkAcceptChild(newParent, newChild, &oldChild, Document::AcceptChildOperation::Replace);
</ins><span class="cx"> return !ec;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -247,7 +247,7 @@
</span><span class="cx"> return appendChild(WTF::move(newChild), ec);
</span><span class="cx">
</span><span class="cx"> // Make sure adding the new child is OK.
</span><del>- if (!checkAddChild(*this, newChild, ec))
</del><ins>+ if (!checkAddChild(*this, newChild, refChild, ec))
</ins><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> // NOT_FOUND_ERR: Raised if refChild is not a child of this node
</span><span class="lines">@@ -666,7 +666,7 @@
</span><span class="cx"> ec = 0;
</span><span class="cx">
</span><span class="cx"> // Make sure adding the new child is ok
</span><del>- if (!checkAddChild(*this, newChild, ec))
</del><ins>+ if (!checkAddChild(*this, newChild, nullptr, ec))
</ins><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> if (newChild.ptr() == m_lastChild) // nothing to do
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/Source/WebCore/dom/Document.cpp        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -3340,82 +3340,74 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool Document::canReplaceChild(Node& newChild, Node& oldChild)
</del><ins>+bool Document::canAcceptChild(const Node& newChild, const Node* refChild, AcceptChildOperation operation) const
</ins><span class="cx"> {
</span><del>- if (oldChild.nodeType() == newChild.nodeType())
</del><ins>+ if (operation == AcceptChildOperation::Replace && refChild->nodeType() == newChild.nodeType())
</ins><span class="cx"> return true;
</span><span class="cx">
</span><del>- int numDoctypes = 0;
- int numElements = 0;
-
- // First, check how many doctypes and elements we have, not counting
- // the child we're about to remove.
- for (Node* c = firstChild(); c; c = c->nextSibling()) {
- if (c == &oldChild)
- continue;
-
- switch (c->nodeType()) {
- case DOCUMENT_TYPE_NODE:
- numDoctypes++;
- break;
- case ELEMENT_NODE:
- numElements++;
- break;
- default:
- break;
</del><ins>+ switch (newChild.nodeType()) {
+ case ATTRIBUTE_NODE:
+ case CDATA_SECTION_NODE:
+ case DOCUMENT_NODE:
+ case ENTITY_NODE:
+ case ENTITY_REFERENCE_NODE:
+ case TEXT_NODE:
+ case XPATH_NAMESPACE_NODE:
+ return false;
+ case COMMENT_NODE:
+ case PROCESSING_INSTRUCTION_NODE:
+ return true;
+ case DOCUMENT_FRAGMENT_NODE: {
+ bool hasSeenElementChild = false;
+ for (auto* node = downcast<DocumentFragment>(newChild).firstChild(); node; node = node->nextSibling()) {
+ if (is<Element>(*node)) {
+ if (hasSeenElementChild)
+ return false;
+ hasSeenElementChild = true;
+ }
+ if (!canAcceptChild(*node, refChild, operation))
+ return false;
</ins><span class="cx"> }
</span><ins>+ break;
</ins><span class="cx"> }
</span><del>-
- // Then, see how many doctypes and elements might be added by the new child.
- if (newChild.isDocumentFragment()) {
- for (Node* c = newChild.firstChild(); c; c = c->nextSibling()) {
- switch (c->nodeType()) {
- case ATTRIBUTE_NODE:
- case CDATA_SECTION_NODE:
- case DOCUMENT_FRAGMENT_NODE:
- case DOCUMENT_NODE:
- case ENTITY_NODE:
- case ENTITY_REFERENCE_NODE:
- case TEXT_NODE:
- case XPATH_NAMESPACE_NODE:
</del><ins>+ case DOCUMENT_TYPE_NODE: {
+ auto* existingDocType = childrenOfType<DocumentType>(*this).first();
+ if (operation == AcceptChildOperation::Replace) {
+ // parent has a doctype child that is not child, or an element is preceding child.
+ if (existingDocType && existingDocType != refChild)
</ins><span class="cx"> return false;
</span><del>- case COMMENT_NODE:
- case PROCESSING_INSTRUCTION_NODE:
- break;
- case DOCUMENT_TYPE_NODE:
- numDoctypes++;
- break;
- case ELEMENT_NODE:
- numElements++;
- break;
</del><ins>+ if (refChild->previousElementSibling())
+ return false;
+ } else {
+ ASSERT(operation == AcceptChildOperation::InsertOrAdd);
+ if (existingDocType)
+ return false;
+ if ((refChild && refChild->previousElementSibling()) || (!refChild && firstElementChild()))
+ return false;
+ }
+ break;
+ }
+ case ELEMENT_NODE: {
+ auto* existingElementChild = firstElementChild();
+ if (operation == AcceptChildOperation::Replace) {
+ if (existingElementChild && existingElementChild != refChild)
+ return false;
+ for (auto* child = refChild->nextSibling(); child; child = child->nextSibling()) {
+ if (is<DocumentType>(*child))
+ return false;
</ins><span class="cx"> }
</span><ins>+ } else {
+ ASSERT(operation == AcceptChildOperation::InsertOrAdd);
+ if (existingElementChild)
+ return false;
+ for (auto* child = refChild; child; child = child->nextSibling()) {
+ if (is<DocumentType>(*child))
+ return false;
+ }
</ins><span class="cx"> }
</span><del>- } else {
- switch (newChild.nodeType()) {
- case ATTRIBUTE_NODE:
- case CDATA_SECTION_NODE:
- case DOCUMENT_FRAGMENT_NODE:
- case DOCUMENT_NODE:
- case ENTITY_NODE:
- case ENTITY_REFERENCE_NODE:
- case TEXT_NODE:
- case XPATH_NAMESPACE_NODE:
- return false;
- case COMMENT_NODE:
- case PROCESSING_INSTRUCTION_NODE:
- return true;
- case DOCUMENT_TYPE_NODE:
- numDoctypes++;
- break;
- case ELEMENT_NODE:
- numElements++;
- break;
- }
</del><ins>+ break;
</ins><span class="cx"> }
</span><del>-
- if (numElements > 1 || numDoctypes > 1)
- return false;
-
</del><ins>+ }
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (189681 => 189682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2015-09-14 05:06:40 UTC (rev 189681)
+++ trunk/Source/WebCore/dom/Document.h        2015-09-14 05:08:39 UTC (rev 189682)
</span><span class="lines">@@ -744,7 +744,8 @@
</span><span class="cx"> void nodeChildrenWillBeRemoved(ContainerNode&);
</span><span class="cx"> // nodeWillBeRemoved is only safe when removing one node at a time.
</span><span class="cx"> void nodeWillBeRemoved(Node&);
</span><del>- bool canReplaceChild(Node& newChild, Node& oldChild);
</del><ins>+ enum class AcceptChildOperation { Replace, InsertOrAdd };
+ bool canAcceptChild(const Node& newChild, const Node* refChild, AcceptChildOperation) const;
</ins><span class="cx">
</span><span class="cx"> void textInserted(Node*, unsigned offset, unsigned length);
</span><span class="cx"> void textRemoved(Node*, unsigned offset, unsigned length);
</span></span></pre>
</div>
</div>
</body>
</html>