feat: add 'coerce_to_object' method to Array
This commit is contained in:
parent
859b422ba8
commit
36e808d2a6
1 changed files with 11 additions and 1 deletions
|
@ -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<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 {
|
||||
|
|
Loading…
Reference in a new issue