From 0eeb075ecd68f79281d99721efe78709c63486e1 Mon Sep 17 00:00:00 2001 From: Patrick Shaughnessy Date: Mon, 10 Feb 2020 14:35:48 -0500 Subject: [PATCH] rooted at the form's root, not rooted at the form --- .../script/dom/htmlformcontrolscollection.rs | 21 +++++++++++-------- .../form-elements-filter.html.ini | 3 --- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/components/script/dom/htmlformcontrolscollection.rs b/components/script/dom/htmlformcontrolscollection.rs index 1cf969a2fdd..410244c52c1 100644 --- a/components/script/dom/htmlformcontrolscollection.rs +++ b/components/script/dom/htmlformcontrolscollection.rs @@ -5,10 +5,11 @@ use crate::dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods; use crate::dom::bindings::codegen::Bindings::HTMLFormControlsCollectionBinding; use crate::dom::bindings::codegen::Bindings::HTMLFormControlsCollectionBinding::HTMLFormControlsCollectionMethods; +use crate::dom::bindings::codegen::Bindings::NodeBinding::{GetRootNodeOptions, NodeMethods}; use crate::dom::bindings::codegen::UnionTypes::RadioNodeListOrElement; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; -use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::DOMString; use crate::dom::element::Element; use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection}; @@ -21,25 +22,30 @@ use dom_struct::dom_struct; #[dom_struct] pub struct HTMLFormControlsCollection { collection: HTMLCollection, + form: Dom, } impl HTMLFormControlsCollection { fn new_inherited( - root: &HTMLFormElement, + form: &HTMLFormElement, filter: Box, ) -> HTMLFormControlsCollection { + let root_of_form = form + .upcast::() + .GetRootNode(&GetRootNodeOptions::empty()); HTMLFormControlsCollection { - collection: HTMLCollection::new_inherited(root.upcast::(), filter), + collection: HTMLCollection::new_inherited(&*root_of_form, filter), + form: Dom::from_ref(form), } } pub fn new( window: &Window, - root: &HTMLFormElement, + form: &HTMLFormElement, filter: Box, ) -> DomRoot { reflect_dom_object( - Box::new(HTMLFormControlsCollection::new_inherited(root, filter)), + Box::new(HTMLFormControlsCollection::new_inherited(form, filter)), window, HTMLFormControlsCollectionBinding::Wrap, ) @@ -80,14 +86,11 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection { // Step 4-5 let global = self.global(); let window = global.as_window(); - // okay to unwrap: root's type was checked in the constructor - let collection_root = self.collection.root_node(); - let form = collection_root.downcast::().unwrap(); // There is only one way to get an HTMLCollection, // specifically HTMLFormElement::Elements(), // and the collection filter excludes image inputs. Some(RadioNodeListOrElement::RadioNodeList( - RadioNodeList::new_controls_except_image_inputs(window, form, name), + RadioNodeList::new_controls_except_image_inputs(window, &*self.form, name), )) } // Step 3 diff --git a/tests/wpt/metadata/html/semantics/forms/the-form-element/form-elements-filter.html.ini b/tests/wpt/metadata/html/semantics/forms/the-form-element/form-elements-filter.html.ini index d64290800cc..027f41382ba 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-form-element/form-elements-filter.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-form-element/form-elements-filter.html.ini @@ -1,8 +1,5 @@ [form-elements-filter.html] type: testharness - [form.elements must contain all listed elements with the form owner] - expected: FAIL - [form.elements only includes elements from the same shadow tree] expected: FAIL