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:
parent
a953190742
commit
9ad5b0653e
2 changed files with 14 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue