From 1dc9974c194b3e115df6f161cc8c5fddcbb8e10f Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sun, 11 Oct 2020 22:26:09 +0800 Subject: [PATCH] feat(napi): implement detach arraybuffer --- README.md | 4 ++-- napi/src/js_values/arraybuffer.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 20b75710..554cbec0 100644 --- a/README.md +++ b/README.md @@ -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 | ✅ | diff --git a/napi/src/js_values/arraybuffer.rs b/napi/src/js_values/arraybuffer.rs index f59faa27..a4538648 100644 --- a/napi/src/js_values/arraybuffer.rs +++ b/napi/src/js_values/arraybuffer.rs @@ -100,6 +100,20 @@ impl From 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 { + 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 { let mut data = ptr::null_mut(); let mut len: u64 = 0;