pub struct Array<A: IVm>(/* private fields */);Expand description
use nanvm_lib::{
vm::{ToArray, IVm, Array, Any, Number, ToAny},
common::{sized_index::SizedIndex, default::default},
naive::Naive
};
fn array_test<A: IVm>() {
let b: Array<A> = [Number::from(1.0).to_any(), true.to_any()].to_array();
assert_eq!(b.length(), 2);
assert_eq!(b[0], Number::from(1.0).to_any());
assert_eq!(b[1], true.to_any());
let b1: Array<A> = [Number::from(1.0).to_any(), true.to_any()].to_array();
assert_eq!(b, b);
assert_ne!(b, b1);
let ac: Any<A> = b.clone().to_any();
let d: Array<A> = ac.try_into().unwrap();
assert_eq!(d, b);
let e0: Array<A> = default();
let e1: Array<A> = [].to_array();
assert_ne!(e0, e1);
}
array_test::<Naive>();Implementations§
Source§impl<A: IVm> Array<A>
impl<A: IVm> Array<A>
Sourcepub fn argument(&self, i: u32) -> Any<A>
pub fn argument(&self, i: u32) -> Any<A>
The i-th argument of a call whose arguments this array holds, or
undefined past the end, as JavaScript binds a parameter the call
left out. What a built-in and a compiled function’s body read their
fixed arguments with: one bounds check and one clone, where
Index<u32> panics past the end.
Source§impl<A: IVm> Array<A>
impl<A: IVm> Array<A>
Sourcepub fn rest(&self, i: u32) -> Array<A>
pub fn rest(&self, i: u32) -> Array<A>
The arguments from the i-th on, as a rest parameter of a call
whose arguments this array holds reads them: the array itself for
i == 0, since nothing is skipped, and a new array of the items
from i otherwise — empty when i is past the end.
The array is the call’s own: a call step builds it from the
argument list, a spread iterated, so no program holds it but the
callee, and answering it as the rest shares nothing a program can
see (fjs/edag/README.md, “An engine may form the arguments the
way the callee reads them”). A host calling Any::call with an
array it keeps is handing the callee that array, and reads it back
as the rest.