diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-05-26 07:02:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-26 05:02:12 +0000 |
commit | e95f098ae350f17450d06270ce37032688447f96 (patch) | |
tree | 4e84e684fd0d0d0d25037cc196841cdccde7f66f /cli/napi/js_native_api.rs | |
parent | 512d5337c480a2a2704881d3fe1c40b6e0445cf0 (diff) |
fix(napi): properly handle arguments in napi_get_cb_info (#19269)
Closes https://github.com/denoland/deno/issues/17213
Diffstat (limited to 'cli/napi/js_native_api.rs')
-rw-r--r-- | cli/napi/js_native_api.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/cli/napi/js_native_api.rs b/cli/napi/js_native_api.rs index b18950403..ed8aacb47 100644 --- a/cli/napi/js_native_api.rs +++ b/cli/napi/js_native_api.rs @@ -1758,7 +1758,7 @@ fn napi_get_cb_info( argc: *mut i32, argv: *mut napi_value, this_arg: *mut napi_value, - cb_data: *mut *mut c_void, + data: *mut *mut c_void, ) -> napi_status { check_env!(env); let env = unsafe { &mut *env }; @@ -1767,8 +1767,17 @@ fn napi_get_cb_info( let cbinfo: &CallbackInfo = &*(cbinfo as *const CallbackInfo); let args = &*(cbinfo.args as *const v8::FunctionCallbackArguments); - if !cb_data.is_null() { - *cb_data = cbinfo.cb_info; + if !argv.is_null() { + check_arg!(env, argc); + let mut v_argv = std::slice::from_raw_parts_mut(argv, argc as usize); + for i in 0..*argc { + let mut arg = args.get(i); + v_argv[i as usize] = arg.into(); + } + } + + if !argc.is_null() { + *argc = args.length(); } if !this_arg.is_null() { @@ -1776,20 +1785,11 @@ fn napi_get_cb_info( *this_arg = this.into(); } - let len = args.length(); - let mut v_argc = len; - if !argc.is_null() { - *argc = len; - } - - if !argv.is_null() { - let mut v_argv = std::slice::from_raw_parts_mut(argv, v_argc as usize); - for i in 0..v_argc { - let mut arg = args.get(i); - v_argv[i as usize] = arg.into(); - } + if !data.is_null() { + *data = cbinfo.cb_info; } + napi_clear_last_error(env); napi_ok } |