Stop using time@0.1 in Servo (#33394)

This removes the last few uses of `time@0.1` in Servo. There are still
dependencies from `style` and `webrender`, but they will be removed soon
as well. The uses of this version of `time` are replaced with
`std::time` types and `time@0.3` when negative `Duration` is necessary.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-09-11 00:09:56 -07:00 committed by GitHub
parent 095590e224
commit bc8d8b62c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 88 additions and 103 deletions

View file

@ -2,10 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::time::SystemTime;
use dom_struct::dom_struct;
use js::rust::HandleObject;
use net_traits::filemanager_thread::SelectedFile;
use script_traits::serializable::BlobImpl;
use time_03::{Duration, OffsetDateTime};
use crate::dom::bindings::codegen::Bindings::FileBinding;
use crate::dom::bindings::codegen::Bindings::FileBinding::FileMethods;
@ -24,23 +27,17 @@ use crate::script_runtime::CanGc;
pub struct File {
blob: Blob,
name: DOMString,
modified: i64,
modified: SystemTime,
}
impl File {
#[allow(crown::unrooted_must_root)]
fn new_inherited(blob_impl: &BlobImpl, name: DOMString, modified: Option<i64>) -> File {
fn new_inherited(blob_impl: &BlobImpl, name: DOMString, modified: Option<SystemTime>) -> File {
File {
blob: Blob::new_inherited(blob_impl),
name,
// https://w3c.github.io/FileAPI/#dfn-lastModified
modified: match modified {
Some(m) => m,
None => {
let time = time::get_time();
time.sec * 1000 + (time.nsec / 1000000) as i64
},
},
modified: modified.unwrap_or_else(SystemTime::now).into(),
}
}
@ -48,7 +45,7 @@ impl File {
global: &GlobalScope,
blob_impl: BlobImpl,
name: DOMString,
modified: Option<i64>,
modified: Option<SystemTime>,
) -> DomRoot<File> {
Self::new_with_proto(global, None, blob_impl, name, modified, CanGc::note())
}
@ -59,7 +56,7 @@ impl File {
proto: Option<HandleObject>,
blob_impl: BlobImpl,
name: DOMString,
modified: Option<i64>,
modified: Option<SystemTime>,
can_gc: CanGc,
) -> DomRoot<File> {
let file = reflect_dom_object_with_proto(
@ -90,7 +87,7 @@ impl File {
normalize_type_string(&selected.type_string.to_string()),
),
name,
Some(selected.modified as i64),
Some(selected.modified.into()),
)
}
@ -110,8 +107,11 @@ impl File {
};
let blobPropertyBag = &filePropertyBag.parent;
let modified = filePropertyBag
.lastModified
.map(|modified| OffsetDateTime::UNIX_EPOCH + Duration::milliseconds(modified))
.map(Into::into);
let modified = filePropertyBag.lastModified;
// NOTE: Following behaviour might be removed in future,
// see https://github.com/w3c/FileAPI/issues/41
let replaced_filename = DOMString::from_string(filename.replace('/', ":"));
@ -139,6 +139,9 @@ impl FileMethods for File {
// https://w3c.github.io/FileAPI/#dfn-lastModified
fn LastModified(&self) -> i64 {
self.modified
// This is first converted to a `time::OffsetDateTime` because it might be from before the
// Unix epoch in which case we will need to return a negative duration to script.
(OffsetDateTime::from(self.modified) - OffsetDateTime::UNIX_EPOCH).whole_milliseconds()
as i64
}
}