Skip to content

Commit

Permalink
clearTimeout's params should not be bigint (denoland#2838)
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac authored and ry committed Aug 30, 2019
1 parent c370f74 commit 65fa2b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions js/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@ function clearTimer(id: number): void {
}

export function clearTimeout(id: number = 0): void {
checkBigInt(id);
if (id === 0) {
return;
}
clearTimer(id);
}

export function clearInterval(id: number = 0): void {
checkBigInt(id);
if (id === 0) {
return;
}
Expand Down
15 changes: 15 additions & 0 deletions js/timers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,21 @@ test(function setTimeoutShouldThrowWithBigint(): void {
assertEquals(hasThrown, 2);
});

test(function clearTimeoutShouldThrowWithBigint(): void {
let hasThrown = 0;
try {
clearTimeout((1n as unknown) as number);
hasThrown = 1;
} catch (err) {
if (err instanceof TypeError) {
hasThrown = 2;
} else {
hasThrown = 3;
}
}
assertEquals(hasThrown, 2);
});

test(function testFunctionName(): void {
assertEquals(clearTimeout.name, "clearTimeout");
assertEquals(clearInterval.name, "clearInterval");
Expand Down

0 comments on commit 65fa2b8

Please sign in to comment.