diff options
author | haturau <135221985+haturatu@users.noreply.github.com> | 2024-11-20 01:20:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 01:20:47 +0900 |
commit | 85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch) | |
tree | face0aecaac53e93ce2f23b53c48859bcf1a36ec /tests/napi/src | |
parent | 67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff) | |
parent | 186b52731c6bb326c4d32905c5e732d082e83465 (diff) |
Merge branch 'denoland:main' into main
Diffstat (limited to 'tests/napi/src')
-rw-r--r-- | tests/napi/src/async.rs | 2 | ||||
-rw-r--r-- | tests/napi/src/callback.rs | 30 | ||||
-rw-r--r-- | tests/napi/src/object.rs | 29 | ||||
-rw-r--r-- | tests/napi/src/tsfn.rs | 6 |
4 files changed, 64 insertions, 3 deletions
diff --git a/tests/napi/src/async.rs b/tests/napi/src/async.rs index 3d3827b51..367d2e9ef 100644 --- a/tests/napi/src/async.rs +++ b/tests/napi/src/async.rs @@ -95,7 +95,7 @@ extern "C" fn test_async_work( )); let mut baton = unsafe { Box::from_raw(baton_ptr as *mut Baton) }; baton.task = async_work; - Box::into_raw(baton); + let _ = Box::into_raw(baton); assert_napi_ok!(napi_queue_async_work(env, async_work)); ptr::null_mut() 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( diff --git a/tests/napi/src/object.rs b/tests/napi/src/object.rs index aa34133dc..9876f4dae 100644 --- a/tests/napi/src/object.rs +++ b/tests/napi/src/object.rs @@ -40,10 +40,39 @@ extern "C" fn test_object_get( obj } +extern "C" fn test_object_attr_property( + env: napi_env, + info: napi_callback_info, +) -> napi_value { + let (args, argc, _) = napi_get_callback_info!(env, info, 1); + assert_eq!(argc, 1); + + let obj = args[0]; + let mut property = napi_new_property!(env, "self", test_object_new); + property.attributes = PropertyAttributes::enumerable; + property.method = None; + property.value = obj; + let mut method_property = napi_new_property!(env, "method", test_object_new); + method_property.attributes = PropertyAttributes::enumerable; + let properties = &[property, method_property]; + assert_napi_ok!(napi_define_properties( + env, + obj, + properties.len(), + properties.as_ptr() + )); + obj +} + pub fn init(env: napi_env, exports: napi_value) { let properties = &[ napi_new_property!(env, "test_object_new", test_object_new), napi_new_property!(env, "test_object_get", test_object_get), + napi_new_property!( + env, + "test_object_attr_property", + test_object_attr_property + ), ]; assert_napi_ok!(napi_define_properties( diff --git a/tests/napi/src/tsfn.rs b/tests/napi/src/tsfn.rs index dabc96f83..a3a231cec 100644 --- a/tests/napi/src/tsfn.rs +++ b/tests/napi/src/tsfn.rs @@ -46,6 +46,7 @@ fn create_custom_gc(env: sys::napi_env) { "Create async resource string in napi_register_module_v1 napi_register_module_v1" ); let mut custom_gc_tsfn = ptr::null_mut(); + let context = Box::into_raw(Box::new(0)) as *mut c_void; check_status_or_panic!( unsafe { sys::napi_create_threadsafe_function( @@ -57,7 +58,7 @@ fn create_custom_gc(env: sys::napi_env) { 1, ptr::null_mut(), Some(custom_gc_finalize), - ptr::null_mut(), + context, Some(custom_gc), &mut custom_gc_tsfn, ) @@ -80,8 +81,9 @@ unsafe extern "C" fn empty( unsafe extern "C" fn custom_gc_finalize( _env: sys::napi_env, _finalize_data: *mut c_void, - _finalize_hint: *mut c_void, + finalize_hint: *mut c_void, ) { + let _ = Box::from_raw(finalize_hint as *mut i32); } extern "C" fn custom_gc( |