pub struct JsArray(/* private fields */);
Expand description
The type of JavaScript
Array
objects.
An array is any JavaScript value for which
Array.isArray
would return true
.
§Example
// Create a new empty array:
let a: Handle<JsArray> = cx.empty_array();
// Create some new values to push onto the array:
let n = cx.number(17);
let s = cx.string("hello");
// Push the elements onto the array:
a.set(&mut cx, 0, n)?;
a.set(&mut cx, 1, s)?;
Implementations§
source§impl JsArray
impl JsArray
sourcepub fn new<'a, C: Context<'a>>(cx: &mut C, len: usize) -> Handle<'a, JsArray>
pub fn new<'a, C: Context<'a>>(cx: &mut C, len: usize) -> Handle<'a, JsArray>
Constructs a new empty array of length len
, equivalent to the JavaScript
expression new Array(len)
.
Note that for non-zero len
, this creates a
sparse array,
which can sometimes have surprising behavior. To ensure that a new array
is and remains dense (i.e., not sparse), consider creating an empty array
with JsArray::new(cx, 0)
or cx.empty_array()
and only appending
elements to the end of the array.
See also: Context::empty_array
sourcepub fn to_vec<'a, C: Context<'a>>(
&self,
cx: &mut C
) -> NeonResult<Vec<Handle<'a, JsValue>>>
pub fn to_vec<'a, C: Context<'a>>( &self, cx: &mut C ) -> NeonResult<Vec<Handle<'a, JsValue>>>
Copies the array contents into a new Vec
by iterating through all indices
from 0 to self.len()
.
The length is dynamically checked on each iteration in case the array is modified during the computation.
Trait Implementations§
source§impl Object for JsArray
impl Object for JsArray
source§fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Option<Handle<'a, V>>>
fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Option<Handle<'a, V>>>
Gets a property from a JavaScript object that may be
undefined
and
attempts to downcast the value if it existed.source§fn get_value<'a, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, JsValue>>
fn get_value<'a, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Handle<'a, JsValue>>
source§fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, V>>
fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Handle<'a, V>>
Gets a property from a JavaScript object and attempts to downcast as a specific type.
Equivalent to calling
obj.get_value(&mut cx)?.downcast_or_throw(&mut cx)
. Read moresource§fn get_own_property_names<'a, C: Context<'a>>(
&self,
cx: &mut C
) -> JsResult<'a, JsArray>
fn get_own_property_names<'a, C: Context<'a>>( &self, cx: &mut C ) -> JsResult<'a, JsArray>
Available on crate feature
napi-6
only.fn freeze<'a, C: Context<'a>>(&self, cx: &mut C) -> NeonResult<&Self>
fn seal<'a, C: Context<'a>>(&self, cx: &mut C) -> NeonResult<&Self>
fn set<'a, C: Context<'a>, K: PropertyKey, W: Value>( &self, cx: &mut C, key: K, val: Handle<'_, W> ) -> NeonResult<bool>
fn root<'a, C: Context<'a>>(&self, cx: &mut C) -> Root<Self>
fn call_method_with<'a, C, K>(
&self,
cx: &mut C,
method: K
) -> NeonResult<CallOptions<'a>>where
C: Context<'a>,
K: PropertyKey,
source§impl Value for JsArray
impl Value for JsArray
Auto Trait Implementations§
impl RefUnwindSafe for JsArray
impl !Send for JsArray
impl !Sync for JsArray
impl Unpin for JsArray
impl UnwindSafe for JsArray
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more