diff options
author | Auguste Baum <52001167+augustebaum@users.noreply.github.com> | 2024-01-16 13:23:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-16 12:23:18 +0000 |
commit | 9654363c187ee549b82bca8c4e3098e4c20c7287 (patch) | |
tree | 83744130e3842433d89e1011fadc0f6db172aa2b /components/script/dom/globalscope.rs | |
parent | c06ae7faf201e539a4cfbaefb6d5b8444796f472 (diff) | |
download | servo-9654363c187ee549b82bca8c4e3098e4c20c7287.tar.gz servo-9654363c187ee549b82bca8c4e3098e4c20c7287.zip |
script: Start replacing `time` with `std::time` and `chrono` (#30639)
* Replace `time` with `chrono` in `script/animation_timeline`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/script_thread.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` and `chrono` in `script/script_thread.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/script_runtime.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/script_runtime.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/dom/workerglobalscope.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `chrono` in `script/dom/workerglobalscope.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/dom/htmlmedialelement.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/dom/htmlmedialelement.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/dom/globalscope.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `chrono` in `script/dom/globalscope.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/dom/htmlformelement.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* Replace `time` with `std::time` in `script/dom/htmlformelement.rs`
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
* 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 <auguste.apple@gmail.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r-- | components/script/dom/globalscope.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 6a1467d7076..c78d24c7e8f 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -11,6 +11,7 @@ use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::thread::JoinHandle; +use std::time::Instant; use std::{mem, ptr}; use content_security_policy::CspList; @@ -54,7 +55,6 @@ use script_traits::{ ScriptToConstellationChan, TimerEvent, TimerEventId, TimerSchedulerMsg, TimerSource, }; use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl}; -use time::{get_time, Timespec}; use uuid::Uuid; use webgpu::identity::WebGPUOpResult; use webgpu::{ErrorScopeId, WebGPUDevice}; @@ -203,8 +203,8 @@ pub struct GlobalScope { /// live updates from the worker. devtools_wants_updates: Cell<bool>, - /// Timers used by the Console API. - console_timers: DomRefCell<HashMap<DOMString, u64>>, + /// Timers (milliseconds) used by the Console API. + console_timers: DomRefCell<HashMap<DOMString, Instant>>, /// module map is used when importing JavaScript modules /// https://html.spec.whatwg.org/multipage/#concept-settings-object-module-map @@ -2262,7 +2262,7 @@ impl GlobalScope { } match timers.entry(label) { Entry::Vacant(entry) => { - entry.insert(timestamp_in_ms(get_time())); + entry.insert(Instant::now()); Ok(()) }, Entry::Occupied(_) => Err(()), @@ -2274,7 +2274,7 @@ impl GlobalScope { .borrow_mut() .remove(label) .ok_or(()) - .map(|start| timestamp_in_ms(get_time()) - start) + .map(|start| (Instant::now() - start).as_millis() as u64) } /// Get an `&IpcSender<ScriptToDevtoolsControlMsg>` to send messages @@ -3111,10 +3111,6 @@ impl GlobalScope { } } -fn timestamp_in_ms(time: Timespec) -> u64 { - (time.sec * 1000 + (time.nsec / 1000000) as i64) as u64 -} - /// Returns the Rust global scope from a JS global object. #[allow(unsafe_code)] unsafe fn global_scope_from_global( |