node/test/parallel/test-timers-not-emit-duration-zero.js
jakecastelli f5ed3386fd
timers: emit warning if delay is negative or NaN
Emit process warning once per process when delay is a negative number or
not a number, this will prevent unexpected behaviour caused by invalid
`delay` also keep the consistency of the behaviour and warning message
for `TIMEOUT_MAX` number As the negative number is invalid delay will be
set to 1.

PR-URL: https://github.com/nodejs/node/pull/46678
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2024-06-28 11:36:31 +00:00

32 lines
538 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
function timerNotCanceled() {
assert.fail('Timer should be canceled');
}
process.on(
'warning',
common.mustNotCall(() => {
assert.fail('Timer should be canceled');
})
);
{
const timeout = setTimeout(timerNotCanceled, 0);
clearTimeout(timeout);
}
{
const interval = setInterval(timerNotCanceled, 0);
clearInterval(interval);
}
{
const timeout = setTimeout(timerNotCanceled, 0);
timeout.refresh();
clearTimeout(timeout);
}