2010-09-12 Adam Barth <abarth@webkit.org>
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Sep 2010 01:04:35 +0000 (01:04 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Sep 2010 01:04:35 +0000 (01:04 +0000)
        Reviewed by Eric Seidel.

        Adoption agency should use takeAllChildrenFrom
        https://bugs.webkit.org/show_bug.cgi?id=45570

        Before this patch, we were using an unsafe pattern of walking the
        sibling list without grabbing references.  Instead, we should use the
        shiny new takeAllChildrenFrom method that shoves the children into a
        vector first.  Also, update takeAllChildrenFrom to handle the case
        where the old parent is attached.

        * dom/ContainerNode.cpp:
        (WebCore::ContainerNode::takeAllChildrenFrom):
        * html/parser/HTMLTreeBuilder.cpp:
        (WebCore::HTMLTreeBuilder::callTheAdoptionAgency):
        * html/parser/HTMLTreeBuilder.h:
2010-09-12  Adam Barth  <abarth@webkit.org>

        Reviewed by Eric Seidel.

        Adoption agency should use takeAllChildrenFrom
        https://bugs.webkit.org/show_bug.cgi?id=45570

        More test cases.

        * html5lib/resources/webkit01.dat:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@67357 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/html5lib/resources/webkit01.dat
LayoutTests/platform/mac/http/tests/navigation/post-goback1-expected.txt
LayoutTests/platform/mac/http/tests/navigation/postredirect-basic-expected.txt
LayoutTests/platform/mac/http/tests/navigation/postredirect-frames-expected.txt
LayoutTests/platform/mac/http/tests/navigation/postredirect-goback1-expected.txt
WebCore/ChangeLog
WebCore/dom/ContainerNode.cpp
WebCore/html/parser/HTMLTreeBuilder.cpp
WebCore/html/parser/HTMLTreeBuilder.h

index a529cce..bf876a4 100644 (file)
@@ -2,6 +2,17 @@
 
         Reviewed by Eric Seidel.
 
+        Adoption agency should use takeAllChildrenFrom
+        https://bugs.webkit.org/show_bug.cgi?id=45570
+
+        More test cases.
+
+        * html5lib/resources/webkit01.dat:
+
+2010-09-12  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Eric Seidel.
+
         isParsingFragment assert hit in new treebuilder
         https://bugs.webkit.org/show_bug.cgi?id=45621
 
index 7022813..a4cbde0 100644 (file)
@@ -432,3 +432,43 @@ console.log("FOO<span>BAR</span>BAZ");
 |         <tbody>
 |           <tr>
 |       <div>
+
+#data
+<a><li><style></style><title></title></a>
+#errors
+#document
+| <html>
+|   <head>
+|   <body>
+|     <a>
+|     <li>
+|       <a>
+|         <style>
+|         <title>
+
+#data
+<font></p><p><meta><title></title></font>
+#errors
+#document
+| <html>
+|   <head>
+|   <body>
+|     <font>
+|       <p>
+|     <p>
+|       <font>
+|         <meta>
+|         <title>
+
+#data
+<a><center><title></title><a>
+#errors
+#document
+| <html>
+|   <head>
+|   <body>
+|     <a>
+|     <center>
+|       <a>
+|         <title>
+|       <a>
index 62479e9..fe41dc6 100644 (file)
@@ -20,6 +20,7 @@ layer at (0,0) size 800x600
       RenderBR {BR} at (0,0) size 0x0
       RenderText {#text} at (0,296) size 591x37
         text run at (0,296) width 591: "This page was requested with an HTTP POST"
+      RenderText {#text} at (0,0) size 0x0
 
 ============== Back Forward List ==============
         http://127.0.0.1:8000/navigation/post-goback1.html  **nav target**
index f353654..6c9a27b 100644 (file)
@@ -20,6 +20,7 @@ layer at (0,0) size 800x600
       RenderBR {BR} at (0,0) size 0x0
       RenderText {#text} at (0,296) size 575x37
         text run at (0,296) width 575: "This page was requested with an HTTP GET"
+      RenderText {#text} at (0,0) size 0x0
 
 ============== Back Forward List ==============
         http://127.0.0.1:8000/navigation/postredirect-basic.html  **nav target**
index bcf663e..de49e7d 100644 (file)
@@ -26,6 +26,7 @@ layer at (0,0) size 800x600
               RenderBR {BR} at (0,0) size 0x0
               RenderText {#text} at (0,296) size 575x37
                 text run at (0,296) width 575: "This page was requested with an HTTP GET"
+              RenderText {#text} at (0,0) size 0x0
       RenderFrame {FRAME} at (0,540) size 800x60
         layer at (0,0) size 785x90
           RenderView at (0,0) size 785x60
index f37153f..89175bf 100644 (file)
@@ -20,6 +20,7 @@ layer at (0,0) size 800x600
       RenderBR {BR} at (0,0) size 0x0
       RenderText {#text} at (0,296) size 575x37
         text run at (0,296) width 575: "This page was requested with an HTTP GET"
+      RenderText {#text} at (0,0) size 0x0
 
 ============== Back Forward List ==============
         http://127.0.0.1:8000/navigation/postredirect-goback1.html  **nav target**
index fb66f95..b3e8873 100644 (file)
@@ -2,6 +2,25 @@
 
         Reviewed by Eric Seidel.
 
+        Adoption agency should use takeAllChildrenFrom
+        https://bugs.webkit.org/show_bug.cgi?id=45570
+
+        Before this patch, we were using an unsafe pattern of walking the
+        sibling list without grabbing references.  Instead, we should use the
+        shiny new takeAllChildrenFrom method that shoves the children into a
+        vector first.  Also, update takeAllChildrenFrom to handle the case
+        where the old parent is attached.
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::takeAllChildrenFrom):
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLTreeBuilder::callTheAdoptionAgency):
+        * html/parser/HTMLTreeBuilder.h:
+
+2010-09-12  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Eric Seidel.
+
         isParsingFragment assert hit in new treebuilder
         https://bugs.webkit.org/show_bug.cgi?id=45621
 
index 1e337b0..2dd50bb 100644 (file)
@@ -72,7 +72,6 @@ void ContainerNode::removeAllChildren()
     removeAllChildrenInContainer<Node, ContainerNode>(this);
 }
 
-
 void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
 {
     NodeVector children;
@@ -82,10 +81,14 @@ void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
 
     for (unsigned i = 0; i < children.size(); ++i) {
         ExceptionCode ec = 0;
+        if (children[i]->attached())
+            children[i]->detach();
         // FIXME: We need a no mutation event version of adoptNode.
         RefPtr<Node> child = document()->adoptNode(children[i].release(), ec);
         ASSERT(!ec);
-        parserAddChild(child.release());
+        parserAddChild(child.get());
+        if (attached() && !child->attached())
+            child->attach();
     }
 }
 
index 9241837..7cd9f34 100644 (file)
@@ -1612,21 +1612,6 @@ HTMLElementStack::ElementRecord* HTMLTreeBuilder::furthestBlockForFormattingElem
     return 0;
 }
 
-// FIXME: This should have a whitty name.
-// FIXME: This must be implemented in many other places in WebCore.
-void HTMLTreeBuilder::reparentChildren(Element* oldParent, Element* newParent)
-{
-    Node* child = oldParent->firstChild();
-    while (child) {
-        Node* nextChild = child->nextSibling();
-        oldParent->parserRemoveChild(child);
-        newParent->parserAddChild(child);
-        if (newParent->attached() && !child->attached())
-            child->attach();
-        child = nextChild;
-    }
-}
-
 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#parsing-main-inbody
 void HTMLTreeBuilder::callTheAdoptionAgency(AtomicHTMLToken& token)
 {
@@ -1719,7 +1704,7 @@ void HTMLTreeBuilder::callTheAdoptionAgency(AtomicHTMLToken& token)
         // 8
         RefPtr<Element> newElement = m_tree.createHTMLElementFromElementRecord(formattingElementRecord);
         // 9
-        reparentChildren(furthestBlock->element(), newElement.get());
+        newElement->takeAllChildrenFrom(furthestBlock->element());
         // 10
         Element* furthestBlockElement = furthestBlock->element();
         // FIXME: All this creation / parserAddChild / attach business should
index 4634f0a..b483f96 100644 (file)
@@ -170,7 +170,6 @@ private:
     PassRefPtr<NamedNodeMap> attributesForIsindexInput(AtomicHTMLToken&);
 
     HTMLElementStack::ElementRecord* furthestBlockForFormattingElement(Element*);
-    void reparentChildren(Element* oldParent, Element* newParent);
     void callTheAdoptionAgency(AtomicHTMLToken&);
 
     void closeTheCell();