Skip to content

Commit

Permalink
fix(node/timers): error when passing id to clearTimeout/clearInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Nov 28, 2024
1 parent f161adf commit ae8a943
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/node/polyfills/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function clearTimeout(timeout?: Timeout | number) {
const id = +timeout;
const timer = MapPrototypeGet(activeTimers, id);
if (timer) {
timeout._destroyed = true;
timer._destroyed = true;
MapPrototypeDelete(activeTimers, id);
}
clearTimeout_(id);
Expand All @@ -74,7 +74,7 @@ export function clearInterval(timeout?: Timeout | number | string) {
const id = +timeout;
const timer = MapPrototypeGet(activeTimers, id);
if (timer) {
timeout._destroyed = true;
timer._destroyed = true;
MapPrototypeDelete(activeTimers, id);
}
clearInterval_(id);
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_node/timers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ Deno.test("[node/timers refresh cancelled timer]", () => {
p.refresh();
});

Deno.test("[node/timers] clearTimeout with number", () => {
const timer = +timers.setTimeout(() => fail(), 10);
timers.clearTimeout(timer);
});

Deno.test("[node/timers] clearInterval with number", () => {
const timer = +timers.setInterval(() => fail(), 10);
timers.clearInterval(timer);
});

Deno.test("[node/timers setImmediate returns Immediate object]", () => {
const { clearImmediate, setImmediate } = timers;

Expand Down

0 comments on commit ae8a943

Please sign in to comment.