Initial commit
[wasm.git] / main.js
1 const memory = new WebAssembly.Memory( { initial: 2, maximum: 8 })
2 const imports = {
3         env: {
4                 __syscall1: (n, a) => console.log(n),
5                 __syscall3: (n, a, b, c) => console.log(n),
6                 __syscall5: (n, a, b, c, d, e) => console.log(n)
7         }
8 }
9
10 const sock = new WebSocket('ws://localhost:8889')
11 sock.onmessage = function (e) {
12         console.log(e.data)
13 }
14
15 function instantiate(bytes) {
16   return WebAssembly.compile(bytes).
17                 then(m => new WebAssembly.Instance(m, imports));
18 }
19
20 fetch('test.wasm')
21         .then(response => response.arrayBuffer())
22         .then(bytes => instantiate(bytes))
23         .then(instance => console.log(instance.exports.foo()));