From 834252543444c1bbaffc40538f09a332da17ee0a Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Mon, 8 Apr 2024 22:01:21 +0200 Subject: [PATCH] LibWeb: Use HTMLOptionElement in select item getter fix item --- Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp | 8 ++++---- Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h | 4 ++-- Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl | 6 ++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 8d423dfef07..72a741647eb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -114,17 +114,17 @@ WebIDL::ExceptionOr HTMLSelectElement::set_length(WebIDL::UnsignedLong len } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-item -DOM::Element* HTMLSelectElement::item(size_t index) +HTMLOptionElement* HTMLSelectElement::item(WebIDL::UnsignedLong 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(*options()).item(index); + return verify_cast(const_cast(*options()).item(index)); } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-nameditem -DOM::Element* HTMLSelectElement::named_item(FlyString const& name) +HTMLOptionElement* 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(*options()).named_item(name); + return verify_cast(const_cast(*options()).named_item(name)); } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-add diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index 819e174c2d2..4456e28a649 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -36,8 +36,8 @@ public: WebIDL::UnsignedLong length(); WebIDL::ExceptionOr set_length(WebIDL::UnsignedLong); - DOM::Element* item(size_t index); - DOM::Element* named_item(FlyString const& name); + HTMLOptionElement* item(WebIDL::UnsignedLong index); + HTMLOptionElement* named_item(FlyString const& name); WebIDL::ExceptionOr add(HTMLOptionOrOptGroupElement element, Optional before = {}); void remove(); void remove(WebIDL::Long); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl index d512e769fcf..35b06dcd91a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl @@ -19,10 +19,8 @@ interface HTMLSelectElement : HTMLElement { [SameObject] readonly attribute HTMLOptionsCollection options; [CEReactions] attribute unsigned long length; - // FIXME: Element is really HTMLOptionElement - getter Element? item(unsigned long index); - // FIXME: Element is really HTMLOptionElement - Element? namedItem(DOMString name); + getter HTMLOptionElement? item(unsigned long index); + HTMLOptionElement? namedItem(DOMString name); [CEReactions] undefined add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null); [CEReactions] undefined remove(); // ChildNode overload [CEReactions] undefined remove(long index);