Title: [224398] trunk
Revision
224398
Author
dba...@webkit.org
Date
2017-11-03 08:41:10 -0700 (Fri, 03 Nov 2017)

Log Message

Invalidate node list when associated form control element is removed
https://bugs.webkit.org/show_bug.cgi?id=179232
<rdar://problem/35308269>

Reviewed by Ryosuke Niwa.

Source/WebCore:

A node list represents a live view of the DOM. Invalidate the node list
associated with a form element whenever one of its associated form control
elements is removed.

Test: fast/forms/node-list-remove-button-from-form.html

* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::removeFormElement):

LayoutTests:

Add a test to ensure the node list returned by HTMLFormElement.elements stays synchronized
with the document.

* fast/forms/node-list-remove-button-from-form-expected.txt: Added.
* fast/forms/node-list-remove-button-from-form.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (224397 => 224398)


--- trunk/LayoutTests/ChangeLog	2017-11-03 15:24:16 UTC (rev 224397)
+++ trunk/LayoutTests/ChangeLog	2017-11-03 15:41:10 UTC (rev 224398)
@@ -1,3 +1,17 @@
+2017-11-03  Daniel Bates  <daba...@apple.com>
+
+        Invalidate node list when associated form control element is removed
+        https://bugs.webkit.org/show_bug.cgi?id=179232
+        <rdar://problem/35308269>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add a test to ensure the node list returned by HTMLFormElement.elements stays synchronized
+        with the document.
+
+        * fast/forms/node-list-remove-button-from-form-expected.txt: Added.
+        * fast/forms/node-list-remove-button-from-form.html: Added.
+
 2017-11-03  Antti Koivisto  <an...@apple.com>
 
         Crash in WebCore::RenderStyle::overflowX with display:contents

Added: trunk/LayoutTests/fast/forms/node-list-remove-button-from-form-expected.txt (0 => 224398)


--- trunk/LayoutTests/fast/forms/node-list-remove-button-from-form-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/node-list-remove-button-from-form-expected.txt	2017-11-03 15:41:10 UTC (rev 224398)
@@ -0,0 +1,15 @@
+Tests that removing a <button> from the document removes it from HTMLFormElement.elements.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Before removal of button:
+PASS document.getElementById('aForm').elements is non-null.
+PASS document.getElementById('aForm')['aButton'] is document.getElementById('aButton')
+
+After removal of button:
+PASS document.getElementById('aForm')['aButton'] is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/node-list-remove-button-from-form.html (0 => 224398)


--- trunk/LayoutTests/fast/forms/node-list-remove-button-from-form.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/node-list-remove-button-from-form.html	2017-11-03 15:41:10 UTC (rev 224398)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<button id="aButton" form="aForm"></button>
+<form id="aForm"></form>
+<script>
+description("Tests that removing a &lt;button&gt; from the document removes it from HTMLFormElement.elements.");
+
+runTest();
+
+function runTest()
+{
+    debug("Before removal of button:");
+    shouldBeNonNull("document.getElementById('aForm').elements");
+    shouldBe("document.getElementById('aForm')['aButton']", "document.getElementById('aButton')");
+    document.getElementById('aButton').remove();
+
+    debug("<br>After removal of button:");
+    shouldBeUndefined("document.getElementById('aForm')['aButton']");
+}
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (224397 => 224398)


--- trunk/Source/WebCore/ChangeLog	2017-11-03 15:24:16 UTC (rev 224397)
+++ trunk/Source/WebCore/ChangeLog	2017-11-03 15:41:10 UTC (rev 224398)
@@ -1,3 +1,20 @@
+2017-11-03  Daniel Bates  <daba...@apple.com>
+
+        Invalidate node list when associated form control element is removed
+        https://bugs.webkit.org/show_bug.cgi?id=179232
+        <rdar://problem/35308269>
+
+        Reviewed by Ryosuke Niwa.
+
+        A node list represents a live view of the DOM. Invalidate the node list
+        associated with a form element whenever one of its associated form control
+        elements is removed.
+
+        Test: fast/forms/node-list-remove-button-from-form.html
+
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::removeFormElement):
+
 2017-11-03  Frederic Wang  <fw...@igalia.com>
 
         Add USE(APPLE_INTERNAL_SDK)-guards around SPI in ResourceHandle code

Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (224397 => 224398)


--- trunk/Source/WebCore/html/HTMLFormElement.cpp	2017-11-03 15:24:16 UTC (rev 224397)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp	2017-11-03 15:41:10 UTC (rev 224398)
@@ -552,6 +552,9 @@
     removeFromPastNamesMap(e);
     m_associatedElements.remove(index);
 
+    if (auto* nodeLists = this->nodeLists())
+        nodeLists->invalidateCaches();
+
     if (e == m_defaultButton)
         resetDefaultButton();
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to