1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<html>
<body>
<script>
const bytes = new Uint8Array([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60,
0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01, 0x03,
0x66, 0x69, 0x62, 0x00, 0x00, 0x0a, 0x1f, 0x01, 0x1d, 0x00, 0x20, 0x00,
0x41, 0x02, 0x48, 0x04, 0x40, 0x41, 0x01, 0x0f, 0x0b, 0x20, 0x00, 0x41,
0x02, 0x6b, 0x10, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6b, 0x10, 0x00, 0x6a,
0x0f, 0x0b
]);
WebAssembly.compile(bytes)
.then(module => WebAssembly.instantiate(module))
.then(instance => instance.exports.fib(10))
.then(value => console.log("Calculated fib(10) with wasm and got " + value))
.catch(err => console.log(err.message));
</script>
</body>
</html>
|