1use std::mem::MaybeUninit;
2
3use super::{
4 bindings as napi,
5 raw::{Env, Local},
6};
7
8pub unsafe fn new(env: Env, value: Local) -> napi::Ref {
9 let mut result = MaybeUninit::uninit();
10
11 napi::create_reference(env, value, 1, result.as_mut_ptr()).unwrap();
12
13 result.assume_init()
14}
15
16pub unsafe fn reference(env: Env, value: napi::Ref) -> usize {
19 let mut result = MaybeUninit::uninit();
20
21 napi::reference_ref(env, value, result.as_mut_ptr()).unwrap();
22
23 result.assume_init() as usize
24}
25
26pub unsafe fn unreference(env: Env, value: napi::Ref) {
29 let mut result = MaybeUninit::uninit();
30
31 napi::reference_unref(env, value, result.as_mut_ptr()).unwrap();
32
33 if result.assume_init() == 0 {
34 napi::delete_reference(env, value).unwrap();
35 }
36}
37
38pub unsafe fn get(env: Env, value: napi::Ref) -> Local {
41 let mut result = MaybeUninit::uninit();
42
43 napi::get_reference_value(env, value, result.as_mut_ptr()).unwrap();
44
45 result.assume_init()
46}