Changeset 147441 in webkit


Ignore:
Timestamp:
Apr 2, 2013, 9:14:40 AM (12 years ago)
Author:
adamk@chromium.org
Message:

HTML parser should consistently inspect the namespace of elements on the stack of open elements
https://bugs.webkit.org/show_bug.cgi?id=113723

Reviewed by Adam Barth.

Source/WebCore:

Added HTMLStackItem::matchesHTMLTag method and use that nearly
everywhere instead of HTMLStackItem::hasLocalName. The most important
of these changes is in HTMLElementStack's inScopeCommon() function,
where the use of matchesHTMLTag means that any of the inXXXScope()
calls now only match HTML tags.

Tests: html5lib/generated/run-namespace-sensitivity-data.html

html5lib/generated/run-namespace-sensitivity-write.html

  • html/parser/HTMLConstructionSite.cpp:

(WebCore::HTMLConstructionSite::generateImpliedEndTagsWithExclusion):

  • html/parser/HTMLElementStack.cpp:

(WebCore::HTMLElementStack::popUntil):
(WebCore::HTMLElementStack::topmost):
(WebCore::inScopeCommon):
(WebCore::HTMLElementStack::inScope):
(WebCore::HTMLElementStack::inListItemScope):
(WebCore::HTMLElementStack::inTableScope):
(WebCore::HTMLElementStack::inButtonScope):
(WebCore::HTMLElementStack::inSelectScope):

  • html/parser/HTMLElementStack.h:

(WebCore::HTMLElementStack::popUntilPopped):

  • html/parser/HTMLFormattingElementList.cpp:

(WebCore::HTMLFormattingElementList::closestElementInScopeWithName):

  • html/parser/HTMLStackItem.h:

(WebCore::HTMLStackItem::matchesHTMLTag):
(HTMLStackItem):

  • html/parser/HTMLTreeBuilder.cpp:

