diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/globals.ts | 4 | ||||
-rw-r--r-- | js/timers.ts | 10 | ||||
-rw-r--r-- | js/timers_test.ts | 11 |
3 files changed, 21 insertions, 4 deletions
diff --git a/js/globals.ts b/js/globals.ts index 2c8a25be3..1d33f6523 100644 --- a/js/globals.ts +++ b/js/globals.ts @@ -63,8 +63,8 @@ console[consoleTypes.isConsoleInstance] = true; window.atob = textEncoding.atob; window.btoa = textEncoding.btoa; window.fetch = fetchTypes.fetch; -window.clearTimeout = timers.clearTimer; -window.clearInterval = timers.clearTimer; +window.clearTimeout = timers.clearTimeout; +window.clearInterval = timers.clearInterval; window.console = console; window.setTimeout = timers.setTimeout; window.setInterval = timers.setInterval; diff --git a/js/timers.ts b/js/timers.ts index 0d0e1e69a..7cac5cc6d 100644 --- a/js/timers.ts +++ b/js/timers.ts @@ -249,7 +249,7 @@ export function setInterval( } /** Clears a previously set timer by id. AKA clearTimeout and clearInterval. */ -export function clearTimer(id: number): void { +function clearTimer(id: number): void { id = Number(id); const timer = idMap.get(id); if (timer === undefined) { @@ -260,3 +260,11 @@ export function clearTimer(id: number): void { unschedule(timer); idMap.delete(timer.id); } + +export function clearTimeout(id: number): void { + clearTimer(id); +} + +export function clearInterval(id: number): void { + clearTimer(id); +} diff --git a/js/timers_test.ts b/js/timers_test.ts index 65432d4c5..76563c96e 100644 --- a/js/timers_test.ts +++ b/js/timers_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { test, assert, assertEquals } from "./test_util.ts"; +import { test, assert, assertEquals, assertNotEquals } from "./test_util.ts"; function deferred(): { promise: Promise<{}>; @@ -243,3 +243,12 @@ test(async function clearTimeoutShouldConvertToNumber(): Promise<void> { clearTimeout((obj as unknown) as number); assert(called); }); + +test(function testFunctionName(): void { + assertEquals(clearTimeout.name, "clearTimeout"); + assertEquals(clearInterval.name, "clearInterval"); +}); + +test(function clearTimeoutAndClearIntervalNotBeEquals(): void { + assertNotEquals(clearTimeout, clearInterval); +}); |