Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecastelli committed Jun 25, 2024
1 parent b6784bf commit e7e7f49
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/internal/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ class Timeout {
// Timer constructor function.
// The entire prototype is defined in lib/timers.js
constructor(callback, after, args, isRepeat, isRefed) {
after === undefined ? 1 : after *= 1; // Coalesce to number or NaN
if (after === undefined) {
after = 1;
} else {
after *= 1; // Coalesce to number or NaN
}

if (!(after >= 1 && after <= TIMEOUT_MAX)) {
if (after > TIMEOUT_MAX) {
Expand Down
31 changes: 31 additions & 0 deletions test/parallel/test-timers-not-emit-duration-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'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);
}

0 comments on commit e7e7f49

Please sign in to comment.