diff --git a/servo/components/script/dom/htmlselectelement.rs b/servo/components/script/dom/htmlselectelement.rs index 03d10e117f4e..c44dac71000f 100644 --- a/servo/components/script/dom/htmlselectelement.rs +++ b/servo/components/script/dom/htmlselectelement.rs @@ -299,6 +299,36 @@ impl HTMLSelectElementMethods for HTMLSelectElement { opt.set_selectedness(false); } } + + // https://html.spec.whatwg.org/multipage/#dom-select-selectedindex + fn SelectedIndex(&self) -> i32 { + self.upcast::() + .traverse_preorder() + .filter_map(Root::downcast::) + .enumerate() + .filter(|&(_, ref opt_elem)| opt_elem.Selected()) + .map(|(i, _)| i as i32) + .next() + .unwrap_or(-1) + } + + // https://html.spec.whatwg.org/multipage/#dom-select-selectedindex + fn SetSelectedIndex(&self, index: i32) { + let mut opt_iter = self.upcast::() + .traverse_preorder() + .filter_map(Root::downcast::); + for opt in opt_iter.by_ref().take(index as usize) { + opt.set_selectedness(false); + } + if let Some(opt) = opt_iter.next() { + opt.set_selectedness(true); + opt.set_dirtiness(true); + // Reset remaining