nodex_api/value/
global.rs

1use crate::{api, prelude::*};
2
3#[derive(Copy, Clone, Debug)]
4pub struct JsGlobal(pub(crate) JsValue);
5
6impl JsGlobal {
7    pub(crate) fn from_value(value: JsValue) -> JsGlobal {
8        JsGlobal(value)
9    }
10
11    /// This API returns the global object.
12    pub fn new(env: NapiEnv) -> NapiResult<JsGlobal> {
13        let value = napi_call!(=napi_get_global, env);
14        Ok(JsGlobal(JsValue::from_raw(env, value)))
15    }
16
17    /// Global is always a `JsObject`
18    pub fn object(&self) -> JsObject {
19        unsafe { self.cast() }
20    }
21}
22
23napi_value_t!(JsGlobal);
24
25impl NapiValueCheck for JsGlobal {
26    fn check(&self) -> NapiResult<bool> {
27        // FIXME: global check
28        Ok(self.kind()? == NapiValuetype::Object)
29    }
30}