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

Get the length of an Array

Example

use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use hirofa_utils::js_utils::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_context();
    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);
});