1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

fix clearTimeout.name / clearInterval.name (#2540)

This commit is contained in:
迷渡 2019-06-18 21:24:20 +08:00 committed by Ryan Dahl
parent 76d51b0f9a
commit d5e80ad677
3 changed files with 21 additions and 4 deletions

View file

@ -63,8 +63,8 @@ console[consoleTypes.isConsoleInstance] = true;
window.atob = textEncoding.atob; window.atob = textEncoding.atob;
window.btoa = textEncoding.btoa; window.btoa = textEncoding.btoa;
window.fetch = fetchTypes.fetch; window.fetch = fetchTypes.fetch;
window.clearTimeout = timers.clearTimer; window.clearTimeout = timers.clearTimeout;
window.clearInterval = timers.clearTimer; window.clearInterval = timers.clearInterval;
window.console = console; window.console = console;
window.setTimeout = timers.setTimeout; window.setTimeout = timers.setTimeout;
window.setInterval = timers.setInterval; window.setInterval = timers.setInterval;

View file

@ -249,7 +249,7 @@ export function setInterval(
} }
/** Clears a previously set timer by id. AKA clearTimeout and clearInterval. */ /** 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); id = Number(id);
const timer = idMap.get(id); const timer = idMap.get(id);
if (timer === undefined) { if (timer === undefined) {
@ -260,3 +260,11 @@ export function clearTimer(id: number): void {
unschedule(timer); unschedule(timer);
idMap.delete(timer.id); idMap.delete(timer.id);
} }
export function clearTimeout(id: number): void {
clearTimer(id);
}
export function clearInterval(id: number): void {
clearTimer(id);
}

View file

@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // 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(): { function deferred(): {
promise: Promise<{}>; promise: Promise<{}>;
@ -243,3 +243,12 @@ test(async function clearTimeoutShouldConvertToNumber(): Promise<void> {
clearTimeout((obj as unknown) as number); clearTimeout((obj as unknown) as number);
assert(called); assert(called);
}); });
test(function testFunctionName(): void {
assertEquals(clearTimeout.name, "clearTimeout");
assertEquals(clearInterval.name, "clearInterval");
});
test(function clearTimeoutAndClearIntervalNotBeEquals(): void {
assertNotEquals(clearTimeout, clearInterval);
});