feat: add 'coerce_to_object' method to Array

This commit is contained in:
Jose Acevedo 2022-01-17 20:50:55 -08:00
parent 859b422ba8
commit 36e808d2a6

View file

@ -1,6 +1,6 @@
use std::ptr; use std::ptr;
use crate::{bindgen_prelude::*, check_status, sys, ValueType}; use crate::{bindgen_prelude::*, check_status, sys, JsObject, Value, ValueType};
pub struct Array { pub struct Array {
env: sys::napi_env, env: sys::napi_env,
@ -69,6 +69,16 @@ impl Array {
pub fn len(&self) -> u32 { pub fn len(&self) -> u32 {
self.len self.len
} }
pub fn coerce_to_object(self) -> Result<JsObject> {
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 { impl TypeName for Array {