0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 20:25:12 -05:00

clearTimeout should convert to number (#2539)

This commit is contained in:
迷渡 2019-06-18 01:42:20 +08:00 committed by Ryan Dahl
parent a953190742
commit 9ad5b0653e
2 changed files with 14 additions and 1 deletions

View file

@ -250,6 +250,7 @@ export function setInterval(
/** Clears a previously set timer by id. AKA clearTimeout and clearInterval. */
export function clearTimer(id: number): void {
id = Number(id);
const timer = idMap.get(id);
if (timer === undefined) {
// Timer doesn't exist any more or never existed. This is not an error.

View file

@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assertEquals } from "./test_util.ts";
import { test, assert, assertEquals } from "./test_util.ts";
function deferred(): {
promise: Promise<{}>;
@ -231,3 +231,15 @@ test(async function timeoutBindThis(): Promise<void> {
}
);
});
test(async function clearTimeoutShouldConvertToNumber(): Promise<void> {
let called = false;
const obj = {
valueOf(): number {
called = true;
return 1;
}
};
clearTimeout((obj as unknown) as number);
assert(called);
});