aboutsummaryrefslogtreecommitdiff
path: root/entries/adirar111/wasm/index.js
diff options
context:
space:
mode:
authorfunemy2022-10-25 07:14:52 +0000
committerfunemy2022-10-25 07:14:52 +0000
commit998ef837b43203319397f191036a97a5adc42220 (patch)
tree920558bd60d282c663fd2da1cd4144cac1849a1d /entries/adirar111/wasm/index.js
parentfdac6c60e115297a58f5b81da0c4b7f18ac758f2 (diff)
parentce7544a6db594f7d3dfad0d7dc65d01515e57ad6 (diff)
Merge branch 'main' of github.com:braxtonhall/fib
Diffstat (limited to 'entries/adirar111/wasm/index.js')
-rw-r--r--entries/adirar111/wasm/index.js23
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
+ }
+);