-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (29 loc) · 1.13 KB
/
index.js
File metadata and controls
31 lines (29 loc) · 1.13 KB
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
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
let mod, inst;
const go = new Go();
async function load(scriptName) {
document.getElementById("runButton").setAttribute("hidden", "");
WebAssembly.instantiateStreaming(fetch(scriptName), go.importObject).then((result) => {
mod = result.module;
inst = result.instance;
document.getElementById("runButton").removeAttribute("hidden");
document.getElementById("loadButton").disabled = true;
}).catch((err) => {
console.error(err);
document.getElementById("errorText").innerHTML = err
document.getElementById("errorText").removeAttribute("hidden")
setTimeout(() => {
document.getElementById("errorText").setAttribute("hidden", "")
}, 3000);
});
}
async function run() {
console.clear();
await go.run(inst);
inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
}