neon/sys/array.rs
1//! Facilities for working with Array `napi_value`s.
2
3use super::{
4 bindings as napi,
5 raw::{Env, Local},
6};
7
8pub unsafe fn new(out: &mut Local, env: Env, length: usize) {
9 napi::create_array_with_length(env, length, out as *mut _).unwrap();
10}
11
12/// Gets the length of a `napi_value` containing a JavaScript Array.
13///
14/// # Panics
15/// This function panics if `array` is not an Array, or if a previous n-api call caused a pending
16/// exception.
17pub unsafe fn len(env: Env, array: Local) -> u32 {
18 let mut len = 0;
19 napi::get_array_length(env, array, &mut len as *mut _).unwrap();
20 len
21}