Wrap all Node-API functions in neon-runtime to check status
Author: kjvalencikCreated Sep 24, 2021Updated Sep 10, 2024
Labelsbeginner friendlyrequires safe rust
Currently every usage of a Node-API function checks the status. This is almost always required for safety, but it's easy to fix.
Since all Node-API FFI bindings are defined in a macro and all functions return napi_status, we could wrap them to return Result<(), Status> instead and use the linter to ensure the Result is checked.
mod node_api {
extern "C" {
fn get_undefined(env: Env, result: *mut Value) -> Status;
}
}
pub unsafe fn get_undefined(env: Env, result: *mut Value) -> Result<(), Status> {
match node_api::get_undefined(env, result) {
Status::Ok => Ok(()),
status => Err(status),
}
}Source: neon-bindings/neon