diff --git a/crates/napi/src/bindgen_runtime/js_values/array.rs b/crates/napi/src/bindgen_runtime/js_values/array.rs index f687439e..2b6c2137 100644 --- a/crates/napi/src/bindgen_runtime/js_values/array.rs +++ b/crates/napi/src/bindgen_runtime/js_values/array.rs @@ -1,6 +1,6 @@ use std::ptr; -use crate::{bindgen_prelude::*, check_status, sys, ValueType}; +use crate::{bindgen_prelude::*, check_status, sys, JsObject, Value, ValueType}; pub struct Array { env: sys::napi_env, @@ -69,6 +69,16 @@ impl Array { pub fn len(&self) -> u32 { self.len } + + pub fn coerce_to_object(self) -> Result { + let mut new_raw_value = ptr::null_mut(); + check_status!(unsafe { sys::napi_coerce_to_object(self.env, self.inner, &mut new_raw_value) })?; + Ok(JsObject(Value { + env: self.env, + value: new_raw_value, + value_type: ValueType::Object, + })) + } } impl TypeName for Array {