fix(napi-derive-backend): wrong restrict on Result return type
This commit is contained in:
parent
ea8a79e761
commit
413a55545f
3 changed files with 8 additions and 7 deletions
|
@ -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 {
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue