Changeset 195438 in webkit
- Timestamp:
- Jan 21, 2016 7:47:37 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r195430 r195438 1 2016-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 1 31 2016-01-21 Andreas Kling <akling@apple.com> 2 32 -
trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp
r195132 r195438 52 52 using namespace HTMLNames; 53 53 54 static inline void setAttributes(Element *element, AtomicHTMLToken* token, ParserContentPolicy parserContentPolicy)54 static inline void setAttributes(Element& element, AtomicHTMLToken* token, ParserContentPolicy parserContentPolicy) 55 55 { 56 56 if (!scriptingContentIsAllowed(parserContentPolicy)) 57 element ->stripScriptingAttributes(token->attributes());58 element ->parserSetAttributes(token->attributes());57 element.stripScriptingAttributes(token->attributes()); 58 element.parserSetAttributes(token->attributes()); 59 59 } 60 60 … … 263 263 { 264 264 Ref<HTMLHtmlElement> element = HTMLHtmlElement::create(*m_document); 265 setAttributes(element. ptr(), token, m_parserContentPolicy);265 setAttributes(element.get(), token, m_parserContentPolicy); 266 266 attachLater(m_attachmentRoot, element.ptr()); 267 267 m_openElements.pushHTMLHtmlElement(HTMLStackItem::create(element.copyRef(), *token)); … … 453 453 { 454 454 ASSERT(!shouldFosterParent()); 455 m_head = HTMLStackItem::create( *createHTMLElement(token), *token);455 m_head = HTMLStackItem::create(createHTMLElement(token), *token); 456 456 attachLater(¤tNode(), &m_head->element()); 457 457 m_openElements.pushHTMLHeadElement(m_head); … … 499 499 // Possible active formatting elements include: 500 500 // a, b, big, code, em, font, i, nobr, s, small, strike, strong, tt, and u. 501 ASSERT(isFormattingTag(token->name())); 501 502 insertHTMLElement(token); 502 503 m_activeFormattingElements.append(¤tStackItem()); … … 512 513 const bool parserInserted = m_parserContentPolicy != AllowScriptingContentAndDoNotMarkAlreadyStarted; 513 514 const bool alreadyStarted = m_isParsingFragment && parserInserted; 514 Ref Ptr<HTMLScriptElement> element = HTMLScriptElement::create(scriptTag, ownerDocumentForCurrentNode(), parserInserted, alreadyStarted);515 Ref<HTMLScriptElement> element = HTMLScriptElement::create(scriptTag, ownerDocumentForCurrentNode(), parserInserted, alreadyStarted); 515 516 setAttributes(element.get(), token, m_parserContentPolicy); 516 517 if (scriptingContentIsAllowed(m_parserContentPolicy)) 517 attachLater(¤tNode(), element );518 m_openElements.push(HTMLStackItem::create( element.releaseNonNull(), *token));518 attachLater(¤tNode(), element.ptr()); 519 m_openElements.push(HTMLStackItem::create(WTFMove(element), *token)); 519 520 } 520 521 … … 616 617 } 617 618 618 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI)619 Ref<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI) 619 620 { 620 621 QualifiedName tagName(nullAtom, token->name(), namespaceURI); 621 Ref Ptr<Element> element = ownerDocumentForCurrentNode().createElement(tagName, true);622 Ref<Element> element = ownerDocumentForCurrentNode().createElement(tagName, true); 622 623 setAttributes(element.get(), token, m_parserContentPolicy); 623 return element .release();624 return element; 624 625 } 625 626 … … 633 634 } 634 635 635 PassRefPtr<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token)636 Ref<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token) 636 637 { 637 638 QualifiedName tagName(nullAtom, token->name(), xhtmlNamespaceURI); … … 642 643 Document& ownerDocument = ownerDocumentForCurrentNode(); 643 644 bool insideTemplateElement = !ownerDocument.frame(); 644 Ref Ptr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);645 Ref<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true); 645 646 646 647 // FIXME: This is a hack to connect images to pictures before the image has 647 648 // been inserted into the document. It can be removed once asynchronous image 648 649 // 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())); 651 652 652 653 setAttributes(element.get(), token, m_parserContentPolicy); 653 654 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 658 Ref<HTMLStackItem> HTMLConstructionSite::createElementFromSavedToken(HTMLStackItem* item) 659 { 660 660 // NOTE: Moving from item -> token -> item copies the Attribute vector twice! 661 661 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()); 667 665 } 668 666 -
trunk/Source/WebCore/html/parser/HTMLConstructionSite.h
r177910 r195438 125 125 void takeAllChildren(HTMLStackItem& newParent, HTMLElementStack::ElementRecord& oldParent); 126 126 127 PassRefPtr<HTMLStackItem> createElementFromSavedToken(HTMLStackItem*);127 Ref<HTMLStackItem> createElementFromSavedToken(HTMLStackItem*); 128 128 129 129 bool shouldFosterParent() const; … … 181 181 }; 182 182 183 static bool isFormattingTag(const AtomicString&); 184 183 185 private: 184 186 // In the common case, this queue will have only one task because most … … 193 195 void findFosterSite(HTMLConstructionSiteTask&); 194 196 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); 197 199 198 200 void mergeAttributesFromTokenIntoElement(AtomicHTMLToken*, Element*); -
trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp
r194496 r195438 122 122 123 123 // https://html.spec.whatwg.org/multipage/syntax.html#formatting 124 static boolisFormattingTag(const AtomicString& tagName)124 bool HTMLConstructionSite::isFormattingTag(const AtomicString& tagName) 125 125 { 126 126 return tagName == aTag || isNonAnchorFormattingTag(tagName); … … 1884 1884 return; 1885 1885 } 1886 if ( isFormattingTag(token.name())) {1886 if (HTMLConstructionSite::isFormattingTag(token.name())) { 1887 1887 callTheAdoptionAgency(token); 1888 1888 return;
Note: See TracChangeset
for help on using the changeset viewer.