diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-01-21 01:30:30 +1100 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2020-01-20 09:30:30 -0500 |
commit | 60b53fd6b6dc2af83a64c332b9f3a1926f43d631 (patch) | |
tree | 4f4ef1aadb8c79ef2319d728b9d5b132af40ef83 /cli/js/timers.ts | |
parent | 23e67eb5153bd26dbae471b27dc6a21a6d283b0b (diff) |
Use globalThis to reference global scope (#3719)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/js/timers.ts')
-rw-r--r-- | cli/js/timers.ts | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/cli/js/timers.ts b/cli/js/timers.ts index e3b3fdd2a..da8fc7a22 100644 --- a/cli/js/timers.ts +++ b/cli/js/timers.ts @@ -1,11 +1,10 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assert } from "./util.ts"; -import { window } from "./window.ts"; import * as dispatch from "./dispatch.ts"; import { sendSync, sendAsync } from "./dispatch_json.ts"; import { RBTree } from "./rbtree.ts"; -const { console } = window; +const { console } = globalThis; interface Timer { id: number; @@ -173,7 +172,7 @@ function fireTimers(): void { if (pendingFireTimers.length > 0) { hasPendingFireTimers = true; // Fire the list of pending timers as a chain of microtasks. - window.queueMicrotask(firePendingTimers); + globalThis.queueMicrotask(firePendingTimers); } else { setOrClearGlobalTimeout(nextDueNode && nextDueNode.due, now); } @@ -198,14 +197,14 @@ function firePendingTimers(): void { // Fire a single timer and allow its children microtasks scheduled first. fire(pendingFireTimers.shift()!); // ...and we schedule next timer after this. - window.queueMicrotask(firePendingTimers); + globalThis.queueMicrotask(firePendingTimers); } } export type Args = unknown[]; function checkThis(thisArg: unknown): void { - if (thisArg !== null && thisArg !== undefined && thisArg !== window) { + if (thisArg !== null && thisArg !== undefined && thisArg !== globalThis) { throw new TypeError("Illegal invocation"); } } @@ -222,8 +221,8 @@ function setTimer( args: Args, repeat: boolean ): number { - // Bind `args` to the callback and bind `this` to window(global). - const callback: () => void = cb.bind(window, ...args); + // Bind `args` to the callback and bind `this` to globalThis(global). + const callback: () => void = cb.bind(globalThis, ...args); // In the browser, the delay value must be coercible to an integer between 0 // and INT32_MAX. Any other value will cause the timer to fire immediately. // We emulate this behavior. |