njs_promise_constructor_call(njs_vm_t *vm, njs_function_t *function)
{
    njs_int_t      ret;
    njs_value_t    retval, arguments[2];
    njs_promise_t  *promise;

    promise = njs_promise_alloc(vm);
    if (njs_slow_path(promise == NULL)) {
        return NULL;
    }

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

    ret = njs_function_call(vm, function, &njs_value_undefined, arguments, 2,
                            &retval);
    if (njs_slow_path(ret != NJS_OK)) {
        if (njs_slow_path(njs_is_memory_error(vm, &vm->retval))) {
            return NULL;
        }

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

    return promise;
}
njs_promise_constructor_call(njs_vm_t *vm, njs_function_t *function)
{
    njs_int_t      ret;
    njs_value_t    retval, arguments[2];
    njs_promise_t  *promise;

    promise = njs_promise_alloc(vm);
    if (njs_slow_path(promise == NULL)) {
        return NULL;
    }

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

    ret = njs_function_call(vm, function, &njs_value_undefined, arguments, 2,
                            &retval);
    if (njs_slow_path(ret != NJS_OK)) {
        if (njs_slow_path(njs_is_memory_error(vm, &vm->retval))) {
            return NULL;
        }

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

    return promise;
}