LibWeb: Add select and options collection remove method

This commit is contained in:
Bastiaan van der Plaat 2024-04-08 21:56:33 +02:00 committed by Andreas Kling
commit 7372c01786
Notes: sideshowbarker 2024-07-17 14:36:19 +09:00
8 changed files with 62 additions and 3 deletions

View file

@ -111,6 +111,24 @@ WebIDL::ExceptionOr<void> HTMLOptionsCollection::add(HTMLOptionOrOptGroupElement
return {};
}
// https://html.spec.whatwg.org/#dom-htmloptionscollection-remove
void HTMLOptionsCollection::remove(WebIDL::Long index)
{
// 1. If the number of nodes represented by the collection is zero, return.
if (length() == 0)
return;
// 2. If index is not a number greater than or equal to 0 and less than the number of nodes represented by the collection, return.
if (index < 0 || static_cast<WebIDL::UnsignedLong>(index) >= length())
return;
// 3. Let element be the indexth element in the collection.
auto* element = this->item(index);
// 4. Remove element from its parent node.
element->remove();
}
// https://html.spec.whatwg.org/#dom-htmloptionscollection-selectedindex
WebIDL::Long HTMLOptionsCollection::selected_index() const
{