diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 2421b683bf7..00377fd8208 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -537,10 +537,8 @@ impl HTMLFormElementMethods for HTMLFormElement { let mut sourced_names_vec: Vec = Vec::new(); - let controls = self.controls.borrow(); - // Step 2 - for child in controls.iter() { + for child in self.controls.borrow().iter() { if child .downcast::() .is_some_and(|c| c.is_listed_element()) @@ -565,7 +563,7 @@ impl HTMLFormElementMethods for HTMLFormElement { } // Step 3 - for child in controls.iter() { + for child in self.controls.borrow().iter() { if child.is::() { if let Some(id_atom) = child.get_id() { let entry = SourcedName { @@ -713,8 +711,9 @@ impl HTMLFormElement { } pub(crate) fn update_validity(&self, can_gc: CanGc) { - let controls = self.controls.borrow(); - let is_any_invalid = controls + let is_any_invalid = self + .controls + .borrow() .iter() .any(|control| control.is_invalid(false, can_gc)); @@ -1084,9 +1083,10 @@ impl HTMLFormElement { /// Statitically validate the constraints of form elements /// fn static_validation(&self, can_gc: CanGc) -> Result<(), Vec>> { - let controls = self.controls.borrow(); // Step 1-3 - let invalid_controls = controls + let invalid_controls = self + .controls + .borrow() .iter() .filter_map(|field| { if let Some(element) = field.downcast::() { @@ -1131,9 +1131,8 @@ impl HTMLFormElement { encoding: Option<&'static Encoding>, can_gc: CanGc, ) -> Vec { - let controls = self.controls.borrow(); let mut data_set = Vec::new(); - for child in controls.iter() { + for child in self.controls.borrow().iter() { // Step 5.1: The field element is disabled. if child.disabled_state() { continue; diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index f5bd98a4e6c..f8c1e66bcbb 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -8241,6 +8241,13 @@ {} ] ], + "form-check-validity-crash.html": [ + "6d3bd0d2e36751c554af42164189d921975ced93", + [ + null, + {} + ] + ], "form-controls-id-removal-crash.html": [ "2b1ef87774fc1c5393129fca8e65147c379ea7a9", [ diff --git a/tests/wpt/tests/html/semantics/forms/the-form-element/form-check-validity-crash.html b/tests/wpt/tests/html/semantics/forms/the-form-element/form-check-validity-crash.html new file mode 100644 index 00000000000..6d3bd0d2e36 --- /dev/null +++ b/tests/wpt/tests/html/semantics/forms/the-form-element/form-check-validity-crash.html @@ -0,0 +1,8 @@ + +
+
+
+ +