aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorRichard Musiol <mail@richard-musiol.de>2020-10-11 10:23:45 +0200
committerRichard Musiol <neelance@gmail.com>2020-10-21 13:19:35 +0000
commit54c0237346adfc2cac7bbebba80d652227ab6ea5 (patch)
tree21dcf1c45f990cc6583d2201249f110c4d918055 /misc
parent9848e93cb76f068b97e8ea342c33cc09b553790f (diff)
downloadgo-54c0237346adfc2cac7bbebba80d652227ab6ea5.tar.gz
go-54c0237346adfc2cac7bbebba80d652227ab6ea5.zip
misc/wasm: improve error message if javascript polyfills are required
wasm_exec.js expects that either "require" is available or that the globals "crypto", "TextEncoder" and "TextDecoder" are already defined. Report a better error message if this is not the case, suggesting the use of a polyfill. Updates #41482 Change-Id: I5473cae15c98ae42e39f5928245b7762e7a5a8bf Reviewed-on: https://go-review.googlesource.com/c/go/+/261357 Trust: Richard Musiol <neelance@gmail.com> Run-TryBot: Richard Musiol <neelance@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'misc')
-rw-r--r--misc/wasm/wasm_exec.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js
index 06b6062a2e..3ea03c45b7 100644
--- a/misc/wasm/wasm_exec.js
+++ b/misc/wasm/wasm_exec.js
@@ -102,7 +102,7 @@
}
}
- if (!global.crypto) {
+ if (!global.crypto && global.require) {
const nodeCrypto = require("crypto");
global.crypto = {
getRandomValues(b) {
@@ -110,6 +110,9 @@
},
};
}
+ if (!global.crypto) {
+ throw new Error("global.crypto is not available, polyfill required (getRandomValues only)");
+ }
if (!global.performance) {
global.performance = {
@@ -120,13 +123,19 @@
};
}
- if (!global.TextEncoder) {
+ if (!global.TextEncoder && global.require) {
global.TextEncoder = require("util").TextEncoder;
}
+ if (!global.TextEncoder) {
+ throw new Error("global.TextEncoder is not available, polyfill required");
+ }
- if (!global.TextDecoder) {
+ if (!global.TextDecoder && global.require) {
global.TextDecoder = require("util").TextDecoder;
}
+ if (!global.TextDecoder) {
+ throw new Error("global.TextDecoder is not available, polyfill required");
+ }
// End of polyfills for common API.