feat(napi): allow return self as this

This commit is contained in:
LongYinan 2021-11-25 22:31:11 +08:00
parent 1fe39ff66d
commit 9a0de8e485
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
4 changed files with 24 additions and 12 deletions
crates/napi/src/bindgen_runtime

View file

@ -12,7 +12,7 @@ pub static ___CALL_FROM_FACTORY: AtomicBool = AtomicBool::new(false);
pub struct CallbackInfo<const N: usize> {
env: sys::napi_env,
this: sys::napi_value,
pub this: sys::napi_value,
pub args: [sys::napi_value; N],
}

View file

@ -123,8 +123,8 @@ impl Array {
T: ToNapiValue,
{
let mut arr = Array::new(env.0, value.len() as u32)?;
value.into_iter().try_for_each(|val| {
arr.insert(val)?;
value.into_iter().enumerate().try_for_each(|(index, val)| {
arr.set(index as u32, val)?;
Ok::<(), Error>(())
})?;
Ok(arr)