aboutsummaryrefslogtreecommitdiff
path: root/entries/adirar111/wasm/index.js
diff options
context:
space:
mode:
authorBraxton Hall2022-10-24 06:34:55 +0000
committerGitHub2022-10-24 06:34:55 +0000
commit15c8967ec8074f3c7272ac7107847e3bb4539e99 (patch)
tree267674dd842fc69fd8a0481ef780693719237dbc /entries/adirar111/wasm/index.js
parentca09b8229ba680d5e5400ed72b121e8302990dab (diff)
parent5e2b3d53917bb6a39dbffd0db6888bacaa283536 (diff)
Merge pull request #17 from adirar111/main
wasm
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
+ }
+);