mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(napi): improve napi_detach_arraybuffer (#17499)
This commit is contained in:
parent
c3e3694b9d
commit
2e1df62380
1 changed files with 14 additions and 3 deletions
|
@ -1497,10 +1497,21 @@ fn napi_delete_reference(env: *mut Env, _nref: napi_ref) -> Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi_sym::napi_sym]
|
#[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 value = napi_value_unchecked(value);
|
||||||
let ab = v8::Local::<v8::ArrayBuffer>::try_from(value).unwrap();
|
let ab = v8::Local::<v8::ArrayBuffer>::try_from(value)
|
||||||
ab.detach(None);
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue