<!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>[163579] 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/163579">163579</a></dd>
<dt>Author</dt> <dd>jpfau@apple.com</dd>
<dt>Date</dt> <dd>2014-02-06 16:54:55 -0800 (Thu, 06 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make adoption agency use the task queue
https://bugs.webkit.org/show_bug.cgi?id=109445

Reviewed by Ryosuke Niwa.

Source/WebCore:

Tests: fast/parser/adoption-agency-crash-01.html
       fast/parser/adoption-agency-crash-02.html
       fast/parser/adoption-agency-crash-03.html

* html/parser/HTMLConstructionSite.cpp:
(WebCore::insert):
(WebCore::executeInsertTask):
(WebCore::executeReparentTask):
(WebCore::executeInsertAlreadyParsedChildTask):
(WebCore::executeTakeAllChildrenTask):
(WebCore::executeTask):
(WebCore::HTMLConstructionSite::attachLater):
(WebCore::HTMLConstructionSite::executeQueuedTasks):
(WebCore::HTMLConstructionSite::insertTextNode):
(WebCore::HTMLConstructionSite::reparent):
(WebCore::HTMLConstructionSite::insertAlreadyParsedChild):
(WebCore::HTMLConstructionSite::takeAllChildren):
(WebCore::HTMLConstructionSite::fosterParent):
* html/parser/HTMLConstructionSite.h:
(WebCore::HTMLConstructionSiteTask::HTMLConstructionSiteTask):
(WebCore::HTMLConstructionSiteTask::oldParent):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::callTheAdoptionAgency):

LayoutTests:

