CallInfo

Raw call info for variadic or dynamic-arity functions. It is available through the exact callback signature (napi.Env, napi.CallInfo) !napi.Val; neither injected value consumes a JS argument. Raw mode cannot add typed parameters or use another return type.

pub fn sum(env: napi.Env, info: napi.CallInfo) !napi.Val {
    const args = try info.argsSlice(env, 16);
    var total: f64 = 0;
    for (args) |arg| total += try arg.to(env, f64);
    return env.toJs(total);
}

Methods

MethodReturnsPurpose
argsSlice(env, comptime max: usize)![]napi.ValSafely capture up to max real arguments. The slice uses the per-call arena.
args(env, comptime max: usize)![max]napi.ValCompatibility API. Missing slots are filled with undefined.
argCount(env)!usizeNumber of arguments actually passed, which may exceed a capture limit.
this(env)!napi.ValThe this binding of the call.

Prefer argsSlice: its length is min(actual argument count, max), so iterating it cannot run beyond captured storage. args remains available for existing code that needs a fixed-size array. When combining args with argCount, cap the count with @min(count, args.len).

When to use it

  • Variadic functions like sum(...nums).
  • Functions whose argument types depend on runtime conditions (where you would convert each argument with val.to(env, T) based on its observed type).
  • Reaching this from a function that is being called as a method on a JS object.

For everything else, prefer typed parameters; the bridge does the conversion for you and the result is shorter and clearer.