<!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>[195438] trunk/Source/WebCore</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/195438">195438</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2016-01-21 19:47:37 -0800 (Thu, 21 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>createElementFromSavedToken shouldn't have the code to create a non-HTML element
https://bugs.webkit.org/show_bug.cgi?id=153327

Reviewed by Chris Dumez.

Since HTMLConstructionSite::createElementFromSavedToken is only used to instantiate a formatting element,
there is no need for it to support creating a non-HTML elements. Remove the branch and assert that this
is indeed the case.

createElementFromSavedToken is called in HTMLTreeBuilder::callTheAdoptionAgency and HTMLConstructionSite's
reconstructTheActiveFormattingElements. In both cases, the stack item passed to createElementFromSavedToken
is guaranteed to be in the list of active formatting elements, which only contains formatting elements.

No new tests since there is no behavioral change.

* html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::insertHTMLHeadElement):
(WebCore::HTMLConstructionSite::insertHTMLHtmlStartTagBeforeHTML):
(WebCore::HTMLConstructionSite::insertFormattingElement):
(WebCore::HTMLConstructionSite::createElement): Returns Ref&lt;Element&gt; instead of PassRefPtr&lt;Element&gt;.
(WebCore::HTMLConstructionSite::createHTMLElement): Ditto.
(WebCore::HTMLConstructionSite::createElementFromSavedToken): Ditto. Removed the code to instantiate
a non-HTML element. Also assert that an element created by this function is a formatting tag.
* html/parser/HTMLConstructionSite.h:
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLConstructionSite::isFormattingTag): Put into HTMLConstructionSite to add an assertion.
(WebCore::HTMLTreeBuilder::processEndTagForInBody):</pre>