(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
(WebCore::HTMLTreeBuilder::processAnyOtherEndTagForInBody):
(WebCore::HTMLTreeBuilder::processEndTagForInCell):
(WebCore::HTMLTreeBuilder::processEndTagForInBody):

LayoutTests:

  • html5lib/generated/run-namespace-sensitivity-data-expected.txt: Added.
  • html5lib/generated/run-namespace-sensitivity-data.html: Added.
  • html5lib/generated/run-namespace-sensitivity-write-expected.txt: Added.
  • html5lib/generated/run-namespace-sensitivity-write.html: Added.
  • html5lib/resources/namespace-sensitivity.dat: Added.
Location:
trunk
Files:
5 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r147437 r147441  
     12013-04-02  Adam Klein  <adamk@chromium.org>
     2
     3        HTML parser should consistently inspect the namespace of elements on the stack of open elements
     4        https://bugs.webkit.org/show_bug.cgi?id=113723
     5
     6        Reviewed by Adam Barth.
     7
     8        * html5lib/generated/run-namespace-sensitivity-data-expected.txt: Added.
     9        * html5lib/generated/run-namespace-sensitivity-data.html: Added.
     10        * html5lib/generated/run-namespace-sensitivity-write-expected.txt: Added.
     11        * html5lib/generated/run-namespace-sensitivity-write.html: Added.
     12        * html5lib/resources/namespace-sensitivity.dat: Added.
     13
    1142013-04-02  Andrei Bucur  <abucur@adobe.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r147440 r147441  
     12013-04-02  Adam Klein  <adamk@chromium.org>
     2
     3        HTML parser should consistently inspect the namespace of elements on the stack of open elements
     4        https://bugs.webkit.org/show_bug.cgi?id=113723
     5
     6        Reviewed by Adam Barth.
     7
     8        Added HTMLStackItem::matchesHTMLTag method and use that nearly
     9        everywhere instead of HTMLStackItem::hasLocalName. The most important
     10        of these changes is in HTMLElementStack's inScopeCommon() function,
     11        where the use of matchesHTMLTag means that any of the inXXXScope()
     12        calls now only match HTML tags.
     13
     14        Tests: html5lib/generated/run-namespace-sensitivity-data.html
     15               html5lib/generated/run-namespace-sensitivity-write.html
     16
     17        * html/parser/HTMLConstructionSite.cpp:
     18        (WebCore::HTMLConstructionSite::generateImpliedEndTagsWithExclusion):
     19        * html/parser/HTMLElementStack.cpp:
     20        (WebCore::HTMLElementStack::popUntil):
     21        (WebCore::HTMLElementStack::topmost):
     22        (WebCore::inScopeCommon):
     23        (WebCore::HTMLElementStack::inScope):
     24        (WebCore::HTMLElementStack::inListItemScope):
     25        (WebCore::HTMLElementStack::inTableScope):
     26        (WebCore::HTMLElementStack::inButtonScope):
     27        (WebCore::HTMLElementStack::inSelectScope):
     28        * html/parser/HTMLElementStack.h:
     29        (WebCore::HTMLElementStack::popUntilPopped):
     30        * html/parser/HTMLFormattingElementList.cpp:
     31        (WebCore::HTMLFormattingElementList::closestElementInScopeWithName):
     32        * html/parser/HTMLStackItem.h:
     33        (WebCore::HTMLStackItem::matchesHTMLTag):
     34        (HTMLStackItem):
     35        * html/parser/HTMLTreeBuilder.cpp:
     36        (WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
     37        (WebCore::HTMLTreeBuilder::processAnyOtherEndTagForInBody):
     38        (WebCore::HTMLTreeBuilder::processEndTagForInCell):
     39        (WebCore::HTMLTreeBuilder::processEndTagForInBody):
     40
    1412013-04-02  Hayato Ito  <hayato@chromium.org>
    242
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r147281 r147441  
    597597void HTMLConstructionSite::generateImpliedEndTagsWithExclusion(const AtomicString& tagName)
    598598{
    599     while (hasImpliedEndTag(currentStackItem()) && !currentStackItem()->hasLocalName(tagName))
     599    while (hasImpliedEndTag(currentStackItem()) && !currentStackItem()->matchesHTMLTag(tagName))
    600600        m_openElements.pop();
    601601}
  • trunk/Source/WebCore/html/parser/HTMLElementStack.cpp

    r146028 r147441  
    220220void HTMLElementStack::popUntil(const AtomicString& tagName)
    221221{
    222     while (!topStackItem()->hasLocalName(tagName)) {
     222    while (!topStackItem()->matchesHTMLTag(tagName)) {
    223223        // pop() will ASSERT if a <body>, <head> or <html> will be popped.
    224224        pop();
     
    226226}
    227227
    228 void HTMLElementStack::popUntil(const QualifiedName& tagName)
    229 {
    230     while (!topStackItem()->hasTagName(tagName)) {
    231         // pop() will ASSERT if a <body>, <head> or <html> will be popped.
    232         pop();
    233     }
    234 }
    235 
    236228void HTMLElementStack::popUntilPopped(const AtomicString& tagName)
    237 {
    238     popUntil(tagName);
    239     pop();
    240 }
    241 
    242 void HTMLElementStack::popUntilPopped(const QualifiedName& tagName)
    243229{
    244230    popUntil(tagName);
     
    443429{
    444430    for (ElementRecord* pos = m_top.get(); pos; pos = pos->next()) {
    445         if (pos->stackItem()->hasLocalName(tagName))
     431        if (pos->stackItem()->matchesHTMLTag(tagName))
    446432            return pos;
    447433    }
     
    464450    for (HTMLElementStack::ElementRecord* pos = top; pos; pos = pos->next()) {
    465451        HTMLStackItem* item = pos->stackItem().get();
    466         if (item->hasLocalName(targetTag))
    467             return true;
    468         if (isMarker(item))
    469             return false;
    470     }
    471     ASSERT_NOT_REACHED(); // <html> is always on the stack and is a scope marker.
    472     return false;
    473 }
    474 
    475 template <bool isMarker(HTMLStackItem*)>
    476 bool inScopeCommon(HTMLElementStack::ElementRecord* top, const QualifiedName& targetTag)
    477 {
    478     for (HTMLElementStack::ElementRecord* pos = top; pos; pos = pos->next()) {
    479         HTMLStackItem* item = pos->stackItem().get();
    480         if (item->hasTagName(targetTag))
     452        if (item->matchesHTMLTag(targetTag))
    481453            return true;
    482454        if (isMarker(item))
     
    520492bool HTMLElementStack::inScope(const QualifiedName& tagName) const
    521493{
    522     // FIXME: Is localName() right for non-html elements?
    523494    return inScope(tagName.localName());
    524495}
     
    531502bool HTMLElementStack::inListItemScope(const QualifiedName& tagName) const
    532503{
    533     // FIXME: Is localName() right for non-html elements?
    534504    return inListItemScope(tagName.localName());
    535505}
     
    542512bool HTMLElementStack::inTableScope(const QualifiedName& tagName) const
    543513{
    544     return inScopeCommon<isTableScopeMarker>(m_top.get(), tagName);
     514    return inTableScope(tagName.localName());
    545515}
    546516
     
    552522bool HTMLElementStack::inButtonScope(const QualifiedName& tagName) const
    553523{
    554     // FIXME: Is localName() right for non-html elements?
    555524    return inButtonScope(tagName.localName());
    556525}
     
    563532bool HTMLElementStack::inSelectScope(const QualifiedName& tagName) const
    564533{
    565     // FIXME: Is localName() right for non-html elements?
    566534    return inSelectScope(tagName.localName());
    567535}
  • trunk/Source/WebCore/html/parser/HTMLElementStack.h

    r146028 r147441  
    117117    void popUntil(Element*);
    118118    void popUntilPopped(const AtomicString& tagName);
    119 
    120     // FIXME: These are fixes for https://www.w3.org/Bugs/Public/show_bug.cgi?id=21292
    121     void popUntil(const QualifiedName&);
    122     void popUntilPopped(const QualifiedName&);
     119    void popUntilPopped(const QualifiedName& tagName) { popUntilPopped(tagName.localName()); }
    123120
    124121    void popUntilPopped(Element*);
  • trunk/Source/WebCore/html/parser/HTMLFormattingElementList.cpp

    r145248 r147441  
    5555        if (entry.isMarker())
    5656            return 0;
    57         if (entry.stackItem()->hasLocalName(targetName))
     57        if (entry.stackItem()->matchesHTMLTag(targetName))
    5858            return entry.element();
    5959    }
  • trunk/Source/WebCore/html/parser/HTMLStackItem.h

    r146904 r147441  
    7878    bool hasLocalName(const AtomicString& name) const { return m_tokenLocalName == name; }
    7979    bool hasTagName(const QualifiedName& name) const { return m_tokenLocalName == name.localName() && m_namespaceURI == name.namespaceURI(); }
     80
     81    bool matchesHTMLTag(const AtomicString& name) const { return m_tokenLocalName == name && m_namespaceURI == HTMLNames::xhtmlNamespaceURI; }
     82    bool matchesHTMLTag(const QualifiedName& name) const { return m_tokenLocalName == name && m_namespaceURI == HTMLNames::xhtmlNamespaceURI; }
    8083
    8184    bool causesFosterParenting()
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r147018 r147441  
    306306
    307307#if ENABLE(TEMPLATE_ELEMENT)
    308         if (contextElement->hasLocalName(templateTag))
     308        if (contextElement->hasTagName(templateTag))
    309309            m_templateInsertionModes.append(TemplateContentsMode);
    310310#endif
     
    15051505    while (1) {
    15061506        RefPtr<HTMLStackItem> item = record->stackItem();
    1507         if (item->hasLocalName(token->name())) {
     1507        if (item->matchesHTMLTag(token->name())) {
    15081508            m_tree.generateImpliedEndTagsWithExclusion(token->name());
    1509             if (!m_tree.currentStackItem()->hasLocalName(token->name()))
     1509            if (!m_tree.currentStackItem()->matchesHTMLTag(token->name()))
    15101510                parseError(token);
    15111511            m_tree.openElements()->popUntilPopped(item->element());
     
    17851785        }
    17861786        m_tree.generateImpliedEndTags();
    1787         if (!m_tree.currentStackItem()->hasLocalName(token->name()))
     1787        if (!m_tree.currentStackItem()->matchesHTMLTag(token->name()))
    17881788            parseError(token);
    17891789        m_tree.openElements()->popUntilPopped(token->name());
     
    18601860        }
    18611861        m_tree.generateImpliedEndTags();
    1862         if (!m_tree.currentStackItem()->hasLocalName(token->name()))
     1862        if (!m_tree.currentStackItem()->matchesHTMLTag(token->name()))
    18631863            parseError(token);
    18641864        m_tree.openElements()->popUntilPopped(token->name());
     
    18851885        }
    18861886        m_tree.generateImpliedEndTagsWithExclusion(token->name());
    1887         if (!m_tree.currentStackItem()->hasLocalName(token->name()))
     1887        if (!m_tree.currentStackItem()->matchesHTMLTag(token->name()))
    18881888            parseError(token);
    18891889        m_tree.openElements()->popUntilPopped(token->name());
     
    18961896        }
    18971897        m_tree.generateImpliedEndTagsWithExclusion(token->name());
    1898         if (!m_tree.currentStackItem()->hasLocalName(token->name()))
     1898        if (!m_tree.currentStackItem()->matchesHTMLTag(token->name()))
    18991899            parseError(token);
    19001900        m_tree.openElements()->popUntilPopped(token->name());
     
    19081908        }
    19091909        m_tree.generateImpliedEndTagsWithExclusion(token->name());
    1910         if (!m_tree.currentStackItem()->hasLocalName(token->name()))
     1910        if (!m_tree.currentStackItem()->matchesHTMLTag(token->name()))
    19111911            parseError(token);
    19121912        m_tree.openElements()->popUntilPopped(token->name());
     
    19191919        }
    19201920        m_tree.generateImpliedEndTags();
    1921         if (!m_tree.currentStackItem()->hasLocalName(token->name()))
     1921        if (!m_tree.currentStackItem()->matchesHTMLTag(token->name()))
    19221922            parseError(token);
    19231923        m_tree.openElements()->popUntilNumberedHeaderElementPopped();
     
    19361936        }
    19371937        m_tree.generateImpliedEndTags();
    1938         if (!m_tree.currentStackItem()->hasLocalName(token->name()))
     1938        if (!m_tree.currentStackItem()->matchesHTMLTag(token->name()))
    19391939            parseError(token);
    19401940        m_tree.openElements()->popUntilPopped(token->name());
Note: See TracChangeset for help on using the changeset viewer.