Implement HTMLSelectElement.add() and indexed setter, fix test that was relying on add to be a stub

This commit is contained in:
Patrick Shaughnessy 2020-01-06 20:14:36 -05:00
parent 1d645f3741
commit c1b71fcc4d
7 changed files with 34 additions and 48 deletions

View file

@ -5263,7 +5263,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
CGIndenter(CGProxyNamedSetter(self.descriptor)).define() +
" return (*opresult).succeed();\n" +
"}\n")
else:
elif self.descriptor.operations['NamedGetter']:
set += ("if RUST_JSID_IS_STRING(id) || RUST_JSID_IS_INT(id) {\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() +
" if result.is_some() {\n"

View file

@ -12,6 +12,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelec
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use crate::dom::bindings::codegen::UnionTypes::HTMLElementOrLong;
use crate::dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement;
use crate::dom::bindings::error::ErrorResult;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
@ -203,13 +204,13 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
ValidityState::new(&window, self.upcast())
}
// Note: this function currently only exists for union.html.
// https://html.spec.whatwg.org/multipage/#dom-select-add
fn Add(
&self,
_element: HTMLOptionElementOrHTMLOptGroupElement,
_before: Option<HTMLElementOrLong>,
) {
element: HTMLOptionElementOrHTMLOptGroupElement,
before: Option<HTMLElementOrLong>,
) -> ErrorResult {
self.Options().Add(element, before)
}
// https://html.spec.whatwg.org/multipage/#dom-fe-disabled
@ -281,6 +282,11 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
self.Options().IndexedGetter(index)
}
// https://html.spec.whatwg.org/multipage/#dom-select-setter
fn IndexedSetter(&self, index: u32, value: Option<&HTMLOptionElement>) -> ErrorResult {
self.Options().IndexedSetter(index, value)
}
// https://html.spec.whatwg.org/multipage/#dom-select-nameditem
fn NamedItem(&self, name: DOMString) -> Option<DomRoot<HTMLOptionElement>> {
self.Options()

View file

@ -28,15 +28,14 @@ interface HTMLSelectElement : HTMLElement {
attribute unsigned long length;
getter Element? item(unsigned long index);
HTMLOptionElement? namedItem(DOMString name);
// Note: this function currently only exists for union.html.
[CEReactions]
[CEReactions, Throws]
void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
[CEReactions]
void remove(); // ChildNode overload
[CEReactions]
void remove(long index);
// [CEReactions]
// setter void (unsigned long index, HTMLOptionElement? option);
[CEReactions, Throws] setter void (unsigned long index, HTMLOptionElement? option);
// readonly attribute HTMLCollection selectedOptions;
attribute long selectedIndex;