diff --git a/crates/napi/src/bindgen_runtime/js_values.rs b/crates/napi/src/bindgen_runtime/js_values.rs index a2d2301c..5e296f7c 100644 --- a/crates/napi/src/bindgen_runtime/js_values.rs +++ b/crates/napi/src/bindgen_runtime/js_values.rs @@ -1,4 +1,4 @@ -use crate::{check_status, sys, Error, Result, Status, ValueType}; +use crate::{check_status, sys, Error, JsUnknown, Result, Status, ValueType}; use std::ptr; mod array; @@ -32,6 +32,12 @@ pub trait ToNapiValue { unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> Result; } +impl ToNapiValue for JsUnknown { + unsafe fn to_napi_value(_env: sys::napi_env, val: Self) -> Result { + Ok(val.0.value) + } +} + pub trait FromNapiValue: Sized { /// # Safety /// @@ -39,6 +45,16 @@ pub trait FromNapiValue: Sized { unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result; } +impl FromNapiValue for JsUnknown { + unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result { + Ok(JsUnknown(crate::Value { + env, + value: napi_val, + value_type: crate::ValueType::Unknown, + })) + } +} + pub trait FromNapiRef { /// # Safety ///