mirror of
https://github.com/denoland/deno
synced 2024-11-05 18:45:24 +00:00
fix timer's params length (#2655)
This commit is contained in:
parent
a0b8f13f18
commit
ac98bd8a7c
2 changed files with 17 additions and 4 deletions
14
js/timers.ts
14
js/timers.ts
|
@ -229,7 +229,7 @@ function setTimer(
|
|||
/** Sets a timer which executes a function once after the timer expires. */
|
||||
export function setTimeout(
|
||||
cb: (...args: Args) => void,
|
||||
delay: number,
|
||||
delay: number = 0,
|
||||
...args: Args
|
||||
): number {
|
||||
// @ts-ignore
|
||||
|
@ -240,7 +240,7 @@ export function setTimeout(
|
|||
/** Repeatedly calls a function , with a fixed time delay between each call. */
|
||||
export function setInterval(
|
||||
cb: (...args: Args) => void,
|
||||
delay: number,
|
||||
delay: number = 0,
|
||||
...args: Args
|
||||
): number {
|
||||
// @ts-ignore
|
||||
|
@ -261,10 +261,16 @@ function clearTimer(id: number): void {
|
|||
idMap.delete(timer.id);
|
||||
}
|
||||
|
||||
export function clearTimeout(id: number): void {
|
||||
export function clearTimeout(id: number = 0): void {
|
||||
if (id === 0) {
|
||||
return;
|
||||
}
|
||||
clearTimer(id);
|
||||
}
|
||||
|
||||
export function clearInterval(id: number): void {
|
||||
export function clearInterval(id: number = 0): void {
|
||||
if (id === 0) {
|
||||
return;
|
||||
}
|
||||
clearTimer(id);
|
||||
}
|
||||
|
|
|
@ -249,6 +249,13 @@ test(function testFunctionName(): void {
|
|||
assertEquals(clearInterval.name, "clearInterval");
|
||||
});
|
||||
|
||||
test(function testFunctionParamsLength(): void {
|
||||
assertEquals(setTimeout.length, 1);
|
||||
assertEquals(setInterval.length, 1);
|
||||
assertEquals(clearTimeout.length, 0);
|
||||
assertEquals(clearInterval.length, 0);
|
||||
});
|
||||
|
||||
test(function clearTimeoutAndClearIntervalNotBeEquals(): void {
|
||||
assertNotEquals(clearTimeout, clearInterval);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue