aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/file.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-09-11 00:09:56 -0700
committerGitHub <noreply@github.com>2024-09-11 07:09:56 +0000
commitbc8d8b62c3017dbdb413a636b80bc3a2df0172d6 (patch)
tree2f4de6402a0bfc56af023b4611bfe14fc59f8fa8 /components/script/dom/file.rs
parent095590e2247517cf22e4aea7956f341a9a38b206 (diff)
downloadservo-bc8d8b62c3017dbdb413a636b80bc3a2df0172d6.tar.gz
servo-bc8d8b62c3017dbdb413a636b80bc3a2df0172d6.zip
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>
Diffstat (limited to 'components/script/dom/file.rs')
-rw-r--r--components/script/dom/file.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs
index 52c21b110ce..863fbf9059e 100644
--- a/components/script/dom/file.rs
+++ b/components/script/dom/file.rs
@@ -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
}
}