feat(napi): implement detach arraybuffer

This commit is contained in:
LongYinan 2020-10-11 22:26:09 +08:00
parent ef51a882c6
commit 1dc9974c19
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 16 additions and 2 deletions

View file

@ -223,5 +223,5 @@ yarn test
| [napi_is_typedarray](https://nodejs.org/api/n-api.html#n_api_napi_is_typedarray) | 1 | v8.0.0 | ✅ |
| [napi_is_dataview](https://nodejs.org/api/n-api.html#n_api_napi_is_dataview) | 1 | v8.3.0 | ✅ |
| [napi_strict_equals](https://nodejs.org/api/n-api.html#n_api_napi_strict_equals) | 1 | v8.0.0 | ✅ |
| [napi_detach_arraybuffer](https://nodejs.org/api/n-api.html#n_api_napi_detach_arraybuffer) | 7 | v13.3.0 | ⛔️ |
| [napi_is_detached_arraybuffer](https://nodejs.org/api/n-api.html#n_api_napi_is_detached_arraybuffer) | 7 | v13.3.0 | ⛔️ |
| [napi_detach_arraybuffer](https://nodejs.org/api/n-api.html#n_api_napi_detach_arraybuffer) | 7 | v13.3.0 | |
| [napi_is_detached_arraybuffer](https://nodejs.org/api/n-api.html#n_api_napi_is_detached_arraybuffer) | 7 | v13.3.0 | |

View file

@ -100,6 +100,20 @@ impl From<TypedArrayType> for sys::napi_typedarray_type {
}
impl JsArrayBuffer {
#[cfg(napi7)]
pub fn detach(self) -> Result<()> {
check_status(unsafe { sys::napi_detach_arraybuffer(self.0.env, self.0.value) })
}
#[cfg(napi7)]
pub fn is_detached(&self) -> Result<bool> {
let mut is_detached = false;
check_status(unsafe {
sys::napi_is_detached_arraybuffer(self.0.env, self.0.value, &mut is_detached)
})?;
Ok(is_detached)
}
pub fn into_value(self) -> Result<JsArrayBufferValue> {
let mut data = ptr::null_mut();
let mut len: u64 = 0;