From 54dd120880f849ee787d9486fbee6d8d1a7e5c82 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 24 Jan 2023 17:41:36 +0800 Subject: [PATCH] fix(napi): add UnknownReturnValue to use in call_async scenario (#1451) --- crates/napi/src/threadsafe_function.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/napi/src/threadsafe_function.rs b/crates/napi/src/threadsafe_function.rs index e41289fe..931ea898 100644 --- a/crates/napi/src/threadsafe_function.rs +++ b/crates/napi/src/threadsafe_function.rs @@ -8,7 +8,7 @@ use std::ptr; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, RwLock}; -use crate::bindgen_runtime::{FromNapiValue, ToNapiValue}; +use crate::bindgen_runtime::{FromNapiValue, ToNapiValue, TypeName, ValidateNapiValue}; use crate::{check_status, sys, Env, JsError, JsUnknown, Result, Status}; /// ThreadSafeFunction Context object @@ -747,3 +747,23 @@ macro_rules! type_level_enum {( )} use type_level_enum; + +pub struct UnknownReturnValue; + +impl TypeName for UnknownReturnValue { + fn type_name() -> &'static str { + "UnknownReturnValue" + } + + fn value_type() -> crate::ValueType { + crate::ValueType::Unknown + } +} + +impl ValidateNapiValue for UnknownReturnValue {} + +impl FromNapiValue for UnknownReturnValue { + unsafe fn from_napi_value(_env: sys::napi_env, _napi_val: sys::napi_value) -> Result { + Ok(UnknownReturnValue) + } +}