diff options
Diffstat (limited to 'static/blog/tos_2/wasm_exec.html')
| -rw-r--r-- | static/blog/tos_2/wasm_exec.html | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/static/blog/tos_2/wasm_exec.html b/static/blog/tos_2/wasm_exec.html new file mode 100644 index 0000000..38d5b6f --- /dev/null +++ b/static/blog/tos_2/wasm_exec.html @@ -0,0 +1,53 @@ +<!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>The voice of god</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) + --> + <link rel="stylesheet" href="https://unpkg.com/xterm/dist/xterm.css" /> + <script src="https://unpkg.com/xterm/dist/xterm.js"></script> + <h1>The voice of <code>god</code></h1> + <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("god.wasm"), go.importObject).then((result) => { + mod = result.module; + inst = result.instance; + document.getElementById("runButton").disabled = false; + }).catch((err) => { + console.error(err); + }); + + async function run() { + await go.run(inst); + inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance + } + </script> + + <button onClick="run();" id="runButton" disabled>Run</button> + + <div id="terminal"></div> +</body> + +</html> |
