<!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 <jpfau@apple.com>
+
+ 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 <pecoraro@apple.com>
</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>+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+document.write('<a><p><iframe onload="document.write(\'<script>void(0)<\/script></a>\');"></iframe><script>document.body.innerHTML = \'PASS\';<\/script>');
+</script>
</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>+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+document.write('<a><p><iframe onload="document.write(\'<script>document.body.innerHTML = &quot;PASS&quot;;<\/script></a>\');"></iframe>');
+</script>
</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>+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+</script>
+<iframe onload="document.write('<a><blockquote>PASS 2 of 2<iframe onload=&quot;document.write(\'<a>\')&quot;></iframe><script>document.body.innerHTML = \'PASS 1 of 2\';</script>');">
</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 <jpfau@apple.com>
+
+ 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 <mhahnenberg@apple.com>
</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<isHTMLSpace>();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static inline void executeTask(HTMLConstructionSiteTask& task)
</del><ins>+static inline void insert(HTMLConstructionSiteTask& task)
</ins><span class="cx"> {
</span><span class="cx"> #if ENABLE(TEMPLATE_ELEMENT)
</span><span class="cx"> if (task.parent->hasTagName(templateTag))
</span><span class="cx"> task.parent = toHTMLTemplateElement(task.parent.get())->content();
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+ if (ContainerNode* parent = task.child->parentNode())
+ parent->parserRemoveChild(*task.child);
+
</ins><span class="cx"> if (task.nextChild)
</span><span class="cx"> task.parent->parserInsertBefore(task.child.get(), task.nextChild.get());
</span><span class="cx"> else
</span><span class="cx"> task.parent->parserAppendChild(task.child.get());
</span><ins>+}
</ins><span class="cx">
</span><ins>+static inline void executeInsertTask(HTMLConstructionSiteTask& task)
+{
+ ASSERT(task.operation == HTMLConstructionSiteTask::Insert);
+
+ insert(task);
+
</ins><span class="cx"> task.child->beginParsingChildren();
</span><span class="cx">
</span><span class="cx"> if (task.selfClosing)
</span><span class="cx"> task.child->finishParsingChildren();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static inline void executeReparentTask(HTMLConstructionSiteTask& task)
+{
+ ASSERT(task.operation == HTMLConstructionSiteTask::Reparent);
+
+ if (ContainerNode* parent = task.child->parentNode())
+ parent->parserRemoveChild(*task.child);
+
+ task.parent->parserAppendChild(task.child);
+}
+
+static inline void executeInsertAlreadyParsedChildTask(HTMLConstructionSiteTask& task)
+{
+ ASSERT(task.operation == HTMLConstructionSiteTask::InsertAlreadyParsedChild);
+
+ insert(task);
+}
+
+static inline void executeTakeAllChildrenTask(HTMLConstructionSiteTask& task)
+{
+ ASSERT(task.operation == HTMLConstructionSiteTask::TakeAllChildren);
+
+ task.parent->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& 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<Node> prpChild, bool selfClosing)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->isElementNode() || !toScriptElementIfPossible(toElement(prpChild.get())));
</span><span class="cx"> ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !prpChild->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->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 < 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& 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& newParent, HTMLElementStack::ElementRecord& child)
+{
+ HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent);
+ task.parent = newParent.node();
+ task.child = child.element();
+ m_taskQueue.append(task);
+}
+
+void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord& newParent, HTMLStackItem& child)
+{
+ HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent);
+ task.parent = newParent.node();
+ task.child = child.element();
+ m_taskQueue.append(task);
+}
+
+void HTMLConstructionSite::insertAlreadyParsedChild(HTMLStackItem& newParent, HTMLElementStack::ElementRecord& 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& newParent, HTMLElementStack::ElementRecord& oldParent)
+{
+ HTMLConstructionSiteTask task(HTMLConstructionSiteTask::TakeAllChildren);
+ task.parent = newParent.node();
+ task.child = oldParent.node();
+ m_taskQueue.append(task);
+}
+
</ins><span class="cx"> PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI)
</span><span class="cx"> {
</span><span class="cx"> QualifiedName tagName(nullAtom, token->name(), namespaceURI);
</span><span class="lines">@@ -655,12 +747,12 @@
</span><span class="cx">
</span><span class="cx"> void HTMLConstructionSite::fosterParent(PassRefPtr<Node> 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<ContainerNode> parent;
</span><span class="cx"> RefPtr<Node> nextChild;
</span><span class="cx"> RefPtr<Node> 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& newParent, HTMLElementStack::ElementRecord& child);
+ void reparent(HTMLElementStack::ElementRecord& newParent, HTMLStackItem& 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& newParent, HTMLElementStack::ElementRecord& child);
+ void takeAllChildren(HTMLStackItem& newParent, HTMLElementStack::ElementRecord& oldParent);
+
</ins><span class="cx"> PassRefPtr<HTMLStackItem> 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<HTMLConstructionSiteTask, 1> AttachmentQueue;
</del><ins>+ typedef Vector<HTMLConstructionSiteTask, 1> TaskQueue;
</ins><span class="cx">
</span><span class="cx"> void setCompatibilityMode(Document::CompatibilityMode);
</span><span class="cx"> void setCompatibilityModeFromDoctype(const String& name, const String& publicId, const String& 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->element()->parentNode())
- parent->parserRemoveChild(*lastNode->element());
- node->element()->parserAppendChild(lastNode->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->element()->parentNode())
- parent->parserRemoveChild(*lastNode->element());
- if (commonAncestor->causesFosterParenting())
- m_tree.fosterParent(lastNode->element());
- else {
-#if ENABLE(TEMPLATE_ELEMENT)
- if (commonAncestor->hasTagName(templateTag))
- toHTMLTemplateElement(commonAncestor->node())->content()->parserAppendChild(lastNode->element());
- else
- commonAncestor->node()->parserAppendChild(lastNode->element());
-#else
- commonAncestor->node()->parserAppendChild(lastNode->element());
-#endif
- ASSERT(lastNode->stackItem()->isElementNode());
- ASSERT(lastNode->element()->parentNode());
- }
</del><ins>+ m_tree.insertAlreadyParsedChild(*commonAncestor, *lastNode);
</ins><span class="cx"> // 11.
</span><span class="cx"> RefPtr<HTMLStackItem> newItem = m_tree.createElementFromSavedToken(formattingElementRecord->stackItem().get());
</span><span class="cx"> // 12.
</span><del>- newItem->element()->takeAllChildrenFrom(furthestBlock->element());
</del><ins>+ m_tree.takeAllChildren(*newItem, *furthestBlock);
</ins><span class="cx"> // 13.
</span><del>- Element* furthestBlockElement = furthestBlock->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->parserAppendChild(newItem->element());
</del><ins>+ m_tree.reparent(*furthestBlock, *newItem);
</ins><span class="cx"> // 14.
</span><span class="cx"> m_tree.activeFormattingElements()->swapTo(formattingElement, newItem, bookmark);
</span><span class="cx"> // 15.
</span></span></pre>
</div>
</div>
</body>
</html>