LibWeb: Implement HTMLSelectElement length, item() and namedItem()

These are simple calls through to the HTMLOptionsCollection functions
the same names, as with HTMLSelectElement.add().
This commit is contained in:
Zaggy1024 2022-10-18 03:22:55 -05:00 committed by Andreas Kling
parent 2547e0b966
commit f0420def78
Notes: sideshowbarker 2024-07-17 05:23:38 +09:00
3 changed files with 27 additions and 0 deletions

View File

@ -42,6 +42,27 @@ JS::GCPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
return m_options;
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-length
size_t HTMLSelectElement::length()
{
// The length IDL attribute must return the number of nodes represented by the options collection. On setting, it must act like the attribute of the same name on the options collection.
return const_cast<HTMLOptionsCollection&>(*options()).length();
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-item
DOM::Element* HTMLSelectElement::item(size_t index)
{
// The item(index) method must return the value returned by the method of the same name on the options collection, when invoked with the same argument.
return const_cast<HTMLOptionsCollection&>(*options()).item(index);
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-nameditem
DOM::Element* HTMLSelectElement::named_item(FlyString const& name)
{
// The namedItem(name) method must return the value returned by the method of the same name on the options collection, when invoked with the same argument.
return const_cast<HTMLOptionsCollection&>(*options()).named_item(name);
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-add
WebIDL::ExceptionOr<void> HTMLSelectElement::add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before)
{

View File

@ -25,6 +25,9 @@ public:
JS::GCPtr<HTMLOptionsCollection> const& options();
size_t length();
DOM::Element* item(size_t index);
DOM::Element* named_item(FlyString const& name);
WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
int selected_index() const;

View File

@ -10,6 +10,9 @@ interface HTMLSelectElement : HTMLElement {
[Reflect] attribute boolean required;
[SameObject] readonly attribute HTMLOptionsCollection options;
readonly attribute unsigned long length;
getter Element? item(unsigned long index);
getter Element? namedItem(DOMString name);
[CEReactions] undefined add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
attribute long selectedIndex;