-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
59 lines (53 loc) · 1.43 KB
/
index.html
File metadata and controls
59 lines (53 loc) · 1.43 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Run wasm64 in Chrome</title>
</head>
<body>
<h1>wasm64 test</h1>
<pre id="out"></pre>
<script>
let sharedMemory = null;
const out = document.getElementById("out");
function write(s) {
out.textContent += s + "\n";
console.log(s);
}
const imports = {
host: {
host_print: (ptr, len) => {
const p = Number(ptr); // ptr is BigInt
const l = Number(len);
if (!sharedMemory) {
write("ERROR: no memory yet");
return;
}
const bytes = new Uint8Array(sharedMemory.buffer, p, l);
const s = new TextDecoder().decode(bytes);
write(s);
},
},
};
(async () => {
try {
const { instance } = await WebAssembly.instantiateStreaming(
fetch(
"hello-world-wasm64/target/wasm64-unknown-unknown/release/hello_world_wasm64.wasm"
),
imports
);
sharedMemory = instance.exports.memory;
if (typeof instance.exports.run === "function") {
instance.exports.run();
} else {
write("no run() export found");
}
} catch (e) {
write("instantiate error: " + e);
console.error(e);
}
})();
</script>
</body>
</html>