diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm.rs | 21 |
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 |