diff options
author | Aymen Dirar | 2022-10-24 06:06:51 +0000 |
---|---|---|
committer | Aymen Dirar | 2022-10-24 06:08:17 +0000 |
commit | 81fdbeb7fa4d8a80d028a988c353c3fa16d4953b (patch) | |
tree | 743dde4e75d9c04ceb259d690f967d0a1f6b7907 /entries/adirar111/wasm/index.js | |
parent | ca09b8229ba680d5e5400ed72b121e8302990dab (diff) |
wasm lol
Diffstat (limited to 'entries/adirar111/wasm/index.js')
-rw-r--r-- | entries/adirar111/wasm/index.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/entries/adirar111/wasm/index.js b/entries/adirar111/wasm/index.js new file mode 100644 index 0000000..43ee9a6 --- /dev/null +++ b/entries/adirar111/wasm/index.js @@ -0,0 +1,21 @@ +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)) { + result.textContent = "that's not a number..." + return + } + result.textContent = fibWasm(n) + } + const button = document.getElementById("compute") + button.onclick = fib + } +); |