2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-10-30 13:13:46 -04:00
|
|
|
|
|
|
|
use napi_sys::Status::napi_ok;
|
|
|
|
use napi_sys::*;
|
|
|
|
|
|
|
|
extern "C" fn test_detached(
|
|
|
|
env: napi_env,
|
|
|
|
info: napi_callback_info,
|
|
|
|
) -> napi_value {
|
|
|
|
let (args, argc, _) = crate::get_callback_info!(env, info, 1);
|
|
|
|
assert_eq!(argc, 1);
|
|
|
|
|
|
|
|
let mut value = false;
|
|
|
|
assert!(
|
|
|
|
unsafe { napi_is_detached_arraybuffer(env, args[0], &mut value) }
|
|
|
|
== napi_ok
|
|
|
|
);
|
|
|
|
assert!(!value);
|
|
|
|
assert!(unsafe { napi_detach_arraybuffer(env, args[0]) } == napi_ok);
|
|
|
|
assert!(
|
|
|
|
unsafe { napi_is_detached_arraybuffer(env, args[0], &mut value) }
|
|
|
|
== napi_ok
|
|
|
|
);
|
|
|
|
assert!(value);
|
|
|
|
args[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init(env: napi_env, exports: napi_value) {
|
|
|
|
let properties =
|
|
|
|
&[crate::new_property!(env, "test_detached\0", test_detached)];
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
napi_define_properties(env, exports, properties.len(), properties.as_ptr())
|
|
|
|
};
|
|
|
|
}
|