mirror of
https://github.com/golang/go
synced 2024-11-26 18:16:48 -07:00
a0e7f12771
Edge supports WASM but not TextEncoder or TextDecoder.
This PR adds a polyfill to `misc/wasm/wasm_exec.js` to fix this.
Fixes #27295
Change-Id: Ie35ee5604529b170a5dc380eb286f71bdd691d3e
GitHub-Last-Rev: a587edae28
GitHub-Pull-Request: golang/go#27296
Reviewed-on: https://go-review.googlesource.com/131718
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
Reviewed-by: Richard Musiol <neelance@gmail.com>
49 lines
1.3 KiB
HTML
49 lines
1.3 KiB
HTML
<!doctype html>
|
|
<!--
|
|
Copyright 2018 The Go Authors. All rights reserved.
|
|
Use of this source code is governed by a BSD-style
|
|
license that can be found in the LICENSE file.
|
|
-->
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Go wasm</title>
|
|
</head>
|
|
|
|
<body>
|
|
<!--
|
|
Polyfill for TextEncoder and TextDecoder for Microsoft Edge 17/18 support
|
|
https://caniuse.com/#feat=textencoder
|
|
-->
|
|
<script src="https://cdn.jsdelivr.net/npm/text-encoding@0.7.0/lib/encoding.min.js"></script>
|
|
<script src="wasm_exec.js"></script>
|
|
<script>
|
|
if (!WebAssembly.instantiateStreaming) { // polyfill
|
|
WebAssembly.instantiateStreaming = async (resp, importObject) => {
|
|
const source = await (await resp).arrayBuffer();
|
|
return await WebAssembly.instantiate(source, importObject);
|
|
};
|
|
}
|
|
|
|
const go = new Go();
|
|
let mod, inst;
|
|
WebAssembly.instantiateStreaming(fetch("test.wasm"), go.importObject).then((result) => {
|
|
mod = result.module;
|
|
inst = result.instance;
|
|
document.getElementById("runButton").disabled = false;
|
|
}).catch((err) => {
|
|
console.error(err);
|
|
});
|
|
|
|
async function run() {
|
|
console.clear();
|
|
await go.run(inst);
|
|
inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
|
|
}
|
|
</script>
|
|
|
|
<button onClick="run();" id="runButton" disabled>Run</button>
|
|
</body>
|
|
|
|
</html> |