From 5aa662437baa51513aa7371d3ba9c3d7a7ee2458 Mon Sep 17 00:00:00 2001 From: Narfinger Date: Sat, 22 Feb 2025 10:42:16 +0100 Subject: [PATCH] Use counter instead of time for HTMLFormElement. (#35555) * Use counter instead of time for HTMLFormElement. Fixes #25455 Signed-off-by: Narfinger * Update components/script/dom/htmlformelement.rs to include suggestions Co-authored-by: Martin Robinson Signed-off-by: Narfinger --------- Signed-off-by: Narfinger Co-authored-by: Martin Robinson --- components/script/dom/htmlformelement.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index d2151881cc0..dfd264dd5ad 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -4,7 +4,6 @@ use std::borrow::ToOwned; use std::cell::Cell; -use std::time::{Duration, Instant}; use dom_struct::dom_struct; use encoding_rs::{Encoding, UTF_8}; @@ -97,7 +96,10 @@ pub(crate) struct HTMLFormElement { controls: DomRefCell>>, #[allow(clippy::type_complexity)] - past_names_map: DomRefCell, NoTrace)>>, + past_names_map: DomRefCell, NoTrace)>>, + + /// The current generation of past names, i.e., the number of name changes to the name. + current_name_generation: Cell, firing_submission_events: Cell, rel_list: MutNullableDom, @@ -125,6 +127,7 @@ impl HTMLFormElement { generation_id: Cell::new(GenerationId(0)), controls: DomRefCell::new(Vec::new()), past_names_map: DomRefCell::new(HashMapTracedValues::new()), + current_name_generation: Cell::new(0), firing_submission_events: Cell::new(false), rel_list: Default::default(), relations: Cell::new(LinkRelations::empty()), @@ -475,9 +478,11 @@ impl HTMLFormElementMethods for HTMLFormElement { name, ( Dom::from_ref(element_node.downcast::().unwrap()), - NoTrace(Instant::now()), + NoTrace(self.current_name_generation.get() + 1), ), ); + self.current_name_generation + .set(self.current_name_generation.get() + 1); // Step 6 Some(RadioNodeListOrElement::Element(DomRoot::from_ref( @@ -515,7 +520,7 @@ impl HTMLFormElementMethods for HTMLFormElement { enum SourcedNameSource { Id, Name, - Past(Duration), + Past(usize), } impl SourcedNameSource { @@ -587,7 +592,7 @@ impl HTMLFormElementMethods for HTMLFormElement { let entry = SourcedName { name: key.clone(), element: DomRoot::from_ref(&*val.0), - source: SourcedNameSource::Past(Instant::now().duration_since(val.1 .0)), + source: SourcedNameSource::Past(self.current_name_generation.get() - val.1 .0), }; sourced_names_vec.push(entry); }