njs_promise_invoke_then(njs_vm_t *vm, njs_value_t *promise, njs_value_t *args,
    njs_int_t nargs)
{
    njs_int_t    ret;
    njs_value_t  function;

    static const njs_value_t  string_then = njs_string("then");

    ret = njs_value_property(vm, promise, njs_value_arg(&string_then),
                             &function);
    if (njs_slow_path(ret != NJS_OK)) {
        if (ret == NJS_DECLINED) {
            goto failed;
        }

        return NJS_ERROR;
    }

    if (njs_fast_path(njs_is_function(&function))) {
        return njs_function_call(vm, njs_function(&function), promise, args,
                                 nargs, &vm->retval);
    }

failed:

    njs_type_error(vm, "is not a function");

    return NJS_ERROR;
}
njs_promise_invoke_then(njs_vm_t *vm, njs_value_t *promise, njs_value_t *args,
    njs_int_t nargs)
{
    njs_int_t    ret;
    njs_value_t  function;

    static const njs_value_t  string_then = njs_string("then");

    ret = njs_value_property(vm, promise, njs_value_arg(&string_then),
                             &function);
    if (njs_slow_path(ret != NJS_OK)) {
        if (ret == NJS_DECLINED) {
            goto failed;
        }

        return NJS_ERROR;
    }

    if (njs_fast_path(njs_is_function(&function))) {
        return njs_function_call(vm, njs_function(&function), promise, args,
                                 nargs, &vm->retval);
    }

failed:

    njs_type_error(vm, "is not a function");

    return NJS_ERROR;
}