diff options
| author | John Leidegren <john.leidegren@gmail.com> | 2018-07-03 12:08:37 +0200 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-07-05 01:42:17 +0000 |
| commit | 9e5fe6baf1dfd8ea7ba1456845a7e1f7256eeeaa (patch) | |
| tree | 8a18505de2a9f095d4bf6a45a8827953c347bbd4 /misc/wasm/wasm_exec.js | |
| parent | 7145f1c7c7dcd4506f2819166f073e92f57afbb7 (diff) | |
| download | go-9e5fe6baf1dfd8ea7ba1456845a7e1f7256eeeaa.tar.xz | |
misc/wasm: use "self" instead of "window" in web worker contexts
There is no "window" global in a web worker context. Use "self" instead.
Fixes #26192
Change-Id: I6c6f3db6c3d3d9ca00a473f8c18b849bc07a0017
Reviewed-on: https://go-review.googlesource.com/122055
Run-TryBot: Richard Musiol <neelance@gmail.com>
Reviewed-by: Richard Musiol <neelance@gmail.com>
Diffstat (limited to 'misc/wasm/wasm_exec.js')
| -rw-r--r-- | misc/wasm/wasm_exec.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index 7246d7bc71..5790effb4a 100644 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -27,7 +27,13 @@ global.TextEncoder = util.TextEncoder; global.TextDecoder = util.TextDecoder; } else { - window.global = window; + if (typeof window !== "undefined") { + window.global = window; + } else if (typeof self !== "undefined") { + self.global = self; + } else { + throw new Error("cannot export Go (neither window nor self is defined)"); + } let outputBuf = ""; global.fs = { |
