From aea418392ab6cf2f3dfc519f12ef34f3f7516b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 17 Oct 2018 01:35:21 +0000 Subject: [PATCH] Bug 1499571 - HTMLOptionsCollection::Remove shouldn't remove the first element of the collection if out of bounds. r=bzbarsky Make it just forward to HTMLSelectElement::Remove like other browsers. Differential Revision: https://phabricator.services.mozilla.com/D8934 --- dom/html/HTMLOptionsCollection.cpp | 5 ----- dom/html/HTMLSelectElement.cpp | 4 ++++ dom/html/test/test_bug405242.html | 4 ++-- .../forms/the-select-element/select-remove.html.ini | 4 ---- 4 files changed, 6 insertions(+), 11 deletions(-) delete mode 100644 testing/web-platform/meta/html/semantics/forms/the-select-element/select-remove.html.ini diff --git a/dom/html/HTMLOptionsCollection.cpp b/dom/html/HTMLOptionsCollection.cpp index 651c9f2dc657..21ea157161b5 100644 --- a/dom/html/HTMLOptionsCollection.cpp +++ b/dom/html/HTMLOptionsCollection.cpp @@ -285,11 +285,6 @@ HTMLOptionsCollection::Remove(int32_t aIndex, ErrorResult& aError) aError.Throw(NS_ERROR_UNEXPECTED); return; } - - uint32_t len = mSelect->Length(); - if (aIndex < 0 || (uint32_t)aIndex >= len) - aIndex = 0; - mSelect->Remove(aIndex); } diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp index 21f3835256b3..8f0e86d097df 100644 --- a/dom/html/HTMLSelectElement.cpp +++ b/dom/html/HTMLSelectElement.cpp @@ -600,6 +600,10 @@ HTMLSelectElement::Add(nsGenericHTMLElement& aElement, void HTMLSelectElement::Remove(int32_t aIndex) { + if (aIndex < 0) { + return; + } + nsCOMPtr option = Item(static_cast(aIndex)); if (!option) { return; diff --git a/dom/html/test/test_bug405242.html b/dom/html/test/test_bug405242.html index 9ca3c11568ef..19c38c5de912 100644 --- a/dom/html/test/test_bug405242.html +++ b/dom/html/test/test_bug405242.html @@ -27,8 +27,8 @@ sel.appendChild(opt); sel.options.remove(0); sel.options.remove(1000); sel.options.remove(-1); -is(sel.length, 1, "Unexpected option collection length"); -is(sel[0].value, "10", "Unexpected remained option"); +is(sel.length, 3, "Unexpected option collection length"); +is(sel[2].value, "10", "Unexpected remained option"); diff --git a/testing/web-platform/meta/html/semantics/forms/the-select-element/select-remove.html.ini b/testing/web-platform/meta/html/semantics/forms/the-select-element/select-remove.html.ini deleted file mode 100644 index 083f9f14a525..000000000000 --- a/testing/web-platform/meta/html/semantics/forms/the-select-element/select-remove.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[select-remove.html] - [select.options.remove(n) should work] - expected: FAIL -