mirror of
https://github.com/denoland/deno.git
synced 2025-01-04 05:18:59 -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 id = +timeout;
|
||||||
const timer = MapPrototypeGet(activeTimers, id);
|
const timer = MapPrototypeGet(activeTimers, id);
|
||||||
if (timer) {
|
if (timer) {
|
||||||
timeout._destroyed = true;
|
timer._destroyed = true;
|
||||||
MapPrototypeDelete(activeTimers, id);
|
MapPrototypeDelete(activeTimers, id);
|
||||||
}
|
}
|
||||||
clearTimeout_(id);
|
clearTimeout_(id);
|
||||||
|
@ -74,7 +74,7 @@ export function clearInterval(timeout?: Timeout | number | string) {
|
||||||
const id = +timeout;
|
const id = +timeout;
|
||||||
const timer = MapPrototypeGet(activeTimers, id);
|
const timer = MapPrototypeGet(activeTimers, id);
|
||||||
if (timer) {
|
if (timer) {
|
||||||
timeout._destroyed = true;
|
timer._destroyed = true;
|
||||||
MapPrototypeDelete(activeTimers, id);
|
MapPrototypeDelete(activeTimers, id);
|
||||||
}
|
}
|
||||||
clearInterval_(id);
|
clearInterval_(id);
|
||||||
|
|
|
@ -100,6 +100,16 @@ Deno.test("[node/timers refresh cancelled timer]", () => {
|
||||||
p.refresh();
|
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]", () => {
|
Deno.test("[node/timers setImmediate returns Immediate object]", () => {
|
||||||
const { clearImmediate, setImmediate } = timers;
|
const { clearImmediate, setImmediate } = timers;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue