-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjs.rs
35 lines (27 loc) · 827 Bytes
/
js.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Bindings to the JS API.
use once_cell::unsync::Lazy;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::{JsCast, JsValue};
#[wasm_bindgen]
extern "C" {
type Global;
#[wasm_bindgen(method, getter)]
fn performance(this: &Global) -> JsValue;
pub(super) type Performance;
#[wasm_bindgen(method)]
pub(super) fn now(this: &Performance) -> f64;
#[cfg(target_feature = "atomics")]
#[wasm_bindgen(method, getter, js_name = timeOrigin)]
pub(super) fn time_origin(this: &Performance) -> f64;
}
thread_local! {
pub(super) static PERFORMANCE: Lazy<Performance> = Lazy::new(|| {
let global: Global = js_sys::global().unchecked_into();
let performance = global.performance();
if performance.is_undefined() {
panic!("`Performance` object not found")
} else {
performance.unchecked_into()
}
});
}