1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(napi): improve napi_detach_arraybuffer (#17499)

This commit is contained in:
Divy Srivastava 2023-01-23 00:51:55 -08:00 committed by GitHub
parent c3e3694b9d
commit 2e1df62380
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1497,10 +1497,21 @@ fn napi_delete_reference(env: *mut Env, _nref: napi_ref) -> Result {
}
#[napi_sym::napi_sym]
fn napi_detach_arraybuffer(_env: *mut Env, value: napi_value) -> Result {
fn napi_detach_arraybuffer(env: *mut Env, value: napi_value) -> Result {
check_env!(env);
let value = napi_value_unchecked(value);
let ab = v8::Local::<v8::ArrayBuffer>::try_from(value).unwrap();
ab.detach(None);
let ab = v8::Local::<v8::ArrayBuffer>::try_from(value)
.map_err(|_| Error::ArrayBufferExpected)?;
if !ab.is_detachable() {
return Err(Error::DetachableArraybufferExpected);
}
// Expected to crash for None.
ab.detach(None).unwrap();
napi_clear_last_error(env);
Ok(())
}