summaryrefslogtreecommitdiff
path: root/test_napi/src/arraybuffer.rs
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2022-10-30 18:13:46 +0100
committerGitHub <noreply@github.com>2022-10-30 13:13:46 -0400
commit207dd8d111303f02b92d632ca00c165a657bc9c2 (patch)
tree270cd208e28351fa6ce8265aa63e9b299a613ac6 /test_napi/src/arraybuffer.rs
parent59ac110edd1f376bed7fa6bbdbe2ee09c266bf74 (diff)
fix(napi): fix is_detached_arraybuffer (#16478)
Diffstat (limited to 'test_napi/src/arraybuffer.rs')
-rw-r--r--test_napi/src/arraybuffer.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/test_napi/src/arraybuffer.rs b/test_napi/src/arraybuffer.rs
new file mode 100644
index 000000000..cf170e713
--- /dev/null
+++ b/test_napi/src/arraybuffer.rs
@@ -0,0 +1,36 @@
+// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+
+use napi_sys::Status::napi_ok;
+use napi_sys::*;
+use std::ptr;
+
+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())
+ };
+}