<!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>[185435] 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/185435">185435</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-06-10 16:07:55 -0700 (Wed, 10 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>ASSERT_WITH_SECURITY_IMPLICATION in WebCore::DocumentOrderedMap::getElementById
https://bugs.webkit.org/show_bug.cgi?id=145857
&lt;rdar://problem/16798440&gt;

Reviewed by Darin Adler.

Source/WebCore:

Make sure Node::insertedInto() gets called on the inserted node and its
descendants after its insertion into the tree but *before*
ContainerNode::childrenChanged() is called on the parent node. This is
needed so that the descendants know they've been inserted into the tree
(and their InDocumentFlag flag gets set) before the parent node does
anything with them in childrenChanged().

In the case of &lt;rdar://problem/16798440&gt;, executing HTMLScriptElement's
childrenChanged() after appending a child to a script element was causing
the script to be executed. The script would call getElementBy() which
would traverse the DOM tree and find a matching Element in the newly
inserted subtree. However, the matching Element's InDocumentFlag flag was
not set yet because the element's insertedInto() method has not been called
yet at this point. This would cause us to hit an assertion as
DocumentOrderedMap::getElementById() is only supposed to return elements
that are in a Document.

This patch is based on Blink <a href="http://trac.webkit.org/projects/webkit/changeset/178976">r178976</a> by &lt;esprehn@chromium.org&gt;:
https://src.chromium.org/viewvc/blink?view=rev&amp;revision=178976

Tests: fast/dom/script-getElementById-during-insertion.html
       fast/dom/script-remove-child-id-map.html

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::notifyChildInserted):
(WebCore::ContainerNode::notifyChildRemoved):
(WebCore::ContainerNode::removeChildren):
(WebCore::ContainerNode::parserInsertBefore): Deleted.
(WebCore::ContainerNode::removeChild): Deleted.
(WebCore::ContainerNode::parserRemoveChild): Deleted.
(WebCore::ContainerNode::parserAppendChild): Deleted.
(WebCore::ContainerNode::childrenChanged): Deleted.
(WebCore::ContainerNode::setAttributeEventListener): Deleted.
(WebCore::ContainerNode::querySelector): Deleted.
* dom/ContainerNodeAlgorithms.cpp:
(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree):
* dom/ContainerNodeAlgorithms.h:
(WebCore::ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument):
(WebCore::ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree):
(WebCore::ChildNodeInsertionNotifier::notify):
(WebCore::ChildNodeRemovalNotifier::notifyNodeRemovedFromDocument): Deleted.
* dom/Element.cpp:
(WebCore::Element::addShadowRoot):

LayoutTests:

Add layout tests covering different crashes caused by the same bug.

* fast/dom/script-getElementById-during-insertion-expected.txt: Added.
* fast/dom/script-getElementById-during-insertion.html: Added.

Reduction test case for &lt;rdar://problem/16798440&gt;.

* fast/dom/script-remove-child-id-map-expected.txt: Added.
* fast/dom/script-remove-child-id-map.html: Added.

