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 /// import the preludes
use napi::bindgen_prelude::*; 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] #[napi]
fn fibonacci(n: u32) -> u32 { fn fibonacci(n: u32) -> u32 {
match n { match n {

View file

@ -2,6 +2,6 @@
"name": "test-module", "name": "test-module",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "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 { } else {
quote! { quote! {
if #ret.is_ok() { match #ret {
<Result<#ty> as ToNapiValue>::to_napi_value(env, #ret) Ok(value) => ToNapiValue::to_napi_value(env, value),
} else { Err(err) => {
JsError::from(#ret.unwrap_err()).throw_into(env); JsError::from(err).throw_into(env);
Ok(std::ptr::null_mut()) Ok(std::ptr::null_mut())
},
} }
} }
} }