bare.js (677B)
1 const fs = require('fs'); 2 3 const memory = new WebAssembly.Memory({initial: 2}); 4 const table = new WebAssembly.Table({initial: 3, element: 'anyfunc'}); 5 const importsObj = { 6 env: { 7 memory: memory, 8 __linear_memory: memory, 9 __indirect_function_table: table, 10 call_me_sometime: (n) => { 11 let a = new Uint8Array(memory.buffer, n, 9) 12 a.set([0x66, 0x6f, 0x6f], 0); 13 console.debug('heap is at: ' + n); 14 console.log('heap contains: ' + new TextDecoder().decode(a)); 15 }, 16 }, 17 } 18 19 async function init() { 20 const code = fs.readFileSync('./bare.wasm'); 21 const m = new WebAssembly.Module(code); 22 const i = new WebAssembly.Instance(m, importsObj); 23 i.exports.foo(); 24 } 25 init();