From 65fa2b810b9e22f6eda6c11945e27ba21dff7a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=B7=E6=B8=A1?= Date: Fri, 30 Aug 2019 23:51:53 +0800 Subject: clearTimeout's params should not be bigint (#2838) --- js/timers.ts | 2 ++ js/timers_test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'js') diff --git a/js/timers.ts b/js/timers.ts index d12205317..4b8596cb7 100644 --- a/js/timers.ts +++ b/js/timers.ts @@ -262,6 +262,7 @@ function clearTimer(id: number): void { } export function clearTimeout(id: number = 0): void { + checkBigInt(id); if (id === 0) { return; } @@ -269,6 +270,7 @@ export function clearTimeout(id: number = 0): void { } export function clearInterval(id: number = 0): void { + checkBigInt(id); if (id === 0) { return; } diff --git a/js/timers_test.ts b/js/timers_test.ts index f4757bdb2..bc4fcffcf 100644 --- a/js/timers_test.ts +++ b/js/timers_test.ts @@ -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"); -- cgit v1.2.3