njs_promise_all_resolve_element_functions(njs_vm_t *vm, njs_value_t *args,
    njs_uint_t nargs, njs_index_t unused)
{
    njs_value_t                arguments;
    njs_promise_all_context_t  *context;

    context = vm->top_frame->function->context;

    if (context->already_called) {
        njs_vm_retval_set(vm, &njs_value_undefined);
        return NJS_OK;
    }

    context->already_called = 1;
    context->values->start[context->index] = *njs_arg(args, nargs, 1);

    if (--(*context->remaining_elements) == 0) {
        njs_mp_free(vm->mem_pool, context->remaining_elements);

        njs_set_array(&arguments, context->values);

        return njs_function_call(vm,
                                 njs_function(&context->capability->resolve),
                                 &njs_value_undefined, &arguments, 1,
                                 &vm->retval);
    }

    njs_vm_retval_set(vm, &njs_value_undefined);

    return NJS_OK;
}
njs_promise_all_resolve_element_functions(njs_vm_t *vm, njs_value_t *args,
    njs_uint_t nargs, njs_index_t unused)
{
    njs_value_t                arguments;
    njs_promise_all_context_t  *context;

    context = vm->top_frame->function->context;

    if (context->already_called) {
        njs_vm_retval_set(vm, &njs_value_undefined);
        return NJS_OK;
    }

    context->already_called = 1;
    context->values->start[context->index] = *njs_arg(args, nargs, 1);

    if (--(*context->remaining_elements) == 0) {
        njs_mp_free(vm->mem_pool, context->remaining_elements);

        njs_set_array(&arguments, context->values);

        return njs_function_call(vm,
                                 njs_function(&context->capability->resolve),
                                 &njs_value_undefined, &arguments, 1,
                                 &vm->retval);
    }

    njs_vm_retval_set(vm, &njs_value_undefined);

    return NJS_OK;
}