Skip to content

Commit 65fa2b8

Browse files
justjavacry
authored andcommitted
clearTimeout's params should not be bigint (#2838)
1 parent c370f74 commit 65fa2b8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

js/timers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,15 @@ function clearTimer(id: number): void {
262262
}
263263

264264
export function clearTimeout(id: number = 0): void {
265+
checkBigInt(id);
265266
if (id === 0) {
266267
return;
267268
}
268269
clearTimer(id);
269270
}
270271

271272
export function clearInterval(id: number = 0): void {
273+
checkBigInt(id);
272274
if (id === 0) {
273275
return;
274276
}

js/timers_test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,21 @@ test(function setTimeoutShouldThrowWithBigint(): void {
259259
assertEquals(hasThrown, 2);
260260
});
261261

262+
test(function clearTimeoutShouldThrowWithBigint(): void {
263+
let hasThrown = 0;
264+
try {
265+
clearTimeout((1n as unknown) as number);
266+
hasThrown = 1;
267+
} catch (err) {
268+
if (err instanceof TypeError) {
269+
hasThrown = 2;
270+
} else {
271+
hasThrown = 3;
272+
}
273+
}
274+
assertEquals(hasThrown, 2);
275+
});
276+
262277
test(function testFunctionName(): void {
263278
assertEquals(clearTimeout.name, "clearTimeout");
264279
assertEquals(clearInterval.name, "clearInterval");

0 commit comments

Comments
 (0)