From 9654363c187ee549b82bca8c4e3098e4c20c7287 Mon Sep 17 00:00:00 2001 From: Auguste Baum <52001167+augustebaum@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:23:18 +0100 Subject: script: Start replacing `time` with `std::time` and `chrono` (#30639) * Replace `time` with `chrono` in `script/animation_timeline` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/script_thread.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` and `chrono` in `script/script_thread.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/script_runtime.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/script_runtime.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/dom/workerglobalscope.rs` Signed-off-by: Auguste Baum * Replace `time` with `chrono` in `script/dom/workerglobalscope.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/dom/htmlmedialelement.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/dom/htmlmedialelement.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/dom/globalscope.rs` Signed-off-by: Auguste Baum * Replace `time` with `chrono` in `script/dom/globalscope.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/dom/htmlformelement.rs` Signed-off-by: Auguste Baum * Replace `time` with `std::time` in `script/dom/htmlformelement.rs` Signed-off-by: Auguste Baum * Increase precision of animation timeline * Some fixes Use Instant a bit more and stop using chrono. Do not transition `navigation_start_precise` to Instant yet as we need to coordinate this across all crates. --------- Signed-off-by: Auguste Baum Co-authored-by: Martin Robinson --- components/script/animation_timeline.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'components/script/animation_timeline.rs') diff --git a/components/script/animation_timeline.rs b/components/script/animation_timeline.rs index ea2a88af380..6cae2640cfa 100644 --- a/components/script/animation_timeline.rs +++ b/components/script/animation_timeline.rs @@ -7,8 +7,9 @@ //! A timeline module, used to specify an `AnimationTimeline` which determines //! the time used for synchronizing animations in the script thread. +use std::time::{SystemTime, UNIX_EPOCH}; + use jstraceable_derive::JSTraceable; -use time; /// A `AnimationTimeline` which is used to synchronize animations during the script /// event loop. @@ -22,7 +23,10 @@ impl AnimationTimeline { #[inline] pub fn new() -> Self { Self { - current_value: time::precise_time_s(), + current_value: SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_secs_f64(), } } @@ -39,7 +43,10 @@ impl AnimationTimeline { /// Updates the value of the `AnimationTimeline` to the current clock time. pub fn update(&mut self) { - self.current_value = time::precise_time_s(); + self.current_value = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_secs_f64(); } /// Increments the current value of the timeline by a specific number of seconds. -- cgit v1.2.3