Advertisement
Guest User

JavaScript WASM Demo

a guest
Jul 29th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (async function() {
  2.     const wasm = new Uint8Array([
  3.         0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60, 0x02, 0x7f, 0x7f, 0x01,
  4.         0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0a, 0x01, 0x06, 0x61, 0x64, 0x64, 0x54, 0x77, 0x6f, 0x00,
  5.         0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b, 0x00, 0x0e, 0x04, 0x6e,
  6.         0x61, 0x6d, 0x65, 0x02, 0x07, 0x01, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00]);
  7.  
  8.     const lib = await WebAssembly.instantiate(wasm).
  9.         then(res => res.instance.exports);
  10.  
  11.     console.log(lib.addTwo(2, 2));
  12. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement