aboutsummaryrefslogtreecommitdiff
path: root/src/wasm.rs
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-11-19 17:08:55 -0800
committerJeff Vander Stoep <jeffv@google.com>2021-01-15 15:52:38 +0100
commitebac46102a63413e1bbbfea012e7f440a9dc8109 (patch)
tree41e7124f4626606cc15fd54021a363b804b92ce5 /src/wasm.rs
parent07ca6a2126c86ce00608a119b940558a407fc068 (diff)
downloadinstant-ebac46102a63413e1bbbfea012e7f440a9dc8109.tar.gz
Upgrade rust/crates/instant to 0.1.9platform-tools-31.0.0
Test: make Change-Id: Ic84c8d65797c8dc71e17ab4f04e2dc6d4d52e889
Diffstat (limited to 'src/wasm.rs')
-rw-r--r--src/wasm.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/wasm.rs b/src/wasm.rs
index 829ef3b..986bbf6 100644
--- a/src/wasm.rs
+++ b/src/wasm.rs
@@ -101,18 +101,27 @@ pub fn now() -> f64 {
use stdweb::unstable::TryInto;
// https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
+ #[cfg(not(feature = "inaccurate"))]
let v = js! { return performance.now(); };
+ #[cfg(feature = "inaccurate")]
+ let v = js! { return Date.now(); };
v.try_into().unwrap()
}
#[cfg(feature = "wasm-bindgen")]
pub fn now() -> f64 {
- use wasm_bindgen_rs::prelude::*;
- use wasm_bindgen_rs::JsCast;
- js_sys::Reflect::get(&js_sys::global(), &JsValue::from_str("performance"))
- .expect("failed to get performance from global object")
- .unchecked_into::<web_sys::Performance>()
- .now()
+ #[cfg(not(feature = "inaccurate"))]
+ let now = {
+ use wasm_bindgen_rs::prelude::*;
+ use wasm_bindgen_rs::JsCast;
+ js_sys::Reflect::get(&js_sys::global(), &JsValue::from_str("performance"))
+ .expect("failed to get performance from global object")
+ .unchecked_into::<web_sys::Performance>()
+ .now()
+ };
+ #[cfg(feature = "inaccurate")]
+ let now = js_sys::Date::now();
+ now
}
// The JS now function is in a module so it won't have to be renamed