Skip to content

Commit

Permalink
Merge r224398 - Invalidate node list when associated form control ele…
Browse files Browse the repository at this point in the history
…ment 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.
  • Loading branch information
dydz authored and carlosgcampos committed Jan 24, 2018
1 parent bcdbd1f commit f50f36a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
14 changes: 14 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,17 @@
2017-11-03 Daniel Bates <dabates@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-10-27 Daniel Bates <dabates@apple.com>

Only allow non-mixed content protected subresources to ask for credentials
Expand Down
@@ -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

28 changes: 28 additions & 0 deletions LayoutTests/fast/forms/node-list-remove-button-from-form.html
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</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>
17 changes: 17 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,20 @@
2017-11-03 Daniel Bates <dabates@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-10-27 Daniel Bates <dabates@apple.com>

Only allow non-mixed content protected subresources to ask for credentials
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/html/HTMLFormElement.cpp
Expand Up @@ -546,6 +546,9 @@ void HTMLFormElement::removeFormElement(FormAssociatedElement* e)
removeFromPastNamesMap(e);
m_associatedElements.remove(index);

if (auto* nodeLists = this->nodeLists())
nodeLists->invalidateCaches();

if (e == m_defaultButton)
resetDefaultButton();
}
Expand Down

0 comments on commit f50f36a

Please sign in to comment.