Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(neon): fix clippy lints #1085

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/neon/src/sys/async_work.rs
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ pub unsafe fn schedule<I, O, D>(
Ok(()) => {}
status => {
// If queueing failed, delete the work to prevent a leak
napi::delete_async_work(env, *work);
let _ = napi::delete_async_work(env, *work);
status.unwrap()
}
}
@@ -150,7 +150,7 @@ unsafe extern "C" fn call_complete<I, O, D>(env: Env, status: napi::Status, data
..
} = *Box::<Data<I, O, D>>::from_raw(data.cast());

napi::delete_async_work(env, work);
debug_assert_eq!(napi::delete_async_work(env, work), Ok(()));

BOUNDARY.catch_failure(env, None, move |env| {
// `unwrap` is okay because `call_complete` should be called exactly once
33 changes: 14 additions & 19 deletions crates/neon/src/sys/no_panic.rs
Original file line number Diff line number Diff line change
@@ -235,9 +235,8 @@ unsafe fn error_from_panic(env: Env, panic: Panic) -> Local {
unsafe fn set_property(env: Env, object: Local, key: &str, value: Local) {
let key = create_string(env, key);

match napi::set_property(env, object, key, value) {
Err(_) => fatal_error("Failed to set an object property"),
Ok(()) => (),
if napi::set_property(env, object, key, value).is_err() {
fatal_error("Failed to set an object property");
}
}

@@ -255,25 +254,24 @@ unsafe fn panic_msg(panic: &Panic) -> Option<&str> {
unsafe fn external_from_panic(env: Env, panic: Panic) -> Local {
let fail = || fatal_error("Failed to create a neon::types::JsBox from a panic");
let mut result = MaybeUninit::uninit();
let status = napi::create_external(

if napi::create_external(
env,
Box::into_raw(Box::new(DebugSendWrapper::new(panic))).cast(),
Some(finalize_panic),
ptr::null_mut(),
result.as_mut_ptr(),
);

match status {
Ok(()) => (),
Err(_) => fail(),
)
.is_err()
{
fail();
}

let external = result.assume_init();

#[cfg(feature = "napi-8")]
match napi::type_tag_object(env, external, &*crate::MODULE_TAG) {
Err(_) => fail(),
Ok(()) => (),
if napi::type_tag_object(env, external, &*crate::MODULE_TAG).is_err() {
fail();
}

external
@@ -288,11 +286,9 @@ extern "C" fn finalize_panic(_env: Env, data: *mut c_void, _hint: *mut c_void) {
#[track_caller]
unsafe fn create_string(env: Env, msg: &str) -> Local {
let mut string = MaybeUninit::uninit();
let status = napi::create_string_utf8(env, msg.as_ptr().cast(), msg.len(), string.as_mut_ptr());

match status {
Err(_) => fatal_error("Failed to create a String"),
Ok(()) => (),
if napi::create_string_utf8(env, msg.as_ptr().cast(), msg.len(), string.as_mut_ptr()).is_err() {
fatal_error("Failed to create a String");
}

string.assume_init()
@@ -301,9 +297,8 @@ unsafe fn create_string(env: Env, msg: &str) -> Local {
unsafe fn is_exception_pending(env: Env) -> bool {
let mut throwing = false;

match napi::is_exception_pending(env, &mut throwing) {
Err(_) => fatal_error("Failed to check if an exception is pending"),
Ok(()) => (),
if napi::is_exception_pending(env, &mut throwing).is_err() {
fatal_error("Failed to check if an exception is pending");
}

throwing
22 changes: 11 additions & 11 deletions crates/neon/src/sys/object.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use super::{

/// Mutates the `out` argument to refer to a `napi_value` containing a newly created JavaScript Object.
pub unsafe fn new(out: &mut Local, env: Env) {
napi::create_object(env, out as *mut _);
napi::create_object(env, out as *mut _).unwrap();
}

#[cfg(feature = "napi-8")]
@@ -39,8 +39,8 @@ pub unsafe fn get_own_property_names(out: &mut Local, env: Env, object: Local) -
napi::KeyConversion::NumbersToStrings,
property_names.as_mut_ptr(),
) {
Err(_) => return false,
Ok(()) => (),
Err(napi::Status::PendingException) => return false,
status => status.unwrap(),
}

*out = property_names.assume_init();
@@ -82,14 +82,14 @@ pub unsafe fn get_string(
// Not using `crate::string::new()` because it requires a _reference_ to a Local,
// while we only have uninitialized memory.
match napi::create_string_utf8(env, key as *const _, len as usize, key_val.as_mut_ptr()) {
Err(_) => return false,
Ok(()) => (),
Err(napi::Status::PendingException) => return false,
status => status.unwrap(),
}

// Not using napi_get_named_property() because the `key` may not be null terminated.
match napi::get_property(env, object, key_val.assume_init(), out as *mut _) {
Err(_) => return false,
Ok(()) => (),
Err(napi::Status::PendingException) => return false,
status => status.unwrap(),
}

true
@@ -114,19 +114,19 @@ pub unsafe fn set_string(
*out = true;

match napi::create_string_utf8(env, key as *const _, len as usize, key_val.as_mut_ptr()) {
Err(_) => {
Err(napi::Status::PendingException) => {
*out = false;
return false;
}
Ok(()) => (),
status => status.unwrap(),
}

match napi::set_property(env, object, key_val.assume_init(), val) {
Err(_) => {
Err(napi::Status::PendingException) => {
*out = false;
return false;
}
Ok(()) => (),
status => status.unwrap(),
}

true
2 changes: 1 addition & 1 deletion crates/neon/src/sys/reference.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ pub unsafe fn unreference(env: Env, value: napi::Ref) {
napi::reference_unref(env, value, result.as_mut_ptr()).unwrap();

if result.assume_init() == 0 {
assert_eq!(napi::delete_reference(env, value), Ok(()));
napi::delete_reference(env, value).unwrap();
}
}

2 changes: 1 addition & 1 deletion crates/neon/src/sys/tag.rs
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ pub unsafe fn is_object(env: Env, val: Local) -> bool {

pub unsafe fn is_array(env: Env, val: Local) -> bool {
let mut result = false;
assert_eq!(napi::is_array(env, val, &mut result as *mut _), Ok(()));
napi::is_array(env, val, &mut result as *mut _).unwrap();
result
}

9 changes: 6 additions & 3 deletions crates/neon/src/sys/tsfn.rs
Original file line number Diff line number Diff line change
@@ -182,9 +182,12 @@ impl<T> Drop for ThreadsafeFunction<T> {
}

unsafe {
napi::release_threadsafe_function(
self.tsfn.0,
napi::ThreadsafeFunctionReleaseMode::Release,
debug_assert_eq!(
napi::release_threadsafe_function(
self.tsfn.0,
napi::ThreadsafeFunctionReleaseMode::Release,
),
Ok(())
);
};
}