From e709f25635004ca8340499775f5917c5b8dd42d3 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 29 Oct 2021 18:50:29 +0800 Subject: [PATCH] feat(napi): impl from/to NapiValue for JsUnkown --- crates/napi/src/bindgen_runtime/js_values.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 ///