Debian Codegraph @

misc/wasm/wasm_exec.html

raw
1 <!doctype html>
2 <!--
3 Copyright 2018 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file.
6 -->
7 <html>
8
9 <head>
10 <meta charset="utf-8">
11 <title>Go wasm</title>
12 </head>
13
14 <body>
15 <!--
16 Add the following polyfill for Microsoft Edge 17/18 support:
17 <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/encoding.min.js"></script>
18 (see https://caniuse.com/#feat=textencoder)
19 -->
20 <script src="../../lib/wasm/wasm_exec.js"></script>
21 <script>
22 if (!WebAssembly.instantiateStreaming) { // polyfill
23 WebAssembly.instantiateStreaming = async (resp, importObject) => {
24 const source = await (await resp).arrayBuffer();
25 return await WebAssembly.instantiate(source, importObject);
26 };
27 }
28
29 const go = new Go();
30 let mod, inst;
31 WebAssembly.instantiateStreaming(fetch("test.wasm"), go.importObject).then((result) => {
32 mod = result.module;
33 inst = result.instance;
34 document.getElementById("runButton").disabled = false;
35 }).catch((err) => {
36 console.error(err);
37 });
38
39 async function run() {
40 console.clear();
41 await go.run(inst);
42 inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
43 }
44 </script>
45
46 <button onClick="run();" id="runButton" disabled>Run</button>
47 </body>
48
49 </html>