Skip to content

Commit

Permalink
add wasm example
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaoboy committed Jul 20, 2024
1 parent e2f6d93 commit 30e0eac
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const base64 = "AGFzbQEAAAABBgFgAX8BfwMCAQAHBwEDRmliAAAKHgEcACAAQQJJBH8gAAUgAEEBaxAAIABBAmsQAGoLCwANBG5hbWUBBgEAA0ZpYg==";
const buffer = Uint8Array.from(atob(base64), c => c.charCodeAt(0));
const wasmModule = new WebAssembly.Module(buffer);
const instance = new WebAssembly.Instance(wasmModule, {});
const fib = instance.exports.Fib;
for (let i = 0; i < 10; i++) {
console.log(`fib(${i}) = ${fib(i)}`);
}

0 comments on commit 30e0eac

Please sign in to comment.