Set Attr.ownerDocument in Element#setAttributeNode()
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jun 2013 17:47:49 +0000 (17:47 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jun 2013 17:47:49 +0000 (17:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=118031

Reviewed by Andreas Kling.

Source/WebCore:

Merge https://chromium.googlesource.com/chromium/blink/+/fa739fe5369f55bbdcb3fa123cb64df36b8ae414.

Adopt Attr node as needed.

Test: fast/dom/Attr/set-attribute-node-from-iframe.html

* dom/Element.cpp:
(WebCore::Element::setAttributeNode):

LayoutTests:

Add a regression test.

* fast/dom/Attr/set-attribute-node-from-iframe-expected.txt: Added.
* fast/dom/Attr/set-attribute-node-from-iframe.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/Attr/set-attribute-node-from-iframe-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Attr/set-attribute-node-from-iframe.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp

index 49e8989..270fa56 100644 (file)
@@ -1,3 +1,15 @@
+2013-06-26  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Set Attr.ownerDocument in Element#setAttributeNode()
+        https://bugs.webkit.org/show_bug.cgi?id=118031
+
+        Reviewed by Andreas Kling.
+
+        Add a regression test.
+
+        * fast/dom/Attr/set-attribute-node-from-iframe-expected.txt: Added.
+        * fast/dom/Attr/set-attribute-node-from-iframe.html: Added.
+
 2013-06-25  David Hyatt  <hyatt@apple.com>
 
         Flex boxes (both old and new) don't handle max-height images correctly.
 2013-06-25  David Hyatt  <hyatt@apple.com>
 
         Flex boxes (both old and new) don't handle max-height images correctly.
diff --git a/LayoutTests/fast/dom/Attr/set-attribute-node-from-iframe-expected.txt b/LayoutTests/fast/dom/Attr/set-attribute-node-from-iframe-expected.txt
new file mode 100644 (file)
index 0000000..ddb3522
--- /dev/null
@@ -0,0 +1,12 @@
+ownerDocument of Attr should be set on setAttributeNode
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS attr = iframeDocument.createAttribute("foo"); attr.ownerDocument is iframeDocument
+PASS elementToBeMoved.setAttributeNode(attr); attr.ownerDocument is document
+PASS iframeDocument.documentElement.appendChild(elementToBeMoved); attr.ownerDocument is iframeDocument
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/Attr/set-attribute-node-from-iframe.html b/LayoutTests/fast/dom/Attr/set-attribute-node-from-iframe.html
new file mode 100644 (file)
index 0000000..974f58d
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<iframe></iframe>
+<div id="toBeMoved"></div>
+<script>
+description("ownerDocument of Attr should be set on setAttributeNode");
+
+var elementToBeMoved = document.getElementById("toBeMoved");
+iframeElement = document.getElementsByTagName("iframe")[0];
+iframeDocument = iframeElement.contentWindow.document;
+
+shouldBe('attr = iframeDocument.createAttribute("foo"); attr.ownerDocument', 'iframeDocument');
+shouldBe('elementToBeMoved.setAttributeNode(attr); attr.ownerDocument', 'document');
+shouldBe('iframeDocument.documentElement.appendChild(elementToBeMoved); attr.ownerDocument', 'iframeDocument');
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 59ee305..71fcb0a 100644 (file)
@@ -1,3 +1,19 @@
+2013-06-26  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Set Attr.ownerDocument in Element#setAttributeNode()
+        https://bugs.webkit.org/show_bug.cgi?id=118031
+
+        Reviewed by Andreas Kling.
+
+        Merge https://chromium.googlesource.com/chromium/blink/+/fa739fe5369f55bbdcb3fa123cb64df36b8ae414.
+
+        Adopt Attr node as needed.
+
+        Test: fast/dom/Attr/set-attribute-node-from-iframe.html
+
+        * dom/Element.cpp:
+        (WebCore::Element::setAttributeNode):
+
 2013-06-25  David Hyatt  <hyatt@apple.com>
 
         Flex boxes (both old and new) don't handle max-height images correctly.
 2013-06-25  David Hyatt  <hyatt@apple.com>
 
         Flex boxes (both old and new) don't handle max-height images correctly.
index f48fb11..c016d13 100644 (file)
@@ -1934,6 +1934,7 @@ PassRefPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionCode& ec)
     setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), NotInSynchronizationOfLazyAttribute);
 
     attrNode->attachToElement(this);
     setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), NotInSynchronizationOfLazyAttribute);
 
     attrNode->attachToElement(this);
+    treeScope()->adoptIfNeeded(attrNode);
     ensureAttrNodeListForElement(this)->append(attrNode);
 
     return oldAttrNode.release();
     ensureAttrNodeListForElement(this)->append(attrNode);
 
     return oldAttrNode.release();