]> Cypherpunks repositories - gostls13.git/commitdiff
misc/wasm: improve error message if javascript polyfills are required
authorRichard Musiol <mail@richard-musiol.de>
Sun, 11 Oct 2020 08:23:45 +0000 (10:23 +0200)
committerRichard Musiol <neelance@gmail.com>
Wed, 21 Oct 2020 13:19:35 +0000 (13:19 +0000)
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>
misc/wasm/wasm_exec.js

index 06b6062a2e0cdd4d5c81935862bf84778e8c4f56..3ea03c45b7ebf43f1f0a8673e56498ab78fd2a39 100644 (file)
                }
        }
 
-       if (!global.crypto) {
+       if (!global.crypto && global.require) {
                const nodeCrypto = require("crypto");
                global.crypto = {
                        getRandomValues(b) {
                        },
                };
        }
+       if (!global.crypto) {
+               throw new Error("global.crypto is not available, polyfill required (getRandomValues only)");
+       }
 
        if (!global.performance) {
                global.performance = {
                };
        }
 
-       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.