mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
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:
parent
095590e224
commit
bc8d8b62c3
18 changed files with 88 additions and 103 deletions
|
@ -17,6 +17,7 @@ use std::time::{Duration, Instant};
|
|||
use base::cross_process_instant::CrossProcessInstant;
|
||||
use base::id::BrowsingContextId;
|
||||
use canvas_traits::webgl::{self, WebGLContextId, WebGLMsg};
|
||||
use chrono::Local;
|
||||
use content_security_policy::{self as csp, CspList};
|
||||
use cookie::Cookie;
|
||||
use cssparser::match_ignore_ascii_case;
|
||||
|
@ -4625,15 +4626,14 @@ impl DocumentMethods for Document {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-document-lastmodified
|
||||
fn LastModified(&self) -> DOMString {
|
||||
match self.last_modified {
|
||||
Some(ref t) => DOMString::from(t.clone()),
|
||||
None => DOMString::from(
|
||||
time::now()
|
||||
.strftime("%m/%d/%Y %H:%M:%S")
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
),
|
||||
}
|
||||
DOMString::from(self.last_modified.as_ref().cloned().unwrap_or_else(|| {
|
||||
// Ideally this would get the local time using `time`, but `time` always fails to get the local
|
||||
// timezone on Unix unless the application is single threaded unless the library is explicitly
|
||||
// set to "unsound" mode. Maybe that's fine, but it needs more investigation. see
|
||||
// https://nvd.nist.gov/vuln/detail/CVE-2020-26235
|
||||
// When `time` supports a thread-safe way of getting the local time zone we could use it here.
|
||||
Local::now().format("%m/%d/%Y %H:%M:%S").to_string()
|
||||
}))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-createrange
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue