Skip to content

Instantly share code, notes, and snippets.

@campoy
Created April 12, 2018 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save campoy/3359edd9b8d4ba6f1b991502864a7622 to your computer and use it in GitHub Desktop.
Save campoy/3359edd9b8d4ba6f1b991502864a7622 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
const env = {
'abortStackOverflow': _ => { throw new Error('overflow'); },
'table': new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }),
'tableBase': 0,
'memory': memory,
'memoryBase': 1024,
'STACKTOP': 0,
'STACK_MAX': memory.buffer.byteLength,
};
const imports = { env };
fs.readFile('sum.wasm', (err, bytes) => {
WebAssembly.instantiate(bytes, imports).then(wa => {
const exports = wa.instance.exports;
const sum = exports._sum;
console.log(sum(39, 3));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment