summaryrefslogtreecommitdiff
path: root/tests/napi/src/callback.rs
diff options
context:
space:
mode:
authorhaturau <135221985+haturatu@users.noreply.github.com>2024-11-20 01:20:47 +0900
committerGitHub <noreply@github.com>2024-11-20 01:20:47 +0900
commit85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch)
treeface0aecaac53e93ce2f23b53c48859bcf1a36ec /tests/napi/src/callback.rs
parent67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff)
parent186b52731c6bb326c4d32905c5e732d082e83465 (diff)
Merge branch 'denoland:main' into main
Diffstat (limited to 'tests/napi/src/callback.rs')
-rw-r--r--tests/napi/src/callback.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/napi/src/callback.rs b/tests/napi/src/callback.rs
index 8909f5176..2512f6a38 100644
--- a/tests/napi/src/callback.rs
+++ b/tests/napi/src/callback.rs
@@ -8,6 +8,7 @@ use napi_sys::ValueType::napi_object;
use napi_sys::ValueType::napi_undefined;
use napi_sys::*;
use std::ptr;
+use Status::napi_pending_exception;
/// `test_callback_run((a, b) => a + b, [1, 2])` => 3
extern "C" fn test_callback_run(
@@ -98,6 +99,34 @@ extern "C" fn test_callback_run_with_recv(
result
}
+extern "C" fn test_callback_throws(
+ env: napi_env,
+ info: napi_callback_info,
+) -> napi_value {
+ let (args, ..) = napi_get_callback_info!(env, info, 1);
+
+ let mut global: napi_value = ptr::null_mut();
+ assert_napi_ok!(napi_get_global(env, &mut global));
+
+ let mut argv = vec![];
+ let mut result: napi_value = ptr::null_mut();
+ assert_eq!(
+ unsafe {
+ napi_call_function(
+ env,
+ global, // recv
+ args[0], // cb
+ argv.len(),
+ argv.as_mut_ptr(),
+ &mut result,
+ )
+ },
+ napi_pending_exception
+ );
+
+ result
+}
+
pub fn init(env: napi_env, exports: napi_value) {
let properties = &[
napi_new_property!(env, "test_callback_run", test_callback_run),
@@ -106,6 +135,7 @@ pub fn init(env: napi_env, exports: napi_value) {
"test_callback_run_with_recv",
test_callback_run_with_recv
),
+ napi_new_property!(env, "test_callback_throws", test_callback_throws),
];
assert_napi_ok!(napi_define_properties(