Title: [140101] trunk
Revision
140101
Author
rafa...@chromium.org
Date
2013-01-17 21:07:08 -0800 (Thu, 17 Jan 2013)

Log Message

Ensure the parser adopts foster-parented children into the document of their parent.
https://bugs.webkit.org/show_bug.cgi?id=107023

Reviewed by Adam Barth.

Source/WebCore:

Tests: fast/parser/foster-parent-adopted.html
       fast/parser/foster-parent-adopted2.html

* html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::insertTextNode):
(WebCore::HTMLConstructionSite::fosterParent):

LayoutTests:

This patch adopts the child into the parent's document after foster parenting to prevent a child from ending up in the tree with the wrong document.

* fast/parser/foster-parent-adopted-expected.txt: Added.
* fast/parser/foster-parent-adopted.html: Added.
* fast/parser/foster-parent-adopted2-expected.txt: Added.
* fast/parser/foster-parent-adopted2.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (140100 => 140101)


--- trunk/LayoutTests/ChangeLog	2013-01-18 04:41:36 UTC (rev 140100)
+++ trunk/LayoutTests/ChangeLog	2013-01-18 05:07:08 UTC (rev 140101)
@@ -1,3 +1,17 @@
+2013-01-17  Rafael Weinstein  <rafa...@chromium.org>
+
+        Ensure the parser adopts foster-parented children into the document of their parent.
+        https://bugs.webkit.org/show_bug.cgi?id=107023
+
+        Reviewed by Adam Barth.
+
+        This patch adopts the child into the parent's document after foster parenting to prevent a child from ending up in the tree with the wrong document.
+
+        * fast/parser/foster-parent-adopted-expected.txt: Added.
+        * fast/parser/foster-parent-adopted.html: Added.
+        * fast/parser/foster-parent-adopted2-expected.txt: Added.
+        * fast/parser/foster-parent-adopted2.html: Added.
+
 2013-01-17  Shinya Kawanaka  <shin...@chromium.org>
 
         Revert r122824 for a while

Added: trunk/LayoutTests/fast/parser/foster-parent-adopted-expected.txt (0 => 140101)


--- trunk/LayoutTests/fast/parser/foster-parent-adopted-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/parser/foster-parent-adopted-expected.txt	2013-01-18 05:07:08 UTC (rev 140101)
@@ -0,0 +1,3 @@
+This tests that when nodes are foster-parented after being adopted into another document, they are adopted back into the ownerDocument of their foster parent.
+
+PASS.

Added: trunk/LayoutTests/fast/parser/foster-parent-adopted.html (0 => 140101)


--- trunk/LayoutTests/fast/parser/foster-parent-adopted.html	                        (rev 0)
+++ trunk/LayoutTests/fast/parser/foster-parent-adopted.html	2013-01-18 05:07:08 UTC (rev 140101)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+  <body>
+      <p>This tests that when nodes are foster-parented after being adopted into another document,
+          they are adopted back into the ownerDocument of their foster parent. </p>
+      <table>
+          <tr>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var tr = document.querySelector('tr');
+var doc = document.implementation.createHTMLDocument();
+doc.adoptNode(tr);
+</script>
+              <div></div>
+          </tr>
+      </table>
+<script>
+var div = document.querySelector('div');
+if (div.ownerDocument === div.parentNode.ownerDocument)
+    document.body.appendChild(document.createTextNode('PASS.'));
+</script>
+    </body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/parser/foster-parent-adopted2-expected.txt (0 => 140101)


--- trunk/LayoutTests/fast/parser/foster-parent-adopted2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/parser/foster-parent-adopted2-expected.txt	2013-01-18 05:07:08 UTC (rev 140101)
@@ -0,0 +1,3 @@
+This tests that when nodes are foster-parented after being adopted into another document, they are adopted back into the ownerDocument of their foster parent.
+
+PASS.

Added: trunk/LayoutTests/fast/parser/foster-parent-adopted2.html (0 => 140101)


--- trunk/LayoutTests/fast/parser/foster-parent-adopted2.html	                        (rev 0)
+++ trunk/LayoutTests/fast/parser/foster-parent-adopted2.html	2013-01-18 05:07:08 UTC (rev 140101)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+  <body>
+      <p>This tests that when nodes are foster-parented after being adopted into another document,
+          they are adopted back into the ownerDocument of their foster parent. </p>
+      <table>
+          <tr>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var doc = document.implementation.createHTMLDocument();
+var div = document.createElement('div');
+doc.adoptNode(div);
+div.appendChild(document.querySelector('table'))
+</script>
+              <div id=fosterChild></div>
+          </tr>
+      </table>
+<script>
+var fosterChild = div.querySelector('#fosterChild');
+if (fosterChild.ownerDocument === fosterChild.parentNode.ownerDocument)
+    document.body.appendChild(document.createTextNode('PASS.'));
+</script>
+    </body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (140100 => 140101)


--- trunk/Source/WebCore/ChangeLog	2013-01-18 04:41:36 UTC (rev 140100)
+++ trunk/Source/WebCore/ChangeLog	2013-01-18 05:07:08 UTC (rev 140101)
@@ -1,3 +1,17 @@
+2013-01-17  Rafael Weinstein  <rafa...@chromium.org>
+
+        Ensure the parser adopts foster-parented children into the document of their parent.
+        https://bugs.webkit.org/show_bug.cgi?id=107023
+
+        Reviewed by Adam Barth.
+
+        Tests: fast/parser/foster-parent-adopted.html
+               fast/parser/foster-parent-adopted2.html
+
+        * html/parser/HTMLConstructionSite.cpp:
+        (WebCore::HTMLConstructionSite::insertTextNode):
+        (WebCore::HTMLConstructionSite::fosterParent):
+
 2013-01-17  Martin Robinson  <mrobin...@igalia.com>
 
         2013-01-17  Martin Robinson  <mrobin...@igalia.com>

Modified: trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp (140100 => 140101)


--- trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp	2013-01-18 04:41:36 UTC (rev 140100)
+++ trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp	2013-01-18 05:07:08 UTC (rev 140101)
@@ -503,6 +503,10 @@
         currentPosition += textNode->length();
         ASSERT(currentPosition <= characters.length());
         task.child = textNode.release();
+
+        if (task.parent->document() != task.child->document())
+            task.parent->document()->adoptNode(task.child, ASSERT_NO_EXCEPTION);
+
         executeTask(task);
     }
 }
@@ -639,6 +643,10 @@
     findFosterSite(task);
     task.child = node;
     ASSERT(task.parent);
+
+    if (task.parent->document() != task.child->document())
+        task.parent->document()->adoptNode(task.child, ASSERT_NO_EXCEPTION);
+
     m_attachmentQueue.append(task);
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to