mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-18 23:41:24 +00:00
Add a top-level web_sys::window
function
Returns `Option<Window>` and can be used as a convenience to get a handle to the global `window` object.
This commit is contained in:
@ -17,4 +17,15 @@ extern crate wasm_bindgen;
|
||||
extern crate js_sys;
|
||||
use js_sys::Object;
|
||||
|
||||
#[cfg(feature = "Window")]
|
||||
pub fn window() -> Option<Window> {
|
||||
use wasm_bindgen::{JsValue, JsCast};
|
||||
|
||||
js_sys::Function::new_no_args("return this")
|
||||
.call0(&JsValue::undefined())
|
||||
.ok()?
|
||||
.dyn_into::<Window>()
|
||||
.ok()
|
||||
}
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
Reference in New Issue
Block a user