From d5e80ad67744bbd2646af0a0abe27cc38205f990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=B7=E6=B8=A1?= Date: Tue, 18 Jun 2019 21:24:20 +0800 Subject: [PATCH] fix clearTimeout.name / clearInterval.name (#2540) --- js/globals.ts | 4 ++-- js/timers.ts | 10 +++++++++- js/timers_test.ts | 11 ++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/js/globals.ts b/js/globals.ts index 2c8a25be30..1d33f65233 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 0d0e1e69ae..7cac5cc6d0 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 65432d4c5f..76563c96e6 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 { 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); +});