Skip to content

Commit

Permalink
fix clearTimeout.name / clearInterval.name (denoland#2540)
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac authored and ry committed Jun 18, 2019
1 parent 76d51b0 commit d5e80ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions js/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion js/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
11 changes: 10 additions & 1 deletion js/timers_test.ts
Original file line number Diff line number Diff line change
@@ -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<{}>;
Expand Down Expand Up @@ -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);
});

0 comments on commit d5e80ad

Please sign in to comment.