Function quickjs_runtime::quickjs_utils::arrays::get_length_q

source ·
pub fn get_length_q(
    q_ctx: &QuickJsRealmAdapter,
    arr_ref: &QuickJsValueAdapter,
) -> Result<u32, JsError>
Expand description

Get the length of an Array

§Example

use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use quickjs_runtime::jsutils::Script;
use quickjs_runtime::quickjs_utils::arrays;

let rt = QuickJsRuntimeBuilder::new().build();
rt.exe_rt_task_in_event_loop(|q_js_rt| {
    let q_ctx = q_js_rt.get_main_realm();
    let obj_ref = q_ctx.eval(Script::new("get_length_test.es", "([1, 2, 3]);")).ok().expect("script failed");
    let len = arrays::get_length_q(q_ctx, &obj_ref).ok().expect("could not get length");
    assert_eq!(len, 3);
});