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>
This commit is contained in:
Auguste Baum 2024-01-16 13:23:18 +01:00 committed by GitHub
parent c06ae7faf2
commit 9654363c18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 61 deletions

View file

@ -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(