diff options
author | James Yoo | 2022-10-24 23:47:51 +0000 |
---|---|---|
committer | James Yoo | 2022-10-24 23:47:51 +0000 |
commit | 03315f012514bdcc5a4f654056f0103abe11eb83 (patch) | |
tree | 2b7c6e9233ecb503e7be0d8354483691f9a1e16c /entries/adirar111/wasm/index.js | |
parent | 0921d8222bb883ea86d51c7200a865a5e4dbc469 (diff) | |
parent | 7ed13a92711a35a9c263c1f53e33e308653ae727 (diff) |
Merging local with remote main
Diffstat (limited to 'entries/adirar111/wasm/index.js')
-rw-r--r-- | entries/adirar111/wasm/index.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/entries/adirar111/wasm/index.js b/entries/adirar111/wasm/index.js new file mode 100644 index 0000000..667ff82 --- /dev/null +++ b/entries/adirar111/wasm/index.js @@ -0,0 +1,23 @@ +const wasmBinaryBase64 = "AGFzbQEAAAABBgFgAX8BfwMCAQAHBwEDZmliAAAKRwFFAQR/IABBAkgEQCAADwtBACEBQQEhAkECIQMgAEEBaiEAA0AgAiEEIAIgAWohAiAEIQEgA0EBaiEDIAMgAEgNAAsgAg8LACgEbmFtZQEGAQADZmliAhkBAAUAAW4BBGxhc3QCA3N1bQMBaQQDdG1w" +const wasmBinaryDataURL = `data:application/wasm;base64,${wasmBinaryBase64}`; + +WebAssembly.instantiateStreaming(fetch(wasmBinaryDataURL)).then( + (wasmObj) => { + const {fib: fibWasm} = wasmObj.instance.exports + const fib = (event) => { + event.preventDefault() + const input = document.getElementById("input") + const result = document.getElementById("result") + const n = parseInt(input.value) + if (isNaN(n)) { + return result.textContent = "that wasn't very wasm of you" + } + if (n < 0) { + return result.textContent = "why are you being so negative" + } + result.textContent = fibWasm(n) + } + const button = document.getElementById("compute") + button.onclick = fib + } +); |