summaryrefslogtreecommitdiffstats
path: root/misc/wasm/wasm_exec.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:23:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:23:18 +0000
commit43a123c1ae6613b3efeed291fa552ecd909d3acf (patch)
treefd92518b7024bc74031f78a1cf9e454b65e73665 /misc/wasm/wasm_exec.html
parentInitial commit. (diff)
downloadgolang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.tar.xz
golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.zip
Adding upstream version 1.20.14.upstream/1.20.14upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc/wasm/wasm_exec.html')
-rw-r--r--misc/wasm/wasm_exec.html49
1 files changed, 49 insertions, 0 deletions
diff --git a/misc/wasm/wasm_exec.html b/misc/wasm/wasm_exec.html
new file mode 100644
index 0000000..72e6447
--- /dev/null
+++ b/misc/wasm/wasm_exec.html
@@ -0,0 +1,49 @@
+<!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="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> \ No newline at end of file