diff --git a/crates/macro/src/lib.rs b/crates/macro/src/lib.rs index 21b8241b..118e02f7 100644 --- a/crates/macro/src/lib.rs +++ b/crates/macro/src/lib.rs @@ -326,12 +326,12 @@ fn replace_napi_attr_in_mod( #[napi(namespace = #js_namespace)] ) }; - let struct_opts: BindgenAttrs; - if let Some(TokenTree::Group(g)) = new_attr.tokens.into_iter().next() { - struct_opts = syn::parse2(g.stream()).ok()?; - } else { - struct_opts = syn::parse2(quote! {}).ok()?; - } + let struct_opts: BindgenAttrs = + if let Some(TokenTree::Group(g)) = new_attr.tokens.into_iter().next() { + syn::parse2(g.stream()).ok()? + } else { + syn::parse2(quote! {}).ok()? + }; attrs.remove(index); Some(struct_opts) } else { diff --git a/crates/napi/src/threadsafe_function.rs b/crates/napi/src/threadsafe_function.rs index 7f87d2fc..4a0848c5 100644 --- a/crates/napi/src/threadsafe_function.rs +++ b/crates/napi/src/threadsafe_function.rs @@ -373,12 +373,10 @@ unsafe extern "C" fn call_js_cb( }) }); - let status; - // Follow async callback conventions: https://nodejs.org/en/knowledge/errors/what-are-the-error-conventions/ // Check if the Result is okay, if so, pass a null as the first (error) argument automatically. // If the Result is an error, pass that as the first argument. - match ret { + let status = match ret { Ok(values) => { let values = values.iter().map(|v| unsafe { v.raw() }); let args: Vec = if ES::VALUE == ErrorStrategy::CalleeHandled::VALUE { @@ -388,7 +386,7 @@ unsafe extern "C" fn call_js_cb( } else { values.collect() }; - status = unsafe { + unsafe { sys::napi_call_function( raw_env, recv, @@ -397,24 +395,22 @@ unsafe extern "C" fn call_js_cb( args.as_ptr(), ptr::null_mut(), ) - }; + } } - Err(e) if ES::VALUE == ErrorStrategy::Fatal::VALUE => { - status = unsafe { sys::napi_fatal_exception(raw_env, JsError::from(e).into_value(raw_env)) }; - } - Err(e) => { - status = unsafe { - sys::napi_call_function( - raw_env, - recv, - js_callback, - 1, - [JsError::from(e).into_value(raw_env)].as_mut_ptr(), - ptr::null_mut(), - ) - }; - } - } + Err(e) if ES::VALUE == ErrorStrategy::Fatal::VALUE => unsafe { + sys::napi_fatal_exception(raw_env, JsError::from(e).into_value(raw_env)) + }, + Err(e) => unsafe { + sys::napi_call_function( + raw_env, + recv, + js_callback, + 1, + [JsError::from(e).into_value(raw_env)].as_mut_ptr(), + ptr::null_mut(), + ) + }, + }; if status == sys::Status::napi_ok { return; }