njs_promise_all(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
    njs_index_t function_type)
{
    njs_int_t                    ret;
    njs_value_t                  *promise, resolve;
    njs_iterator_handler_t       handler;
    njs_promise_iterator_args_t  pargs;

    promise = njs_argument(args, 0);

    pargs.capability = njs_promise_new_capability(vm, promise);
    if (njs_slow_path(pargs.capability == NULL)) {
        return NJS_ERROR;
    }

    ret = njs_value_property(vm, promise, njs_value_arg(&string_resolve),
                             &resolve);
    if (njs_slow_path(ret != NJS_OK)) {
        return ret;
    }

    if (njs_slow_path(!njs_is_function(&resolve))) {
        njs_type_error(vm, "resolve is not callable");
        return NJS_ERROR;
    }

    pargs.function = njs_function(&resolve);
    pargs.constructor = promise;

    switch (function_type) {
    case NJS_PROMISE_ALL_SETTLED:
        handler = njs_promise_perform_all_settled_handler;
        break;

    case NJS_PROMISE_ANY:
        handler = njs_promise_perform_any_handler;
        break;

    default:
        handler = njs_promise_perform_all_handler;
        break;
    }

    return njs_promise_perform_all(vm, njs_arg(args, nargs, 1), &pargs,
                                   handler, &vm->retval);
}
njs_promise_all(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
    njs_index_t function_type)
{
    njs_int_t                    ret;
    njs_value_t                  *promise, resolve;
    njs_iterator_handler_t       handler;
    njs_promise_iterator_args_t  pargs;

    promise = njs_argument(args, 0);

    pargs.capability = njs_promise_new_capability(vm, promise);
    if (njs_slow_path(pargs.capability == NULL)) {
        return NJS_ERROR;
    }

    ret = njs_value_property(vm, promise, njs_value_arg(&string_resolve),
                             &resolve);
    if (njs_slow_path(ret != NJS_OK)) {
        return ret;
    }

    if (njs_slow_path(!njs_is_function(&resolve))) {
        njs_type_error(vm, "resolve is not callable");
        return NJS_ERROR;
    }

    pargs.function = njs_function(&resolve);
    pargs.constructor = promise;

    switch (function_type) {
    case NJS_PROMISE_ALL_SETTLED:
        handler = njs_promise_perform_all_settled_handler;
        break;

    case NJS_PROMISE_ANY:
        handler = njs_promise_perform_any_handler;
        break;

    default:
        handler = njs_promise_perform_all_handler;
        break;
    }

    return njs_promise_perform_all(vm, njs_arg(args, nargs, 1), &pargs,
                                   handler, &vm->retval);
}