#[js(global_this)]

Use #[js(global_this)] for access to the JavaScript globalThis object:

use ferrosaur::js;
// use it on a unit struct:
#[js(global_this)]
struct Global;
// (struct name does not need to be `Global`)

Call the new method to initialize it:

use ferrosaur::js;

#[path = "../../../crates/ferrosaur/tests/fixture/mod.rs"]
mod fixture;
use fixture::items::global::Global;

let rt = &mut fixture::deno()?;

// let rt: &mut JsRuntime;
let global = Global::new(rt);

Ok::<_, anyhow::Error>(())

After this, you can use #[js(interface)] to further derive access to properties, functions, and more, on globalThis:

use ferrosaur::js;

#[path = "../../../crates/ferrosaur/tests/fixture/mod.rs"]
mod fixture;
use fixture::items::global::Global;

#[js(interface)]
impl Global {
    #[js(func)]
    fn atob(&self, to_decode: String) -> String {}
}

Ok::<_, anyhow::Error>(())

The atob function.

Derived APIs

Methods

pub fn new(rt: &mut JsRuntime) -> Self

Create a handle to the globalThis object from the given JsRuntime.

Trait implementations

impl AsRef<v8::Global<v8::Object>> for Global

impl<'a> ToV8<'a> for Global

impl<'a> ToV8<'a> for &'_ Global