提交 9ad5b065 编写于 作者: 迷渡's avatar 迷渡 提交者: Ryan Dahl

clearTimeout should convert to number (#2539)

上级 a9531907
...@@ -250,6 +250,7 @@ export function setInterval( ...@@ -250,6 +250,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 { export function clearTimer(id: number): void {
id = Number(id);
const timer = idMap.get(id); const timer = idMap.get(id);
if (timer === undefined) { if (timer === undefined) {
// Timer doesn't exist any more or never existed. This is not an error. // Timer doesn't exist any more or never existed. This is not an error.
......
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // 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(): { function deferred(): {
promise: Promise<{}>; promise: Promise<{}>;
...@@ -231,3 +231,15 @@ test(async function timeoutBindThis(): Promise<void> { ...@@ -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);
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册