<h3>Modified Paths</h3>
<ul>
<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>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (195437 => 195438)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-01-22 03:40:16 UTC (rev 195437)
+++ trunk/Source/WebCore/ChangeLog        2016-01-22 03:47:37 UTC (rev 195438)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-01-21  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        createElementFromSavedToken shouldn't have the code to create a non-HTML element
+        https://bugs.webkit.org/show_bug.cgi?id=153327
+
+        Reviewed by Chris Dumez.
+
+        Since HTMLConstructionSite::createElementFromSavedToken is only used to instantiate a formatting element,
+        there is no need for it to support creating a non-HTML elements. Remove the branch and assert that this
+        is indeed the case.
+
+        createElementFromSavedToken is called in HTMLTreeBuilder::callTheAdoptionAgency and HTMLConstructionSite's
+        reconstructTheActiveFormattingElements. In both cases, the stack item passed to createElementFromSavedToken
+        is guaranteed to be in the list of active formatting elements, which only contains formatting elements.
+
+        No new tests since there is no behavioral change.
+
+        * html/parser/HTMLConstructionSite.cpp:
+        (WebCore::HTMLConstructionSite::insertHTMLHeadElement):
+        (WebCore::HTMLConstructionSite::insertHTMLHtmlStartTagBeforeHTML):
+        (WebCore::HTMLConstructionSite::insertFormattingElement):
+        (WebCore::HTMLConstructionSite::createElement): Returns Ref&lt;Element&gt; instead of PassRefPtr&lt;Element&gt;.
+        (WebCore::HTMLConstructionSite::createHTMLElement): Ditto.
+        (WebCore::HTMLConstructionSite::createElementFromSavedToken): Ditto. Removed the code to instantiate
+        a non-HTML element. Also assert that an element created by this function is a formatting tag.
+        * html/parser/HTMLConstructionSite.h:
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLConstructionSite::isFormattingTag): Put into HTMLConstructionSite to add an assertion.
+        (WebCore::HTMLTreeBuilder::processEndTagForInBody):
+
</ins><span class="cx"> 2016-01-21  Andreas Kling  &lt;akling@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         CGImageSource sometimes retains temporary SharedBuffer data indefinitely, doubling memory cost.
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLConstructionSitecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp (195437 => 195438)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp        2016-01-22 03:40:16 UTC (rev 195437)
+++ trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp        2016-01-22 03:47:37 UTC (rev 195438)
</span><span class="lines">@@ -51,11 +51,11 @@
</span><span class="cx"> 
</span><span class="cx"> using namespace HTMLNames;
</span><span class="cx"> 
</span><del>-static inline void setAttributes(Element* element, AtomicHTMLToken* token, ParserContentPolicy parserContentPolicy)
</del><ins>+static inline void setAttributes(Element&amp; element, AtomicHTMLToken* token, ParserContentPolicy parserContentPolicy)
</ins><span class="cx"> {
</span><span class="cx">     if (!scriptingContentIsAllowed(parserContentPolicy))
</span><del>-        element-&gt;stripScriptingAttributes(token-&gt;attributes());
-    element-&gt;parserSetAttributes(token-&gt;attributes());
</del><ins>+        element.stripScriptingAttributes(token-&gt;attributes());
+    element.parserSetAttributes(token-&gt;attributes());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool hasImpliedEndTag(const HTMLStackItem&amp; item)
</span><span class="lines">@@ -262,7 +262,7 @@
</span><span class="cx"> void HTMLConstructionSite::insertHTMLHtmlStartTagBeforeHTML(AtomicHTMLToken* token)
</span><span class="cx"> {
</span><span class="cx">     Ref&lt;HTMLHtmlElement&gt; element = HTMLHtmlElement::create(*m_document);
</span><del>-    setAttributes(element.ptr(), token, m_parserContentPolicy);
</del><ins>+    setAttributes(element.get(), token, m_parserContentPolicy);
</ins><span class="cx">     attachLater(m_attachmentRoot, element.ptr());
</span><span class="cx">     m_openElements.pushHTMLHtmlElement(HTMLStackItem::create(element.copyRef(), *token));
</span><span class="cx"> 
</span><span class="lines">@@ -452,7 +452,7 @@
</span><span class="cx"> void HTMLConstructionSite::insertHTMLHeadElement(AtomicHTMLToken* token)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!shouldFosterParent());
</span><del>-    m_head = HTMLStackItem::create(*createHTMLElement(token), *token);
</del><ins>+    m_head = HTMLStackItem::create(createHTMLElement(token), *token);
</ins><span class="cx">     attachLater(&amp;currentNode(), &amp;m_head-&gt;element());
</span><span class="cx">     m_openElements.pushHTMLHeadElement(m_head);
</span><span class="cx"> }
</span><span class="lines">@@ -498,6 +498,7 @@
</span><span class="cx">     // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#the-stack-of-open-elements
</span><span class="cx">     // Possible active formatting elements include:
</span><span class="cx">     // a, b, big, code, em, font, i, nobr, s, small, strike, strong, tt, and u.
</span><ins>+    ASSERT(isFormattingTag(token-&gt;name()));
</ins><span class="cx">     insertHTMLElement(token);
</span><span class="cx">     m_activeFormattingElements.append(&amp;currentStackItem());
</span><span class="cx"> }
</span><span class="lines">@@ -511,11 +512,11 @@
</span><span class="cx">     // those flags or effects thereof.
</span><span class="cx">     const bool parserInserted = m_parserContentPolicy != AllowScriptingContentAndDoNotMarkAlreadyStarted;
</span><span class="cx">     const bool alreadyStarted = m_isParsingFragment &amp;&amp; parserInserted;
</span><del>-    RefPtr&lt;HTMLScriptElement&gt; element = HTMLScriptElement::create(scriptTag, ownerDocumentForCurrentNode(), parserInserted, alreadyStarted);
</del><ins>+    Ref&lt;HTMLScriptElement&gt; element = HTMLScriptElement::create(scriptTag, ownerDocumentForCurrentNode(), parserInserted, alreadyStarted);
</ins><span class="cx">     setAttributes(element.get(), token, m_parserContentPolicy);
</span><span class="cx">     if (scriptingContentIsAllowed(m_parserContentPolicy))
</span><del>-        attachLater(&amp;currentNode(), element);
-    m_openElements.push(HTMLStackItem::create(element.releaseNonNull(), *token));
</del><ins>+        attachLater(&amp;currentNode(), element.ptr());
+    m_openElements.push(HTMLStackItem::create(WTFMove(element), *token));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLConstructionSite::insertForeignElement(AtomicHTMLToken* token, const AtomicString&amp; namespaceURI)
</span><span class="lines">@@ -615,12 +616,12 @@
</span><span class="cx">     m_taskQueue.append(task);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;Element&gt; HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString&amp; namespaceURI)
</del><ins>+Ref&lt;Element&gt; HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString&amp; namespaceURI)
</ins><span class="cx"> {
</span><span class="cx">     QualifiedName tagName(nullAtom, token-&gt;name(), namespaceURI);
</span><del>-    RefPtr&lt;Element&gt; element = ownerDocumentForCurrentNode().createElement(tagName, true);
</del><ins>+    Ref&lt;Element&gt; element = ownerDocumentForCurrentNode().createElement(tagName, true);
</ins><span class="cx">     setAttributes(element.get(), token, m_parserContentPolicy);
</span><del>-    return element.release();
</del><ins>+    return element;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline Document&amp; HTMLConstructionSite::ownerDocumentForCurrentNode()
</span><span class="lines">@@ -632,7 +633,7 @@
</span><span class="cx">     return currentNode().document();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;Element&gt; HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token)
</del><ins>+Ref&lt;Element&gt; HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token)
</ins><span class="cx"> {
</span><span class="cx">     QualifiedName tagName(nullAtom, token-&gt;name(), xhtmlNamespaceURI);
</span><span class="cx">     // FIXME: This can't use HTMLConstructionSite::createElement because we
</span><span class="lines">@@ -641,29 +642,26 @@
</span><span class="cx">     // http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#create-an-element-for-the-token
</span><span class="cx">     Document&amp; ownerDocument = ownerDocumentForCurrentNode();
</span><span class="cx">     bool insideTemplateElement = !ownerDocument.frame();
</span><del>-    RefPtr&lt;Element&gt; element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);
</del><ins>+    Ref&lt;Element&gt; element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);
</ins><span class="cx">     
</span><span class="cx">     // FIXME: This is a hack to connect images to pictures before the image has
</span><span class="cx">     // been inserted into the document. It can be removed once asynchronous image
</span><span class="cx">     // loading is working.
</span><del>-    if (is&lt;HTMLPictureElement&gt;(currentNode()) &amp;&amp; is&lt;HTMLImageElement&gt;(*element.get()))
-        downcast&lt;HTMLImageElement&gt;(*element.get()).setPictureElement(&amp;downcast&lt;HTMLPictureElement&gt;(currentNode()));
</del><ins>+    if (is&lt;HTMLPictureElement&gt;(currentNode()) &amp;&amp; is&lt;HTMLImageElement&gt;(element))
+        downcast&lt;HTMLImageElement&gt;(element.get()).setPictureElement(&amp;downcast&lt;HTMLPictureElement&gt;(currentNode()));
</ins><span class="cx"> 
</span><span class="cx">     setAttributes(element.get(), token, m_parserContentPolicy);
</span><span class="cx">     ASSERT(element-&gt;isHTMLElement());
</span><del>-    return element.release();
</del><ins>+    return element;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;HTMLStackItem&gt; HTMLConstructionSite::createElementFromSavedToken(HTMLStackItem* item)
</del><ins>+Ref&lt;HTMLStackItem&gt; HTMLConstructionSite::createElementFromSavedToken(HTMLStackItem* item)
</ins><span class="cx"> {
</span><del>-    RefPtr&lt;Element&gt; element;
</del><span class="cx">     // NOTE: Moving from item -&gt; token -&gt; item copies the Attribute vector twice!
</span><span class="cx">     AtomicHTMLToken fakeToken(HTMLToken::StartTag, item-&gt;localName(), Vector&lt;Attribute&gt;(item-&gt;attributes()));
</span><del>-    if (item-&gt;namespaceURI() == HTMLNames::xhtmlNamespaceURI)
-        element = createHTMLElement(&amp;fakeToken);
-    else
-        element = createElement(&amp;fakeToken, item-&gt;namespaceURI());
-    return HTMLStackItem::create(element.releaseNonNull(), fakeToken, item-&gt;namespaceURI());
</del><ins>+    ASSERT(item-&gt;namespaceURI() == HTMLNames::xhtmlNamespaceURI);
+    ASSERT(isFormattingTag(item-&gt;localName()));
+    return HTMLStackItem::create(createHTMLElement(&amp;fakeToken), fakeToken, item-&gt;namespaceURI());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool HTMLConstructionSite::indexOfFirstUnopenFormattingElement(unsigned&amp; firstUnopenElementIndex) const
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLConstructionSiteh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLConstructionSite.h (195437 => 195438)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLConstructionSite.h        2016-01-22 03:40:16 UTC (rev 195437)
+++ trunk/Source/WebCore/html/parser/HTMLConstructionSite.h        2016-01-22 03:47:37 UTC (rev 195438)
</span><span class="lines">@@ -124,7 +124,7 @@
</span><span class="cx">     void insertAlreadyParsedChild(HTMLStackItem&amp; newParent, HTMLElementStack::ElementRecord&amp; child);
</span><span class="cx">     void takeAllChildren(HTMLStackItem&amp; newParent, HTMLElementStack::ElementRecord&amp; oldParent);
</span><span class="cx"> 
</span><del>-    PassRefPtr&lt;HTMLStackItem&gt; createElementFromSavedToken(HTMLStackItem*);
</del><ins>+    Ref&lt;HTMLStackItem&gt; createElementFromSavedToken(HTMLStackItem*);
</ins><span class="cx"> 
</span><span class="cx">     bool shouldFosterParent() const;
</span><span class="cx">     void fosterParent(PassRefPtr&lt;Node&gt;);
</span><span class="lines">@@ -180,6 +180,8 @@
</span><span class="cx">         bool m_wasRedirectingBefore;
</span><span class="cx">     };
</span><span class="cx"> 
</span><ins>+    static bool isFormattingTag(const AtomicString&amp;);
+
</ins><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><span class="lines">@@ -192,8 +194,8 @@
</span><span class="cx"> 
</span><span class="cx">     void findFosterSite(HTMLConstructionSiteTask&amp;);
</span><span class="cx"> 
</span><del>-    PassRefPtr&lt;Element&gt; createHTMLElement(AtomicHTMLToken*);
-    PassRefPtr&lt;Element&gt; createElement(AtomicHTMLToken*, const AtomicString&amp; namespaceURI);
</del><ins>+    Ref&lt;Element&gt; createHTMLElement(AtomicHTMLToken*);
+    Ref&lt;Element&gt; createElement(AtomicHTMLToken*, const AtomicString&amp; namespaceURI);
</ins><span class="cx"> 
</span><span class="cx">     void mergeAttributesFromTokenIntoElement(AtomicHTMLToken*, Element*);
</span><span class="cx">     void dispatchDocumentElementAvailableIfNeeded();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLTreeBuildercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp (195437 => 195438)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp        2016-01-22 03:40:16 UTC (rev 195437)
+++ trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp        2016-01-22 03:47:37 UTC (rev 195438)
</span><span class="lines">@@ -121,7 +121,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://html.spec.whatwg.org/multipage/syntax.html#formatting
</span><del>-static bool isFormattingTag(const AtomicString&amp; tagName)
</del><ins>+bool HTMLConstructionSite::isFormattingTag(const AtomicString&amp; tagName)
</ins><span class="cx"> {
</span><span class="cx">     return tagName == aTag || isNonAnchorFormattingTag(tagName);
</span><span class="cx"> }
</span><span class="lines">@@ -1883,7 +1883,7 @@
</span><span class="cx">         m_tree.openElements().popUntilNumberedHeaderElementPopped();
</span><span class="cx">         return;
</span><span class="cx">     }
</span><del>-    if (isFormattingTag(token.name())) {
</del><ins>+    if (HTMLConstructionSite::isFormattingTag(token.name())) {
</ins><span class="cx">         callTheAdoptionAgency(token);
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre>
</div>
</div>

</body>
</html>