Skip to content

Commit 9e5fe6b

Browse files
leidegrebradfitz
authored andcommitted
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 golang#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>
1 parent 7145f1c commit 9e5fe6b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

misc/wasm/wasm_exec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
global.TextEncoder = util.TextEncoder;
2828
global.TextDecoder = util.TextDecoder;
2929
} else {
30-
window.global = window;
30+
if (typeof window !== "undefined") {
31+
window.global = window;
32+
} else if (typeof self !== "undefined") {
33+
self.global = self;
34+
} else {
35+
throw new Error("cannot export Go (neither window nor self is defined)");
36+
}
3137

3238
let outputBuf = "";
3339
global.fs = {

0 commit comments

Comments
 (0)