mirror of
https://github.com/golang/go
synced 2024-11-15 00:50:32 -07:00
6781ff226d
Fixes #68024
Change-Id: I730c3ecfb14472f3eea3895c2a4d5e1d4ac146f5
GitHub-Last-Rev: 4242f36010
GitHub-Pull-Request: golang/go#68840
Reviewed-on: https://go-review.googlesource.com/c/go/+/604696
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
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>
|
|
<!--
|
|
Add the following polyfill for Microsoft Edge 17/18 support:
|
|
<script src="https://cdn.jsdelivr.net/npm/text-encoding@0.7.0/lib/encoding.min.js"></script>
|
|
(see https://caniuse.com/#feat=textencoder)
|
|
-->
|
|
<script src="../../lib/wasm/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> |