Use the original token to create an element in "reconstruct the active formatting...
authorkseo@webkit.org <kseo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jul 2012 23:15:50 +0000 (23:15 +0000)
committerkseo@webkit.org <kseo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jul 2012 23:15:50 +0000 (23:15 +0000)
commitedf5f5a08dcf5e8abd93f2e380212993f19f2b90
tree62125d78f10e4cfe7b883097d69013220ae364cf
parent44897501a8dcc55ca7193089ef761271b710e156
Use the original token to create an element in "reconstruct the active formatting elements" and "call the adoption agency"
https://bugs.webkit.org/show_bug.cgi?id=91703

Reviewed by Adam Barth.

Source/WebCore:

The current WebKit HTML5 parser implementation does not hold the original token
in the stack of open elements and the active formatting elements. This is
problematic because the original token is used to create an element in
"reconstruct the active formatting elements" and "call the adoption agency".

As a workaround, WebKit uses the saved element instead of the original token
to create an element. But this causes us to fail examples like this:
<b id="1"><p><script>document.getElementById("1").id = "2"</script></p>TEXT</b>
reconstructTheActiveFormattingElements calls this method to open a second <b>
tag to wrap TEXT, it will have id "2", even though the HTML5 spec implies it
should be "1".

Created a ref-counted container class, HTMLStackItem to hold the original token
and the namespace URI as well as the element. Changed HTMLElementStack and
HTMLFormattingElementList to use HTMLStackItem.
Changed HTMLConstructionSite::reconstructTheActiveFormattingElements and
HTMLTreeBuilder::callTheAdoptionAgency to create an element from the saved token
instead of the saved element.

Updated test expectation for html5lib/runner-expected.txt
because now resources/scripted/adoption01.dat passes.

* html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::insertHTMLHtmlStartTagBeforeHTML):
(WebCore::HTMLConstructionSite::insertHTMLHeadElement):
(WebCore::HTMLConstructionSite::insertHTMLBodyElement):
(WebCore::HTMLConstructionSite::insertHTMLFormElement):
(WebCore::HTMLConstructionSite::insertHTMLElement):
(WebCore::HTMLConstructionSite::insertFormattingElement):
(WebCore::HTMLConstructionSite::insertScriptElement):
(WebCore::HTMLConstructionSite::insertForeignElement):
(WebCore::HTMLConstructionSite::createElementFromSavedToken):
(WebCore::HTMLConstructionSite::reconstructTheActiveFormattingElements):
* html/parser/HTMLConstructionSite.h:
(HTMLConstructionSite):
(WebCore::HTMLConstructionSite::currentElementRecord):
* html/parser/HTMLElementStack.cpp:
(WebCore::HTMLElementStack::ElementRecord::ElementRecord):
(WebCore::HTMLElementStack::ElementRecord::replaceElement):
(WebCore::HTMLElementStack::pushRootNode):
(WebCore::HTMLElementStack::pushHTMLHtmlElement):
(WebCore::HTMLElementStack::pushRootNodeCommon):
(WebCore::HTMLElementStack::pushHTMLHeadElement):
(WebCore::HTMLElementStack::pushHTMLBodyElement):
(WebCore::HTMLElementStack::push):
(WebCore::HTMLElementStack::insertAbove):
(WebCore::HTMLElementStack::pushCommon):
* html/parser/HTMLElementStack.h:
(WebCore::HTMLElementStack::ElementRecord::element):
(WebCore::HTMLElementStack::ElementRecord::node):
(WebCore::HTMLElementStack::ElementRecord::stackItem):
(ElementRecord):
(HTMLElementStack):
* html/parser/HTMLFormattingElementList.cpp:
(WebCore::HTMLFormattingElementList::swapTo):
(WebCore::HTMLFormattingElementList::append):
* html/parser/HTMLFormattingElementList.h:
(WebCore::HTMLFormattingElementList::Entry::Entry):
(WebCore::HTMLFormattingElementList::Entry::isMarker):
(WebCore::HTMLFormattingElementList::Entry::stackItem):
(WebCore::HTMLFormattingElementList::Entry::element):
(WebCore::HTMLFormattingElementList::Entry::replaceElement):
(WebCore::HTMLFormattingElementList::Entry::operator==):
(WebCore::HTMLFormattingElementList::Entry::operator!=):
(Entry):
(HTMLFormattingElementList):
* html/parser/HTMLStackItem.h: Added.
(WebCore):
(HTMLStackItem):
(WebCore::HTMLStackItem::create):
(WebCore::HTMLStackItem::element):
(WebCore::HTMLStackItem::node):
(WebCore::HTMLStackItem::token):
(WebCore::HTMLStackItem::namespaceURI):
(WebCore::HTMLStackItem::HTMLStackItem):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
(WebCore::HTMLTreeBuilder::processStartTag):
(WebCore::HTMLTreeBuilder::callTheAdoptionAgency):

LayoutTests:

Updated test expectation for html5lib/runner-expected.txt
because now resources/scripted/adoption01.dat passes.

* html5lib/runner-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@123399 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/html5lib/runner-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/html/parser/HTMLConstructionSite.h
Source/WebCore/html/parser/HTMLElementStack.cpp
Source/WebCore/html/parser/HTMLElementStack.h
Source/WebCore/html/parser/HTMLFormattingElementList.cpp
Source/WebCore/html/parser/HTMLFormattingElementList.h
Source/WebCore/html/parser/HTMLStackItem.h [new file with mode: 0644]
Source/WebCore/html/parser/HTMLTreeBuilder.cpp