Test imported from Blink <a href="http://trac.webkit.org/projects/webkit/changeset/178976">r178976</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</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="#trunkSourceWebCoredomContainerNodeAlgorithmscpp">trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp</a></li>
<li><a href="#trunkSourceWebCoredomContainerNodeAlgorithmsh">trunk/Source/WebCore/dom/ContainerNodeAlgorithms.h</a></li>
<li><a href="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastdomscriptgetElementByIdduringinsertionexpectedtxt">trunk/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomscriptgetElementByIdduringinsertionhtml">trunk/LayoutTests/fast/dom/script-getElementById-during-insertion.html</a></li>
<li><a href="#trunkLayoutTestsfastdomscriptremovechildidmapexpectedtxt">trunk/LayoutTests/fast/dom/script-remove-child-id-map-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomscriptremovechildidmaphtml">trunk/LayoutTests/fast/dom/script-remove-child-id-map.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (185434 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-06-10 22:53:42 UTC (rev 185434)
+++ trunk/LayoutTests/ChangeLog        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2015-06-10  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        ASSERT_WITH_SECURITY_IMPLICATION in WebCore::DocumentOrderedMap::getElementById
+        https://bugs.webkit.org/show_bug.cgi?id=145857
+        &lt;rdar://problem/16798440&gt;
+
+        Reviewed by Darin Adler.
+
+        Add layout tests covering different crashes caused by the same bug.
+
+        * fast/dom/script-getElementById-during-insertion-expected.txt: Added.
+        * fast/dom/script-getElementById-during-insertion.html: Added.
+
+        Reduction test case for &lt;rdar://problem/16798440&gt;.
+
+        * fast/dom/script-remove-child-id-map-expected.txt: Added.
+        * fast/dom/script-remove-child-id-map.html: Added.
+
+        Test imported from Blink r178976.
+
</ins><span class="cx"> 2015-06-10  Jordan Harband  &lt;ljharb@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement RegExp.prototype.flags
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomscriptgetElementByIdduringinsertionexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt (0 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -0,0 +1,2 @@
</span><ins>+PASS
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomscriptgetElementByIdduringinsertionhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/script-getElementById-during-insertion.html (0 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/script-getElementById-during-insertion.html                                (rev 0)
+++ trunk/LayoutTests/fast/dom/script-getElementById-during-insertion.html        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script&gt;
+// Tests that we don't crash if a script is being executed as a result of appending a child to it.&lt;/p&gt;
+executedScript = false;
+if (window.testRunner)
+  testRunner.dumpAsText();
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div id=&quot;test&quot;&gt;&lt;/div&gt;
+&lt;script&gt;
+var elem = document.getElementById(&quot;test&quot;);
+if (!executedScript) {
+    executedScript = true;
+
+    document.documentElement.appendChild(elem.cloneNode(true));
+
+    var range = document.createRange();
+    range.setStartBefore(document.body);
+    range.setEndAfter(document.body);
+    range.surroundContents(document.head.appendChild(document.createElement(&quot;script&quot;)));
+} else {
+    var span = document.createElement(&quot;span&quot;);
+    document.documentElement.appendChild(span);
+    span.innerHTML = 'PASS&lt;br/&gt;';
+}
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomscriptremovechildidmapexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/script-remove-child-id-map-expected.txt (0 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/script-remove-child-id-map-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/dom/script-remove-child-id-map-expected.txt        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+Passes if it doesn't crash and the child is not in the id map
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS document.getElementById('child') is null
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomscriptremovechildidmaphtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/script-remove-child-id-map.html (0 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/script-remove-child-id-map.html                                (rev 0)
+++ trunk/LayoutTests/fast/dom/script-remove-child-id-map.html        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -0,0 +1,30 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;script src=&quot;../../resources/js-test.js&quot;&gt;&lt;/script&gt;
+
+&lt;script&gt;
+description(&quot;Passes if it doesn't crash and the child is not in the id map&quot;);
+
+var script = document.createElement(&quot;script&quot;);
+script.type = &quot;dont-execute&quot;;
+script.textContent = &quot;script.remove()&quot;;
+child = document.createElement(&quot;div&quot;);
+child.id = &quot;child&quot;;
+script.appendChild(child);
+
+// The script won't execute here because the type is invalid, but it also won't
+// get marked as being already run, so changing the children later will run it.
+document.documentElement.appendChild(script);
+
+// Per the spec setting the type has no effect
+script.type = &quot;&quot;;
+
+// but changing the children *will* execute the script now that the type is
+// is valid.
+child.remove();
+
+child = null;
+gc();
+
+shouldBeNull(&quot;document.getElementById('child')&quot;);
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (185434 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-06-10 22:53:42 UTC (rev 185434)
+++ trunk/Source/WebCore/ChangeLog        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2015-06-10  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        ASSERT_WITH_SECURITY_IMPLICATION in WebCore::DocumentOrderedMap::getElementById
+        https://bugs.webkit.org/show_bug.cgi?id=145857
+        &lt;rdar://problem/16798440&gt;
+
+        Reviewed by Darin Adler.
+
+        Make sure Node::insertedInto() gets called on the inserted node and its
+        descendants after its insertion into the tree but *before*
+        ContainerNode::childrenChanged() is called on the parent node. This is
+        needed so that the descendants know they've been inserted into the tree
+        (and their InDocumentFlag flag gets set) before the parent node does
+        anything with them in childrenChanged().
+
+        In the case of &lt;rdar://problem/16798440&gt;, executing HTMLScriptElement's
+        childrenChanged() after appending a child to a script element was causing
+        the script to be executed. The script would call getElementBy() which
+        would traverse the DOM tree and find a matching Element in the newly
+        inserted subtree. However, the matching Element's InDocumentFlag flag was
+        not set yet because the element's insertedInto() method has not been called
+        yet at this point. This would cause us to hit an assertion as
+        DocumentOrderedMap::getElementById() is only supposed to return elements
+        that are in a Document.
+
+        This patch is based on Blink r178976 by &lt;esprehn@chromium.org&gt;:
+        https://src.chromium.org/viewvc/blink?view=rev&amp;revision=178976
+
+        Tests: fast/dom/script-getElementById-during-insertion.html
+               fast/dom/script-remove-child-id-map.html
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::notifyChildInserted):
+        (WebCore::ContainerNode::notifyChildRemoved):
+        (WebCore::ContainerNode::removeChildren):
+        (WebCore::ContainerNode::parserInsertBefore): Deleted.
+        (WebCore::ContainerNode::removeChild): Deleted.
+        (WebCore::ContainerNode::parserRemoveChild): Deleted.
+        (WebCore::ContainerNode::parserAppendChild): Deleted.
+        (WebCore::ContainerNode::childrenChanged): Deleted.
+        (WebCore::ContainerNode::setAttributeEventListener): Deleted.
+        (WebCore::ContainerNode::querySelector): Deleted.
+        * dom/ContainerNodeAlgorithms.cpp:
+        (WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
+        (WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree):
+        * dom/ContainerNodeAlgorithms.h:
+        (WebCore::ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument):
+        (WebCore::ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree):
+        (WebCore::ChildNodeInsertionNotifier::notify):
+        (WebCore::ChildNodeRemovalNotifier::notifyNodeRemovedFromDocument): Deleted.
+        * dom/Element.cpp:
+        (WebCore::Element::addShadowRoot):
+
</ins><span class="cx"> 2015-06-10  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [Web Timing] Fix flaky test.
</span></span></pre></div>
<a id="trunkSourceWebCoredomContainerNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (185434 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ContainerNode.cpp        2015-06-10 22:53:42 UTC (rev 185434)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -333,6 +333,11 @@
</span><span class="cx"> 
</span><span class="cx"> void ContainerNode::notifyChildInserted(Node&amp; child, ChildChangeSource source)
</span><span class="cx"> {
</span><ins>+    ChildListMutationScope(*this).childAdded(child);
+
+    NodeVector postInsertionNotificationTargets;
+    ChildNodeInsertionNotifier(*this).notify(child, postInsertionNotificationTargets);
+
</ins><span class="cx">     ChildChange change;
</span><span class="cx">     change.type = child.isElementNode() ? ElementInserted : child.isTextNode() ? TextInserted : NonContentsChildChanged;
</span><span class="cx">     change.previousSiblingElement = ElementTraversal::previousSibling(child);
</span><span class="lines">@@ -340,10 +345,15 @@
</span><span class="cx">     change.source = source;
</span><span class="cx"> 
</span><span class="cx">     childrenChanged(change);
</span><ins>+
+    for (auto&amp; target : postInsertionNotificationTargets)
+        target-&gt;didNotifySubtreeInsertions();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ContainerNode::notifyChildRemoved(Node&amp; child, Node* previousSibling, Node* nextSibling, ChildChangeSource source)
</span><span class="cx"> {
</span><ins>+    ChildNodeRemovalNotifier(*this).notify(child);
+
</ins><span class="cx">     ChildChange change;
</span><span class="cx">     change.type = is&lt;Element&gt;(child) ? ElementRemoved : is&lt;Text&gt;(child) ? TextRemoved : NonContentsChildChanged;
</span><span class="cx">     change.previousSiblingElement = (!previousSibling || is&lt;Element&gt;(*previousSibling)) ? downcast&lt;Element&gt;(previousSibling) : ElementTraversal::previousSibling(*previousSibling);
</span><span class="lines">@@ -373,12 +383,8 @@
</span><span class="cx"> 
</span><span class="cx">     newChild-&gt;updateAncestorConnectedSubframeCountForInsertion();
</span><span class="cx"> 
</span><del>-    ChildListMutationScope(*this).childAdded(*newChild);
-
</del><span class="cx">     notifyChildInserted(*newChild, ChildChangeSourceParser);
</span><span class="cx"> 
</span><del>-    ChildNodeInsertionNotifier(*this).notify(*newChild);
-
</del><span class="cx">     newChild-&gt;setNeedsStyleRecalc(ReconstructRenderTree);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -563,8 +569,6 @@
</span><span class="cx">         removeBetween(prev, next, child);
</span><span class="cx"> 
</span><span class="cx">         notifyChildRemoved(child, prev, next, ChildChangeSourceAPI);
</span><del>-
-        ChildNodeRemovalNotifier(*this).notify(child);
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -621,8 +625,6 @@
</span><span class="cx">     removeBetween(prev, next, oldChild);
</span><span class="cx"> 
</span><span class="cx">     notifyChildRemoved(oldChild, prev, next, ChildChangeSourceParser);
</span><del>-
-    ChildNodeRemovalNotifier(*this).notify(oldChild);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // this differs from other remove functions because it forcibly removes all the children,
</span><span class="lines">@@ -646,23 +648,18 @@
</span><span class="cx">     // and remove... e.g. stop loading frames, fire unload events.
</span><span class="cx">     willRemoveChildren(*this);
</span><span class="cx"> 
</span><del>-    NodeVector removedChildren;
</del><span class="cx">     {
</span><span class="cx">         WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
</span><span class="cx">         {
</span><span class="cx">             NoEventDispatchAssertion assertNoEventDispatch;
</span><del>-            removedChildren.reserveInitialCapacity(countChildNodes());
</del><span class="cx">             while (RefPtr&lt;Node&gt; n = m_firstChild) {
</span><del>-                removedChildren.append(*m_firstChild);
</del><span class="cx">                 removeBetween(0, m_firstChild-&gt;nextSibling(), *m_firstChild);
</span><ins>+                ChildNodeRemovalNotifier(*this).notify(*n);
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         ChildChange change = { AllChildrenRemoved, nullptr, nullptr, ChildChangeSourceAPI };
</span><span class="cx">         childrenChanged(change);
</span><del>-        
-        for (auto&amp; removedChild : removedChildren)
-            ChildNodeRemovalNotifier(*this).notify(removedChild);
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (document().svgExtensions()) {
</span><span class="lines">@@ -752,12 +749,8 @@
</span><span class="cx"> 
</span><span class="cx">     newChild-&gt;updateAncestorConnectedSubframeCountForInsertion();
</span><span class="cx"> 
</span><del>-    ChildListMutationScope(*this).childAdded(*newChild);
-
</del><span class="cx">     notifyChildInserted(*newChild, ChildChangeSourceParser);
</span><span class="cx"> 
</span><del>-    ChildNodeInsertionNotifier(*this).notify(*newChild);
-
</del><span class="cx">     newChild-&gt;setNeedsStyleRecalc(ReconstructRenderTree);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -848,12 +841,8 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(child.refCount());
</span><span class="cx"> 
</span><del>-    ChildListMutationScope(*this).childAdded(child);
-
</del><span class="cx">     notifyChildInserted(child, ChildChangeSourceAPI);
</span><span class="cx"> 
</span><del>-    ChildNodeInsertionNotifier(*this).notify(child);
-
</del><span class="cx">     child.setNeedsStyleRecalc(ReconstructRenderTree);
</span><span class="cx"> 
</span><span class="cx">     dispatchChildInsertionEvents(child);
</span></span></pre></div>
<a id="trunkSourceWebCoredomContainerNodeAlgorithmscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp (185434 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp        2015-06-10 22:53:42 UTC (rev 185434)
+++ trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -29,7 +29,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerNode&amp; node)
</del><ins>+void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerNode&amp; node, NodeVector&amp; postInsertionNotificationTargets)
</ins><span class="cx"> {
</span><span class="cx">     ChildNodesLazySnapshot snapshot(node);
</span><span class="cx">     while (RefPtr&lt;Node&gt; child = snapshot.nextNode()) {
</span><span class="lines">@@ -37,7 +37,7 @@
</span><span class="cx">         // we don't want to tell the rest of our children that they've been
</span><span class="cx">         // inserted into the document because they haven't.
</span><span class="cx">         if (node.inDocument() &amp;&amp; child-&gt;parentNode() == &amp;node)
</span><del>-            notifyNodeInsertedIntoDocument(*child);
</del><ins>+            notifyNodeInsertedIntoDocument(*child, postInsertionNotificationTargets);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (!is&lt;Element&gt;(node))
</span><span class="lines">@@ -45,19 +45,19 @@
</span><span class="cx"> 
</span><span class="cx">     if (RefPtr&lt;ShadowRoot&gt; root = downcast&lt;Element&gt;(node).shadowRoot()) {
</span><span class="cx">         if (node.inDocument() &amp;&amp; root-&gt;hostElement() == &amp;node)
</span><del>-            notifyNodeInsertedIntoDocument(*root);
</del><ins>+            notifyNodeInsertedIntoDocument(*root, postInsertionNotificationTargets);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree(ContainerNode&amp; node)
</del><ins>+void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree(ContainerNode&amp; node, NodeVector&amp; postInsertionNotificationTargets)
</ins><span class="cx"> {
</span><span class="cx">     for (Node* child = node.firstChild(); child; child = child-&gt;nextSibling()) {
</span><span class="cx">         if (is&lt;ContainerNode&gt;(*child))
</span><del>-            notifyNodeInsertedIntoTree(downcast&lt;ContainerNode&gt;(*child));
</del><ins>+            notifyNodeInsertedIntoTree(downcast&lt;ContainerNode&gt;(*child), postInsertionNotificationTargets);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (ShadowRoot* root = node.shadowRoot())
</span><del>-        notifyNodeInsertedIntoTree(*root);
</del><ins>+        notifyNodeInsertedIntoTree(*root, postInsertionNotificationTargets);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument(ContainerNode&amp; node)
</span></span></pre></div>
<a id="trunkSourceWebCoredomContainerNodeAlgorithmsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ContainerNodeAlgorithms.h (185434 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ContainerNodeAlgorithms.h        2015-06-10 22:53:42 UTC (rev 185434)
+++ trunk/Source/WebCore/dom/ContainerNodeAlgorithms.h        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -41,16 +41,15 @@
</span><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void notify(Node&amp;);
</del><ins>+    void notify(Node&amp;, NodeVector&amp; postInsertionNotificationTargets);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void notifyDescendantInsertedIntoDocument(ContainerNode&amp;);
-    void notifyDescendantInsertedIntoTree(ContainerNode&amp;);
-    void notifyNodeInsertedIntoDocument(Node&amp;);
-    void notifyNodeInsertedIntoTree(ContainerNode&amp;);
</del><ins>+    void notifyDescendantInsertedIntoDocument(ContainerNode&amp;, NodeVector&amp; postInsertionNotificationTargets);
+    void notifyDescendantInsertedIntoTree(ContainerNode&amp;, NodeVector&amp; postInsertionNotificationTargets);
+    void notifyNodeInsertedIntoDocument(Node&amp;, NodeVector&amp; postInsertionNotificationTargets);
+    void notifyNodeInsertedIntoTree(ContainerNode&amp;, NodeVector&amp; postInsertionNotificationTargets);
</ins><span class="cx"> 
</span><span class="cx">     ContainerNode&amp; m_insertionPoint;
</span><del>-    Vector&lt;Ref&lt;Node&gt;&gt; m_postInsertionNotificationTargets;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> class ChildNodeRemovalNotifier {
</span><span class="lines">@@ -193,26 +192,26 @@
</span><span class="cx"> 
</span><span class="cx"> } // namespace Private
</span><span class="cx"> 
</span><del>-inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument(Node&amp; node)
</del><ins>+inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument(Node&amp; node, NodeVector&amp; postInsertionNotificationTargets)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(m_insertionPoint.inDocument());
</span><span class="cx">     if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.insertedInto(m_insertionPoint))
</span><del>-        m_postInsertionNotificationTargets.append(node);
</del><ins>+        postInsertionNotificationTargets.append(node);
</ins><span class="cx">     if (is&lt;ContainerNode&gt;(node))
</span><del>-        notifyDescendantInsertedIntoDocument(downcast&lt;ContainerNode&gt;(node));
</del><ins>+        notifyDescendantInsertedIntoDocument(downcast&lt;ContainerNode&gt;(node), postInsertionNotificationTargets);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree(ContainerNode&amp; node)
</del><ins>+inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree(ContainerNode&amp; node, NodeVector&amp; postInsertionNotificationTargets)
</ins><span class="cx"> {
</span><span class="cx">     NoEventDispatchAssertion assertNoEventDispatch;
</span><span class="cx">     ASSERT(!m_insertionPoint.inDocument());
</span><span class="cx"> 
</span><span class="cx">     if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.insertedInto(m_insertionPoint))
</span><del>-        m_postInsertionNotificationTargets.append(node);
-    notifyDescendantInsertedIntoTree(node);
</del><ins>+        postInsertionNotificationTargets.append(node);
+    notifyDescendantInsertedIntoTree(node, postInsertionNotificationTargets);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline void ChildNodeInsertionNotifier::notify(Node&amp; node)
</del><ins>+inline void ChildNodeInsertionNotifier::notify(Node&amp; node, NodeVector&amp; postInsertionNotificationTargets)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT_WITH_SECURITY_IMPLICATION(!NoEventDispatchAssertion::isEventDispatchForbidden());
</span><span class="cx"> 
</span><span class="lines">@@ -222,12 +221,9 @@
</span><span class="cx">     Ref&lt;Node&gt; protectNode(node);
</span><span class="cx"> 
</span><span class="cx">     if (m_insertionPoint.inDocument())
</span><del>-        notifyNodeInsertedIntoDocument(node);
</del><ins>+        notifyNodeInsertedIntoDocument(node, postInsertionNotificationTargets);
</ins><span class="cx">     else if (is&lt;ContainerNode&gt;(node))
</span><del>-        notifyNodeInsertedIntoTree(downcast&lt;ContainerNode&gt;(node));
-
-    for (size_t i = 0; i &lt; m_postInsertionNotificationTargets.size(); ++i)
-        m_postInsertionNotificationTargets[i]-&gt;didNotifySubtreeInsertions();
</del><ins>+        notifyNodeInsertedIntoTree(downcast&lt;ContainerNode&gt;(node), postInsertionNotificationTargets);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (185434 => 185435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2015-06-10 22:53:42 UTC (rev 185434)
+++ trunk/Source/WebCore/dom/Element.cpp        2015-06-10 23:07:55 UTC (rev 185435)
</span><span class="lines">@@ -1632,8 +1632,12 @@
</span><span class="cx">     shadowRoot.setParentTreeScope(&amp;treeScope());
</span><span class="cx">     shadowRoot.distributor().didShadowBoundaryChange(this);
</span><span class="cx"> 
</span><del>-    ChildNodeInsertionNotifier(*this).notify(shadowRoot);
</del><ins>+    NodeVector postInsertionNotificationTargets;
+    ChildNodeInsertionNotifier(*this).notify(shadowRoot, postInsertionNotificationTargets);
</ins><span class="cx"> 
</span><ins>+    for (auto&amp; target : postInsertionNotificationTargets)
+        target-&gt;didNotifySubtreeInsertions();
+
</ins><span class="cx">     resetNeedsNodeRenderingTraversalSlowPath();
</span><span class="cx"> 
</span><span class="cx">     setNeedsStyleRecalc(ReconstructRenderTree);
</span></span></pre>
</div>
</div>

</body>
</html>