Code
webassembly
// Imports provided to a WASM module
const importObject = {
env: {
consoleLog: (value) => console.log("from wasm:", value),
now: () => Date.now(),
memory: new WebAssembly.Memory({ initial: 1 }),
},
};
const { instance } = await WebAssembly.instantiate(bytes, importObject);
// Exports can be functions, memory, tables, or globals
const { add, multiply, memory, __heap_base } = instance.exports;
console.log(add(2, 3)); // 5
console.log(multiply(4, 5)); // 20
console.log("heap starts at", __heap_base);