node: less unwraps (#6388)

* Update api/node/rust/interpreter/value.rs

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

---------

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
This commit is contained in:
FloVanGH 2024-10-01 08:47:53 +00:00 committed by GitHub
parent 68a4e15cff
commit 4b880a7b49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 171 additions and 17 deletions

View file

@ -54,7 +54,10 @@ pub fn invoke_from_event_loop(env: Env, callback: JsFunction) -> napi::Result<na
let function_ref = send_wrapper::SendWrapper::new(function_ref);
i_slint_core::api::invoke_from_event_loop(move || {
let function_ref = function_ref.take();
let callback: JsFunction = function_ref.get().unwrap();
let Ok(callback) = function_ref.get::<JsFunction>() else {
eprintln!("Node.js: JavaScript invoke_from_event_loop throws an exception");
return;
};
callback.call_without_args(None).ok();
})
.map_err(|e| napi::Error::from_reason(e.to_string()))