mirror of
https://github.com/denoland/deno.git
synced 2025-01-01 11:58:45 -05:00
fix(node/timers): error when passing id to clearTimeout/clearInterval (#27130)
As pointed out in https://github.com/denoland/deno/issues/27126 we used a variable which could potentially be of type `number` instead of the `Timeout` class instance. Ensure that we're always setting `_destroyed` on the class instead instead. Fixes https://github.com/denoland/deno/issues/27126
This commit is contained in:
parent
026bbc4a9e
commit
39722f190a
2 changed files with 12 additions and 2 deletions
|
@ -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);
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue