napi/bindgen_runtime/
env.rs1use crate::{sys, JsGlobal, Result};
2
3use super::Array;
4
5pub use crate::Env;
6
7impl Env {
8 pub fn create_array(&self, len: u32) -> Result<Array<'_>> {
9 Array::new(self.0, len)
10 }
11
12 pub fn get_global(&self) -> Result<JsGlobal<'static>> {
13 let mut global = std::ptr::null_mut();
14 crate::check_status!(
15 unsafe { sys::napi_get_global(self.0, &mut global) },
16 "Get global object from Env failed"
17 )?;
18 Ok(JsGlobal(
19 crate::Value {
20 value: global,
21 env: self.0,
22 value_type: crate::ValueType::Object,
23 },
24 std::marker::PhantomData,
25 ))
26 }
27}