Created
April 22, 2017 01:16
-
-
Save WA9ACE/3076325cf95595ff0cb345795f3fd95c to your computer and use it in GitHub Desktop.
Hello World WASM bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", main) | |
function log(offset, length) { | |
const bytes = new Uint8Array(memory.buffer, offset, length) | |
const string = new TextDecoder('utf8').decode(bytes) | |
console.log(string) | |
} | |
var memory = new WebAssembly.Memory({ initial : 20 }); | |
const exposed = { | |
stdlib: { print: log }, | |
js: { mem: memory } | |
} | |
function main(event) { | |
fetch('hello.wasm').then(response => | |
response.arrayBuffer() | |
).then(bytes => | |
WebAssembly.instantiate(bytes, exposed) | |
).then(result => | |
result.instance.exports.main() | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment