Source/WebCore: LabelsNodeList isn't updated properly after its owner node is adopted into a new document
https://bugs.webkit.org/show_bug.cgi?id=89730
Reviewed by Darin Adler.
When a node is adopted, node lists that are invalidated at document level need to be unregistered
from old document and registered to new document so that DOM mutations in new document will invalidate
caches in the node lists. Done that in NodeListsNodeData::adoptTreeScope, which was extracted from
TreeScopeAdopter::moveTreeToNewScope.
Also renamed DynamicNodeList::node() and m_node to rootNode() and m_ownerNode to better express
their semantics and added ownerNode() to make m_ownerNode private to DynamicNodeList.
Test: fast/forms/label/labels-owner-node-adopted.html
* bindings/js/JSNodeListCustom.cpp:
(WebCore::JSNodeListOwner::isReachableFromOpaqueRoots):
* dom/ChildNodeList.cpp:
(WebCore::ChildNodeList::~ChildNodeList):
(WebCore::ChildNodeList::length):
(WebCore::ChildNodeList::item):
(WebCore::ChildNodeList::nodeMatches):
* dom/ClassNodeList.cpp:
(WebCore::ClassNodeList::ClassNodeList):
(WebCore::ClassNodeList::~ClassNodeList):
* dom/DynamicNodeList.cpp:
(WebCore::DynamicSubtreeNodeList::length):
(WebCore::DynamicSubtreeNodeList::itemForwardsFromCurrent):
(WebCore::DynamicSubtreeNodeList::itemBackwardsFromCurrent):
(WebCore::DynamicSubtreeNodeList::item):
(WebCore::DynamicNodeList::itemWithName):
* dom/DynamicNodeList.h:
(WebCore::DynamicNodeList::DynamicNodeList):
(WebCore::DynamicNodeList::ownerNode):
(WebCore::DynamicNodeList::rootedAtDocument):
(WebCore::DynamicNodeList::shouldInvalidateOnAttributeChange):
(WebCore::DynamicNodeList::rootNode):
(WebCore::DynamicNodeList::document):
(DynamicNodeList):
* dom/NameNodeList.cpp:
(WebCore::NameNodeList::~NameNodeList):
* dom/NodeRareData.h:
(WebCore::NodeListsNodeData::adoptTreeScope):
(NodeListsNodeData):
* dom/TagNodeList.cpp:
(WebCore::TagNodeList::~TagNodeList):
* dom/TreeScopeAdopter.cpp:
(WebCore::TreeScopeAdopter::moveTreeToNewScope):
* html/LabelsNodeList.cpp:
(WebCore::LabelsNodeList::~LabelsNodeList):
(WebCore::LabelsNodeList::nodeMatches):
* html/RadioNodeList.cpp:
(WebCore::RadioNodeList::~RadioNodeList):
(WebCore::RadioNodeList::checkElementMatchesRadioNodeListFilter):
LayoutTests: LabelsNostList isn't updated properly after its owner node is adopted into a new document
https://bugs.webkit.org/show_bug.cgi?id=89730
Reviewed by Darin Adler.
* fast/forms/label/labels-owner-node-adopted-expected.txt: Added.
* fast/forms/label/labels-owner-node-adopted.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121003 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/fast/forms/label/labels-owner-node-adopted-expected.txt b/LayoutTests/fast/forms/label/labels-owner-node-adopted-expected.txt
new file mode 100644
index 0000000..b1f5174
--- /dev/null
+++ b/LayoutTests/fast/forms/label/labels-owner-node-adopted-expected.txt
@@ -0,0 +1,13 @@
+This tests moving a node with labels property from one document to another. The labels node list should be updated when labels are modified in the new document.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+The input element initially have two label elements #label1 and #label2.
+PASS labels = input.labels; labels.length is 2
+PASS label0 = labels[0]; label1 = labels[1]; iframe.contentDocument.body.appendChild(form); labels.length; label1.parentNode.removeChild(label1); labels.length is 1
+PASS labels[0] is label0
+PASS label0.parentNode.appendChild(label1); labels.length is 2
+PASS labels[0] is label0
+PASS labels[1] is label1
+