njs_promise_resolve_thenable_job(njs_vm_t *vm, njs_value_t *args,
    njs_uint_t nargs, njs_index_t unused)
{
    njs_int_t    ret;
    njs_value_t  *promise, retval, arguments[2];

    promise = njs_arg(args, nargs, 1);

    ret = njs_promise_create_resolving_functions(vm, njs_promise(promise),
                                                 arguments);
    if (njs_slow_path(ret != NJS_OK)) {
        return ret;
    }

    ret = njs_function_call(vm, njs_function(njs_arg(args, nargs, 3)),
                            njs_arg(args, nargs, 2), arguments, 2, &retval);
    if (njs_slow_path(ret != NJS_OK)) {

        if (njs_slow_path(njs_is_memory_error(vm, &vm->retval))) {
            return NJS_ERROR;
        }

        ret = njs_function_call(vm, njs_function(&arguments[1]),
                                &njs_value_undefined, &vm->retval, 1,
                                &vm->retval);
        if (njs_slow_path(ret != NJS_OK)) {
            return NJS_ERROR;
        }
    }

    return NJS_OK;
}
njs_promise_resolve_thenable_job(njs_vm_t *vm, njs_value_t *args,
    njs_uint_t nargs, njs_index_t unused)
{
    njs_int_t    ret;
    njs_value_t  *promise, retval, arguments[2];

    promise = njs_arg(args, nargs, 1);

    ret = njs_promise_create_resolving_functions(vm, njs_promise(promise),
                                                 arguments);
    if (njs_slow_path(ret != NJS_OK)) {
        return ret;
    }

    ret = njs_function_call(vm, njs_function(njs_arg(args, nargs, 3)),
                            njs_arg(args, nargs, 2), arguments, 2, &retval);
    if (njs_slow_path(ret != NJS_OK)) {

        if (njs_slow_path(njs_is_memory_error(vm, &vm->retval))) {
            return NJS_ERROR;
        }

        ret = njs_function_call(vm, njs_function(&arguments[1]),
                                &njs_value_undefined, &vm->retval, 1,
                                &vm->retval);
        if (njs_slow_path(ret != NJS_OK)) {
            return NJS_ERROR;
        }
    }

    return NJS_OK;
}