Changeset 195438 in webkit


Ignore:
Timestamp:
Jan 21, 2016 7:47:37 PM (8 years ago)
Author:
rniwa@webkit.org
Message:

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<Element> instead of PassRefPtr<Element>.
(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):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r195430 r195438  
     12016-01-21  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        createElementFromSavedToken shouldn't have the code to create a non-HTML element
     4        https://bugs.webkit.org/show_bug.cgi?id=153327
     5
     6        Reviewed by Chris Dumez.
     7
     8        Since HTMLConstructionSite::createElementFromSavedToken is only used to instantiate a formatting element,
     9        there is no need for it to support creating a non-HTML elements. Remove the branch and assert that this
     10        is indeed the case.
     11
     12        createElementFromSavedToken is called in HTMLTreeBuilder::callTheAdoptionAgency and HTMLConstructionSite's
     13        reconstructTheActiveFormattingElements. In both cases, the stack item passed to createElementFromSavedToken
     14        is guaranteed to be in the list of active formatting elements, which only contains formatting elements.
     15
     16        No new tests since there is no behavioral change.
     17
     18        * html/parser/HTMLConstructionSite.cpp:
     19        (WebCore::HTMLConstructionSite::insertHTMLHeadElement):
     20        (WebCore::HTMLConstructionSite::insertHTMLHtmlStartTagBeforeHTML):
     21        (WebCore::HTMLConstructionSite::insertFormattingElement):
     22        (WebCore::HTMLConstructionSite::createElement): Returns Ref<Element> instead of PassRefPtr<Element>.
     23        (WebCore::HTMLConstructionSite::createHTMLElement): Ditto.
     24        (WebCore::HTMLConstructionSite::createElementFromSavedToken): Ditto. Removed the code to instantiate
     25        a non-HTML element. Also assert that an element created by this function is a formatting tag.
     26        * html/parser/HTMLConstructionSite.h:
     27        * html/parser/HTMLTreeBuilder.cpp:
     28        (WebCore::HTMLConstructionSite::isFormattingTag): Put into HTMLConstructionSite to add an assertion.
     29        (WebCore::HTMLTreeBuilder::processEndTagForInBody):
     30
    1312016-01-21  Andreas Kling  <akling@apple.com>
    232
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r195132 r195438  
    5252using namespace HTMLNames;
    5353
    54 static inline void setAttributes(Element* element, AtomicHTMLToken* token, ParserContentPolicy parserContentPolicy)
     54static inline void setAttributes(Element& element, AtomicHTMLToken* token, ParserContentPolicy parserContentPolicy)
    5555{
    5656    if (!scriptingContentIsAllowed(parserContentPolicy))
    57         element->stripScriptingAttributes(token->attributes());
    58     element->parserSetAttributes(token->attributes());
     57        element.stripScriptingAttributes(token->attributes());
     58    element.parserSetAttributes(token->attributes());
    5959}
    6060
     
    263263{
    264264    Ref<HTMLHtmlElement> element = HTMLHtmlElement::create(*m_document);
    265     setAttributes(element.ptr(), token, m_parserContentPolicy);
     265    setAttributes(element.get(), token, m_parserContentPolicy);
    266266    attachLater(m_attachmentRoot, element.ptr());
    267267    m_openElements.pushHTMLHtmlElement(HTMLStackItem::create(element.copyRef(), *token));
     
    453453{
    454454    ASSERT(!shouldFosterParent());
    455     m_head = HTMLStackItem::create(*createHTMLElement(token), *token);
     455    m_head = HTMLStackItem::create(createHTMLElement(token), *token);
    456456    attachLater(&currentNode(), &m_head->element());
    457457    m_openElements.pushHTMLHeadElement(m_head);
     
    499499    // Possible active formatting elements include:
    500500    // a, b, big, code, em, font, i, nobr, s, small, strike, strong, tt, and u.
     501    ASSERT(isFormattingTag(token->name()));
    501502    insertHTMLElement(token);
    502503    m_activeFormattingElements.append(&currentStackItem());
     
    512513    const bool parserInserted = m_parserContentPolicy != AllowScriptingContentAndDoNotMarkAlreadyStarted;
    513514    const bool alreadyStarted = m_isParsingFragment && parserInserted;
    514     RefPtr<HTMLScriptElement> element = HTMLScriptElement::create(scriptTag, ownerDocumentForCurrentNode(), parserInserted, alreadyStarted);
     515    Ref<HTMLScriptElement> element = HTMLScriptElement::create(scriptTag, ownerDocumentForCurrentNode(), parserInserted, alreadyStarted);
    515516    setAttributes(element.get(), token, m_parserContentPolicy);
    516517    if (scriptingContentIsAllowed(m_parserContentPolicy))
    517         attachLater(&currentNode(), element);
    518     m_openElements.push(HTMLStackItem::create(element.releaseNonNull(), *token));
     518        attachLater(&currentNode(), element.ptr());
     519    m_openElements.push(HTMLStackItem::create(WTFMove(element), *token));
    519520}
    520521
     
    616617}
    617618
    618 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI)
     619Ref<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI)
    619620{
    620621    QualifiedName tagName(nullAtom, token->name(), namespaceURI);
    621     RefPtr<Element> element = ownerDocumentForCurrentNode().createElement(tagName, true);
     622    Ref<Element> element = ownerDocumentForCurrentNode().createElement(tagName, true);
    622623    setAttributes(element.get(), token, m_parserContentPolicy);
    623     return element.release();
     624    return element;
    624625}
    625626
     
    633634}
    634635
    635 PassRefPtr<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token)
     636Ref<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token)
    636637{
    637638    QualifiedName tagName(nullAtom, token->name(), xhtmlNamespaceURI);
     
    642643    Document& ownerDocument = ownerDocumentForCurrentNode();
    643644    bool insideTemplateElement = !ownerDocument.frame();
    644     RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);
     645    Ref<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);
    645646   
    646647    // FIXME: This is a hack to connect images to pictures before the image has
    647648    // been inserted into the document. It can be removed once asynchronous image
    648649    // loading is working.
    649     if (is<HTMLPictureElement>(currentNode()) && is<HTMLImageElement>(*element.get()))
    650         downcast<HTMLImageElement>(*element.get()).setPictureElement(&downcast<HTMLPictureElement>(currentNode()));
     650    if (is<HTMLPictureElement>(currentNode()) && is<HTMLImageElement>(element))
     651        downcast<HTMLImageElement>(element.get()).setPictureElement(&downcast<HTMLPictureElement>(currentNode()));
    651652
    652653    setAttributes(element.get(), token, m_parserContentPolicy);
    653654    ASSERT(element->isHTMLElement());
    654     return element.release();
    655 }
    656 
    657 PassRefPtr<HTMLStackItem> HTMLConstructionSite::createElementFromSavedToken(HTMLStackItem* item)
    658 {
    659     RefPtr<Element> element;
     655    return element;
     656}
     657
     658Ref<HTMLStackItem> HTMLConstructionSite::createElementFromSavedToken(HTMLStackItem* item)
     659{
    660660    // NOTE: Moving from item -> token -> item copies the Attribute vector twice!
    661661    AtomicHTMLToken fakeToken(HTMLToken::StartTag, item->localName(), Vector<Attribute>(item->attributes()));
    662     if (item->namespaceURI() == HTMLNames::xhtmlNamespaceURI)
    663         element = createHTMLElement(&fakeToken);
    664     else
    665         element = createElement(&fakeToken, item->namespaceURI());
    666     return HTMLStackItem::create(element.releaseNonNull(), fakeToken, item->namespaceURI());
     662    ASSERT(item->namespaceURI() == HTMLNames::xhtmlNamespaceURI);
     663    ASSERT(isFormattingTag(item->localName()));
     664    return HTMLStackItem::create(createHTMLElement(&fakeToken), fakeToken, item->namespaceURI());
    667665}
    668666
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.h

    r177910 r195438  
    125125    void takeAllChildren(HTMLStackItem& newParent, HTMLElementStack::ElementRecord& oldParent);
    126126
    127     PassRefPtr<HTMLStackItem> createElementFromSavedToken(HTMLStackItem*);
     127    Ref<HTMLStackItem> createElementFromSavedToken(HTMLStackItem*);
    128128
    129129    bool shouldFosterParent() const;
     
    181181    };
    182182
     183    static bool isFormattingTag(const AtomicString&);
     184
    183185private:
    184186    // In the common case, this queue will have only one task because most
     
    193195    void findFosterSite(HTMLConstructionSiteTask&);
    194196
    195     PassRefPtr<Element> createHTMLElement(AtomicHTMLToken*);
    196     PassRefPtr<Element> createElement(AtomicHTMLToken*, const AtomicString& namespaceURI);
     197    Ref<Element> createHTMLElement(AtomicHTMLToken*);
     198    Ref<Element> createElement(AtomicHTMLToken*, const AtomicString& namespaceURI);
    197199
    198200    void mergeAttributesFromTokenIntoElement(AtomicHTMLToken*, Element*);
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r194496 r195438  
    122122
    123123// https://html.spec.whatwg.org/multipage/syntax.html#formatting
    124 static bool isFormattingTag(const AtomicString& tagName)
     124bool HTMLConstructionSite::isFormattingTag(const AtomicString& tagName)
    125125{
    126126    return tagName == aTag || isNonAnchorFormattingTag(tagName);
     
    18841884        return;
    18851885    }
    1886     if (isFormattingTag(token.name())) {
     1886    if (HTMLConstructionSite::isFormattingTag(token.name())) {
    18871887        callTheAdoptionAgency(token);
    18881888        return;
Note: See TracChangeset for help on using the changeset viewer.