feat(napi): allow create reference with refcount
This commit is contained in:
parent
1a2c692a1a
commit
fa23769e9d
1 changed files with 19 additions and 1 deletions
|
@ -809,7 +809,7 @@ impl Env {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This API create a new reference with the specified reference count to the Object passed in.
|
/// This API create a new reference with the initial 1 ref count to the Object passed in.
|
||||||
pub fn create_reference<T>(&self, value: T) -> Result<Ref<()>>
|
pub fn create_reference<T>(&self, value: T) -> Result<Ref<()>>
|
||||||
where
|
where
|
||||||
T: NapiRaw,
|
T: NapiRaw,
|
||||||
|
@ -828,6 +828,24 @@ impl Env {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This API create a new reference with the specified reference count to the Object passed in.
|
||||||
|
pub fn create_reference_with_refcount<T>(&self, value: T, ref_count: u32) -> Result<Ref<()>>
|
||||||
|
where
|
||||||
|
T: NapiRaw,
|
||||||
|
{
|
||||||
|
let mut raw_ref = ptr::null_mut();
|
||||||
|
let raw_value = unsafe { value.raw() };
|
||||||
|
check_status!(unsafe {
|
||||||
|
sys::napi_create_reference(self.0, raw_value, ref_count, &mut raw_ref)
|
||||||
|
})?;
|
||||||
|
Ok(Ref {
|
||||||
|
raw_ref,
|
||||||
|
count: ref_count,
|
||||||
|
inner: (),
|
||||||
|
raw_value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Get reference value from `Ref` with type check
|
/// Get reference value from `Ref` with type check
|
||||||
///
|
///
|
||||||
/// Return error if the type of `reference` provided is mismatched with `T`
|
/// Return error if the type of `reference` provided is mismatched with `T`
|
||||||
|
|
Loading…
Add table
Reference in a new issue