blob: 7b135308bf42527e8c51b2f4baaa234771700349 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<!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">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Go wasm</title>
<script src="eruda.js"></script>
<script>eruda.init();</script>
</head>
<body>
<script src="js/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;
let url = new URLSearchParams(window.location.search).get("wasm");
if (!url) {
// url = "dummy-ui/dummy-ui.wasm";
// url = "client/client.wasm";
url = "ai-companion.wasm";
}
WebAssembly.instantiateStreaming(fetch(url), go.importObject).then((result) => {
document.getElementById("wasmName").innerHTML = url;
mod = result.module;
inst = result.instance;
document.getElementById("runButton").disabled = false;
}).catch((err) => {
console.error(err);
});
async function run() {
let wN = document.getElementById("wasmName");
let rB = document.getElementById("runButton");
document.body.removeChild(wN);
document.body.removeChild(rB);
console.clear();
await go.run(inst);
}
</script>
<div style="width:0; height:0; overflow:hidden;">
<input id="hiddenInput"></input>
</div>
<div id="wasmName"></div>
<button onClick="run();" id="runButton" disabled>Run</button>
</body>
</html>
|