summaryrefslogtreecommitdiff
path: root/js/timers.ts
diff options
context:
space:
mode:
authorjustjavac <justjavac@gmail.com>2019-06-11 15:50:36 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-06-11 10:09:33 -0400
commitcb581620522febe618cbf084b0dc3428479e84a9 (patch)
tree0cc7d6f4f0c626921b8cee13db5a8af87ef8e433 /js/timers.ts
parent0efb7c2ab7b9705a9f5f177b4dc170c1abbd97ed (diff)
set setTimeout callback's this to window object
Diffstat (limited to 'js/timers.ts')
-rw-r--r--js/timers.ts5
1 files changed, 3 insertions, 2 deletions
diff --git a/js/timers.ts b/js/timers.ts
index 9a595973c..1e8bb428d 100644
--- a/js/timers.ts
+++ b/js/timers.ts
@@ -3,6 +3,7 @@ import { assert } from "./util";
import * as msg from "gen/cli/msg_generated";
import * as flatbuffers from "./flatbuffers";
import { sendAsync, sendSync } from "./dispatch";
+import { window } from "./window";
interface Timer {
id: number;
@@ -186,8 +187,8 @@ function setTimer(
args: Args,
repeat: boolean
): number {
- // If any `args` were provided (which is uncommon), bind them to the callback.
- const callback: () => void = args.length === 0 ? cb : cb.bind(null, ...args);
+ // Bind `args` to the callback and bind `this` to window(global).
+ const callback: () => void = cb.bind(window, ...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.