]> Cypherpunks repositories - gostls13.git/commitdiff
misc/wasm: use "self" instead of "window" in web worker contexts
authorJohn Leidegren <john.leidegren@gmail.com>
Tue, 3 Jul 2018 10:08:37 +0000 (12:08 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 5 Jul 2018 01:42:17 +0000 (01:42 +0000)
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>
misc/wasm/wasm_exec.js

index 7246d7bc71c7a0b05ae30c7b77c4d48f43463eb2..5790effb4a9e9306c117a6dc6c82348120ef602b 100644 (file)
                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 = {