* TestExpectations:
* fast/parser/adoption-agency-crash-01-expected.txt: Added.
* fast/parser/adoption-agency-crash-01.html: Added.
* fast/parser/adoption-agency-crash-02-expected.txt: Added.
* fast/parser/adoption-agency-crash-02.html: Added.
* fast/parser/adoption-agency-crash-03-expected.txt: Added.
* fast/parser/adoption-agency-crash-03.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsTestExpectations">trunk/LayoutTests/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLConstructionSitecpp">trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLConstructionSiteh">trunk/Source/WebCore/html/parser/HTMLConstructionSite.h</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLTreeBuildercpp">trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastparseradoptionagencycrash01expectedtxt">trunk/LayoutTests/fast/parser/adoption-agency-crash-01-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastparseradoptionagencycrash01html">trunk/LayoutTests/fast/parser/adoption-agency-crash-01.html</a></li>
<li><a href="#trunkLayoutTestsfastparseradoptionagencycrash02expectedtxt">trunk/LayoutTests/fast/parser/adoption-agency-crash-02-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastparseradoptionagencycrash02html">trunk/LayoutTests/fast/parser/adoption-agency-crash-02.html</a></li>
<li><a href="#trunkLayoutTestsfastparseradoptionagencycrash03expectedtxt">trunk/LayoutTests/fast/parser/adoption-agency-crash-03-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastparseradoptionagencycrash03html">trunk/LayoutTests/fast/parser/adoption-agency-crash-03.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (163578 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-02-07 00:51:18 UTC (rev 163578)
+++ trunk/LayoutTests/ChangeLog        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2014-02-04  Jeffrey Pfau  &lt;jpfau@apple.com&gt;
+
+        Make adoption agency use the task queue
+        https://bugs.webkit.org/show_bug.cgi?id=109445
+
+        Reviewed by Ryosuke Niwa.
+
+        * TestExpectations:
+        * fast/parser/adoption-agency-crash-01-expected.txt: Added.
+        * fast/parser/adoption-agency-crash-01.html: Added.
+        * fast/parser/adoption-agency-crash-02-expected.txt: Added.
+        * fast/parser/adoption-agency-crash-02.html: Added.
+        * fast/parser/adoption-agency-crash-03-expected.txt: Added.
+        * fast/parser/adoption-agency-crash-03.html: Added.
+
</ins><span class="cx"> 2014-02-06  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Add Console support to JSContext Inspection
</span></span></pre></div>
<a id="trunkLayoutTestsTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/TestExpectations (163578 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/TestExpectations        2014-02-07 00:51:18 UTC (rev 163578)
+++ trunk/LayoutTests/TestExpectations        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -98,3 +98,7 @@
</span><span class="cx"> fast/harness/sample-fail-mismatch-reftest.html [ WontFix ImageOnlyFailure ]
</span><span class="cx"> 
</span><span class="cx"> webkit.org/b/127697 fast/writing-mode/ruby-text-logical-left.html [ Skip ]
</span><ins>+
+# These will be fixed soon
+[ Debug ] fast/parser/adoption-agency-crash-01.html [ Crash ]
+[ Debug ] fast/parser/adoption-agency-crash-03.html [ Crash ]
</ins></span></pre></div>
<a id="trunkLayoutTestsfastparseradoptionagencycrash01expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/parser/adoption-agency-crash-01-expected.txt (0 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/parser/adoption-agency-crash-01-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/parser/adoption-agency-crash-01-expected.txt        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -0,0 +1,2 @@
</span><ins>+PASS
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastparseradoptionagencycrash01html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/parser/adoption-agency-crash-01.html (0 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/parser/adoption-agency-crash-01.html                                (rev 0)
+++ trunk/LayoutTests/fast/parser/adoption-agency-crash-01.html        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+document.write('&lt;a&gt;&lt;p&gt;&lt;iframe onload=&quot;document.write(\'&lt;script&gt;void(0)&lt;\/script&gt;&lt;/a&gt;\');&quot;&gt;&lt;/iframe&gt;&lt;script&gt;document.body.innerHTML = \'PASS\';&lt;\/script&gt;');
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastparseradoptionagencycrash02expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/parser/adoption-agency-crash-02-expected.txt (0 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/parser/adoption-agency-crash-02-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/parser/adoption-agency-crash-02-expected.txt        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+PASS
</ins></span></pre></div>
<a id="trunkLayoutTestsfastparseradoptionagencycrash02html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/parser/adoption-agency-crash-02.html (0 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/parser/adoption-agency-crash-02.html                                (rev 0)
+++ trunk/LayoutTests/fast/parser/adoption-agency-crash-02.html        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+document.write('&lt;a&gt;&lt;p&gt;&lt;iframe onload=&quot;document.write(\'&lt;script&gt;document.body.innerHTML = &amp;quot;PASS&amp;quot;;&lt;\/script&gt;&lt;/a&gt;\');&quot;&gt;&lt;/iframe&gt;');
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastparseradoptionagencycrash03expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/parser/adoption-agency-crash-03-expected.txt (0 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/parser/adoption-agency-crash-03-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/parser/adoption-agency-crash-03-expected.txt        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -0,0 +1,2 @@
</span><ins>+PASS 1 of 2
+PASS 2 of 2
</ins></span></pre></div>
<a id="trunkLayoutTestsfastparseradoptionagencycrash03html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/parser/adoption-agency-crash-03.html (0 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/parser/adoption-agency-crash-03.html                                (rev 0)
+++ trunk/LayoutTests/fast/parser/adoption-agency-crash-03.html        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+&lt;/script&gt;
+&lt;iframe onload=&quot;document.write('&lt;a&gt;&lt;blockquote&gt;PASS 2 of 2&lt;iframe onload=&amp;quot;document.write(\'&lt;a&gt;\')&amp;quot;&gt;&lt;/iframe&gt;&lt;script&gt;document.body.innerHTML = \'PASS 1 of 2\';&lt;/script&gt;');&quot;&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163578 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-07 00:51:18 UTC (rev 163578)
+++ trunk/Source/WebCore/ChangeLog        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2014-02-04  Jeffrey Pfau  &lt;jpfau@apple.com&gt;
+
+        Make adoption agency use the task queue
+        https://bugs.webkit.org/show_bug.cgi?id=109445
+
+        Reviewed by Ryosuke Niwa.
+
+        Tests: fast/parser/adoption-agency-crash-01.html
+               fast/parser/adoption-agency-crash-02.html
+               fast/parser/adoption-agency-crash-03.html
+
+        * html/parser/HTMLConstructionSite.cpp:
+        (WebCore::insert):
+        (WebCore::executeInsertTask):
+        (WebCore::executeReparentTask):
+        (WebCore::executeInsertAlreadyParsedChildTask):
+        (WebCore::executeTakeAllChildrenTask):
+        (WebCore::executeTask):
+        (WebCore::HTMLConstructionSite::attachLater):
+        (WebCore::HTMLConstructionSite::executeQueuedTasks):
+        (WebCore::HTMLConstructionSite::insertTextNode):
+        (WebCore::HTMLConstructionSite::reparent):
+        (WebCore::HTMLConstructionSite::insertAlreadyParsedChild):
+        (WebCore::HTMLConstructionSite::takeAllChildren):
+        (WebCore::HTMLConstructionSite::fosterParent):
+        * html/parser/HTMLConstructionSite.h:
+        (WebCore::HTMLConstructionSiteTask::HTMLConstructionSiteTask):
+        (WebCore::HTMLConstructionSiteTask::oldParent):
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLTreeBuilder::callTheAdoptionAgency):
+
</ins><span class="cx"> 2014-02-06  Mark Hahnenberg  &lt;mhahnenberg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Heap::writeBarrier shouldn't be static
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLConstructionSitecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp (163578 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp        2014-02-07 00:51:18 UTC (rev 163578)
+++ trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -79,30 +79,86 @@
</span><span class="cx">     return string.isAllSpecialCharacters&lt;isHTMLSpace&gt;();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline void executeTask(HTMLConstructionSiteTask&amp; task)
</del><ins>+static inline void insert(HTMLConstructionSiteTask&amp; task)
</ins><span class="cx"> {
</span><span class="cx"> #if ENABLE(TEMPLATE_ELEMENT)
</span><span class="cx">     if (task.parent-&gt;hasTagName(templateTag))
</span><span class="cx">         task.parent = toHTMLTemplateElement(task.parent.get())-&gt;content();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    if (ContainerNode* parent = task.child-&gt;parentNode())
+        parent-&gt;parserRemoveChild(*task.child);
+
</ins><span class="cx">     if (task.nextChild)
</span><span class="cx">         task.parent-&gt;parserInsertBefore(task.child.get(), task.nextChild.get());
</span><span class="cx">     else
</span><span class="cx">         task.parent-&gt;parserAppendChild(task.child.get());
</span><ins>+}
</ins><span class="cx"> 
</span><ins>+static inline void executeInsertTask(HTMLConstructionSiteTask&amp; task)
+{
+    ASSERT(task.operation == HTMLConstructionSiteTask::Insert);
+
+    insert(task);
+
</ins><span class="cx">     task.child-&gt;beginParsingChildren();
</span><span class="cx"> 
</span><span class="cx">     if (task.selfClosing)
</span><span class="cx">         task.child-&gt;finishParsingChildren();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static inline void executeReparentTask(HTMLConstructionSiteTask&amp; task)
+{
+    ASSERT(task.operation == HTMLConstructionSiteTask::Reparent);
+
+    if (ContainerNode* parent = task.child-&gt;parentNode())
+        parent-&gt;parserRemoveChild(*task.child);
+
+    task.parent-&gt;parserAppendChild(task.child);
+}
+
+static inline void executeInsertAlreadyParsedChildTask(HTMLConstructionSiteTask&amp; task)
+{
+    ASSERT(task.operation == HTMLConstructionSiteTask::InsertAlreadyParsedChild);
+
+    insert(task);
+}
+
+static inline void executeTakeAllChildrenTask(HTMLConstructionSiteTask&amp; task)
+{
+    ASSERT(task.operation == HTMLConstructionSiteTask::TakeAllChildren);
+
+    task.parent-&gt;takeAllChildrenFrom(task.oldParent());
+    // Notice that we don't need to manually attach the moved children
+    // because takeAllChildrenFrom does that work for us.
+}
+
+static inline void executeTask(HTMLConstructionSiteTask&amp; task)
+{
+    switch (task.operation) {
+    case HTMLConstructionSiteTask::Insert:
+        executeInsertTask(task);
+        return;
+    // All the cases below this point are only used by the adoption agency.
+    case HTMLConstructionSiteTask::InsertAlreadyParsedChild:
+        executeInsertAlreadyParsedChildTask(task);
+        return;
+    case HTMLConstructionSiteTask::Reparent:
+        executeReparentTask(task);
+        return;
+    case HTMLConstructionSiteTask::TakeAllChildren:
+        executeTakeAllChildrenTask(task);
+        return;
+    }
+    ASSERT_NOT_REACHED();
+}
+
</ins><span class="cx"> void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtr&lt;Node&gt; prpChild, bool selfClosing)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()-&gt;isElementNode() || !toScriptElementIfPossible(toElement(prpChild.get())));
</span><span class="cx">     ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !prpChild-&gt;isPluginElement());
</span><span class="cx"> 
</span><del>-    HTMLConstructionSiteTask task;
</del><ins>+    HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert);
</ins><span class="cx">     task.parent = parent;
</span><span class="cx">     task.child = prpChild;
</span><span class="cx">     task.selfClosing = selfClosing;
</span><span class="lines">@@ -117,19 +173,18 @@
</span><span class="cx">         task.parent = task.parent-&gt;parentNode();
</span><span class="cx"> 
</span><span class="cx">     ASSERT(task.parent);
</span><del>-    m_attachmentQueue.append(task);
</del><ins>+    m_taskQueue.append(task);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLConstructionSite::executeQueuedTasks()
</span><span class="cx"> {
</span><del>-    const size_t size = m_attachmentQueue.size();
</del><ins>+    const size_t size = m_taskQueue.size();
</ins><span class="cx">     if (!size)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     // Copy the task queue into a local variable in case executeTask
</span><span class="cx">     // re-enters the parser.
</span><del>-    AttachmentQueue queue;
-    queue.swap(m_attachmentQueue);
</del><ins>+    TaskQueue queue = std::move(m_taskQueue);
</ins><span class="cx"> 
</span><span class="cx">     for (size_t i = 0; i &lt; size; ++i)
</span><span class="cx">         executeTask(queue[i]);
</span><span class="lines">@@ -466,7 +521,7 @@
</span><span class="cx"> 
</span><span class="cx"> void HTMLConstructionSite::insertTextNode(const String&amp; characters, WhitespaceMode whitespaceMode)
</span><span class="cx"> {
</span><del>-    HTMLConstructionSiteTask task;
</del><ins>+    HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert);
</ins><span class="cx">     task.parent = currentNode();
</span><span class="cx"> 
</span><span class="cx">     if (shouldFosterParent())
</span><span class="lines">@@ -512,6 +567,43 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord&amp; newParent, HTMLElementStack::ElementRecord&amp; child)
+{
+    HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent);
+    task.parent = newParent.node();
+    task.child = child.element();
+    m_taskQueue.append(task);
+}
+
+void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord&amp; newParent, HTMLStackItem&amp; child)
+{
+    HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent);
+    task.parent = newParent.node();
+    task.child = child.element();
+    m_taskQueue.append(task);
+}
+
+void HTMLConstructionSite::insertAlreadyParsedChild(HTMLStackItem&amp; newParent, HTMLElementStack::ElementRecord&amp; child)
+{
+    if (newParent.causesFosterParenting()) {
+        fosterParent(child.element());
+        return;
+    }
+
+    HTMLConstructionSiteTask task(HTMLConstructionSiteTask::InsertAlreadyParsedChild);
+    task.parent = newParent.node();
+    task.child = child.element();
+    m_taskQueue.append(task);
+}
+
+void HTMLConstructionSite::takeAllChildren(HTMLStackItem&amp; newParent, HTMLElementStack::ElementRecord&amp; oldParent)
+{
+    HTMLConstructionSiteTask task(HTMLConstructionSiteTask::TakeAllChildren);
+    task.parent = newParent.node();
+    task.child = oldParent.node();
+    m_taskQueue.append(task);
+}
+
</ins><span class="cx"> PassRefPtr&lt;Element&gt; HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString&amp; namespaceURI)
</span><span class="cx"> {
</span><span class="cx">     QualifiedName tagName(nullAtom, token-&gt;name(), namespaceURI);
</span><span class="lines">@@ -655,12 +747,12 @@
</span><span class="cx"> 
</span><span class="cx"> void HTMLConstructionSite::fosterParent(PassRefPtr&lt;Node&gt; node)
</span><span class="cx"> {
</span><del>-    HTMLConstructionSiteTask task;
</del><ins>+    HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert);
</ins><span class="cx">     findFosterSite(task);
</span><span class="cx">     task.child = node;
</span><span class="cx">     ASSERT(task.parent);
</span><span class="cx"> 
</span><del>-    m_attachmentQueue.append(task);
</del><ins>+    m_taskQueue.append(task);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLConstructionSiteh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLConstructionSite.h (163578 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLConstructionSite.h        2014-02-07 00:51:18 UTC (rev 163578)
+++ trunk/Source/WebCore/html/parser/HTMLConstructionSite.h        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -38,11 +38,28 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> struct HTMLConstructionSiteTask {
</span><del>-    HTMLConstructionSiteTask()
-        : selfClosing(false)
</del><ins>+    enum Operation {
+        Insert,
+        InsertAlreadyParsedChild,
+        Reparent,
+        TakeAllChildren,
+    };
+
+    explicit HTMLConstructionSiteTask(Operation op)
+        : operation(op)
+        , selfClosing(false)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    ContainerNode* oldParent()
+    {
+        // It's sort of ugly, but we store the |oldParent| in the |child| field
+        // of the task so that we don't bloat the HTMLConstructionSiteTask
+        // object in the common case of the Insert operation.
+        return toContainerNode(child.get());
+    }
+
+    Operation operation;
</ins><span class="cx">     RefPtr&lt;ContainerNode&gt; parent;
</span><span class="cx">     RefPtr&lt;Node&gt; nextChild;
</span><span class="cx">     RefPtr&lt;Node&gt; child;
</span><span class="lines">@@ -99,6 +116,14 @@
</span><span class="cx">     void insertHTMLHtmlStartTagInBody(AtomicHTMLToken*);
</span><span class="cx">     void insertHTMLBodyStartTagInBody(AtomicHTMLToken*);
</span><span class="cx"> 
</span><ins>+    void reparent(HTMLElementStack::ElementRecord&amp; newParent, HTMLElementStack::ElementRecord&amp; child);
+    void reparent(HTMLElementStack::ElementRecord&amp; newParent, HTMLStackItem&amp; child);
+    // insertAlreadyParsedChild assumes that |child| has already been parsed (i.e., we're just
+    // moving it around in the tree rather than parsing it for the first time). That means
+    // this function doesn't call beginParsingChildren / finishParsingChildren.
+    void insertAlreadyParsedChild(HTMLStackItem&amp; newParent, HTMLElementStack::ElementRecord&amp; child);
+    void takeAllChildren(HTMLStackItem&amp; newParent, HTMLElementStack::ElementRecord&amp; oldParent);
+
</ins><span class="cx">     PassRefPtr&lt;HTMLStackItem&gt; createElementFromSavedToken(HTMLStackItem*);
</span><span class="cx"> 
</span><span class="cx">     bool shouldFosterParent() const;
</span><span class="lines">@@ -160,7 +185,7 @@
</span><span class="cx"> private:
</span><span class="cx">     // In the common case, this queue will have only one task because most
</span><span class="cx">     // tokens produce only one DOM mutation.
</span><del>-    typedef Vector&lt;HTMLConstructionSiteTask, 1&gt; AttachmentQueue;
</del><ins>+    typedef Vector&lt;HTMLConstructionSiteTask, 1&gt; TaskQueue;
</ins><span class="cx"> 
</span><span class="cx">     void setCompatibilityMode(Document::CompatibilityMode);
</span><span class="cx">     void setCompatibilityModeFromDoctype(const String&amp; name, const String&amp; publicId, const String&amp; systemId);
</span><span class="lines">@@ -187,7 +212,7 @@
</span><span class="cx">     mutable HTMLElementStack m_openElements;
</span><span class="cx">     mutable HTMLFormattingElementList m_activeFormattingElements;
</span><span class="cx"> 
</span><del>-    AttachmentQueue m_attachmentQueue;
</del><ins>+    TaskQueue m_taskQueue;
</ins><span class="cx"> 
</span><span class="cx">     ParserContentPolicy m_parserContentPolicy;
</span><span class="cx">     bool m_isParsingFragment;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLTreeBuildercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp (163578 => 163579)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp        2014-02-07 00:51:18 UTC (rev 163578)
+++ trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp        2014-02-07 00:54:55 UTC (rev 163579)
</span><span class="lines">@@ -1600,39 +1600,18 @@
</span><span class="cx">             if (lastNode == furthestBlock)
</span><span class="cx">                 bookmark.moveToAfter(nodeEntry);
</span><span class="cx">             // 9.9
</span><del>-            if (ContainerNode* parent = lastNode-&gt;element()-&gt;parentNode())
-                parent-&gt;parserRemoveChild(*lastNode-&gt;element());
-            node-&gt;element()-&gt;parserAppendChild(lastNode-&gt;element());
</del><ins>+            m_tree.reparent(*node, *lastNode);
</ins><span class="cx">             // 9.10
</span><span class="cx">             lastNode = node;
</span><span class="cx">         }
</span><span class="cx">         // 10.
</span><del>-        if (ContainerNode* parent = lastNode-&gt;element()-&gt;parentNode())
-            parent-&gt;parserRemoveChild(*lastNode-&gt;element());
-        if (commonAncestor-&gt;causesFosterParenting())
-            m_tree.fosterParent(lastNode-&gt;element());
-        else {
-#if ENABLE(TEMPLATE_ELEMENT)
-            if (commonAncestor-&gt;hasTagName(templateTag))
-                toHTMLTemplateElement(commonAncestor-&gt;node())-&gt;content()-&gt;parserAppendChild(lastNode-&gt;element());
-            else
-                commonAncestor-&gt;node()-&gt;parserAppendChild(lastNode-&gt;element());
-#else
-            commonAncestor-&gt;node()-&gt;parserAppendChild(lastNode-&gt;element());
-#endif
-            ASSERT(lastNode-&gt;stackItem()-&gt;isElementNode());
-            ASSERT(lastNode-&gt;element()-&gt;parentNode());
-        }
</del><ins>+        m_tree.insertAlreadyParsedChild(*commonAncestor, *lastNode);
</ins><span class="cx">         // 11.
</span><span class="cx">         RefPtr&lt;HTMLStackItem&gt; newItem = m_tree.createElementFromSavedToken(formattingElementRecord-&gt;stackItem().get());
</span><span class="cx">         // 12.
</span><del>-        newItem-&gt;element()-&gt;takeAllChildrenFrom(furthestBlock-&gt;element());
</del><ins>+        m_tree.takeAllChildren(*newItem, *furthestBlock);
</ins><span class="cx">         // 13.
</span><del>-        Element* furthestBlockElement = furthestBlock-&gt;element();
-        // FIXME: All this creation / parserAppendChild / attach business should
-        //        be in HTMLConstructionSite. My guess is that steps 11--15
-        //        should all be in some HTMLConstructionSite function.
-        furthestBlockElement-&gt;parserAppendChild(newItem-&gt;element());
</del><ins>+        m_tree.reparent(*furthestBlock, *newItem);
</ins><span class="cx">         // 14.
</span><span class="cx">         m_tree.activeFormattingElements()-&gt;swapTo(formattingElement, newItem, bookmark);
</span><span class="cx">         // 15.
</span></span></pre>
</div>
</div>

</body>
</html>