njs_promise_add_event(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
    njs_uint_t nargs)
{
    njs_event_t  *event;

    event = njs_mp_zalloc(vm->mem_pool, sizeof(njs_event_t));
    if (njs_slow_path(event == NULL)) {
        njs_memory_error(vm);
        return NJS_ERROR;
    }

    event->function = function;
    event->once = 1;

    if (nargs != 0) {
        event->args = njs_mp_alloc(vm->mem_pool, sizeof(njs_value_t) * nargs);
        if (njs_slow_path(event->args == NULL)) {
            njs_memory_error(vm);
            return NJS_ERROR;
        }

        memcpy(event->args, args, sizeof(njs_value_t) * nargs);

        event->nargs = nargs;
    }

    njs_queue_insert_tail(&vm->promise_events, &event->link);

    return NJS_OK;
}
njs_promise_add_event(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
    njs_uint_t nargs)
{
    njs_event_t  *event;

    event = njs_mp_zalloc(vm->mem_pool, sizeof(njs_event_t));
    if (njs_slow_path(event == NULL)) {
        njs_memory_error(vm);
        return NJS_ERROR;
    }

    event->function = function;
    event->once = 1;

    if (nargs != 0) {
        event->args = njs_mp_alloc(vm->mem_pool, sizeof(njs_value_t) * nargs);
        if (njs_slow_path(event->args == NULL)) {
            njs_memory_error(vm);
            return NJS_ERROR;
        }

        memcpy(event->args, args, sizeof(njs_value_t) * nargs);

        event->nargs = nargs;
    }

    njs_queue_insert_tail(&vm->promise_events, &event->link);

    return NJS_OK;
}