fix(napi-derive-backend): wrong restrict on Result return type

This commit is contained in:
LongYinan 2021-11-10 13:15:54 +08:00
parent ea8a79e761
commit 413a55545f
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
3 changed files with 8 additions and 7 deletions

View file

@ -89,7 +89,7 @@ extern crate napi;
/// import the preludes
use napi::bindgen_prelude::*;
/// module registerion is done by the runtime, no need to explicitly do it now.
/// module registration is done by the runtime, no need to explicitly do it now.
#[napi]
fn fibonacci(n: u32) -> u32 {
match n {

View file

@ -2,6 +2,6 @@
"name": "test-module",
"version": "1.0.0",
"scripts": {
"build": "node ../cli/scripts/index.js build --release"
"build": "node ../cli/scripts/index.js build --js false --release"
}
}

View file

@ -262,11 +262,12 @@ impl NapiFn {
}
} else {
quote! {
if #ret.is_ok() {
<Result<#ty> as ToNapiValue>::to_napi_value(env, #ret)
} else {
JsError::from(#ret.unwrap_err()).throw_into(env);
Ok(std::ptr::null_mut())
match #ret {
Ok(value) => ToNapiValue::to_napi_value(env, value),
Err(err) => {
JsError::from(err).throw_into(env);
Ok(std::ptr::null_mut())
},
}
}
}