Guest User

Untitled

a guest
Apr 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. const fs = require('fs');
  2. const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
  3. const env = {
  4. 'abortStackOverflow': _ => { throw new Error('overflow'); },
  5. 'table': new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }),
  6. 'tableBase': 0,
  7. 'memory': memory,
  8. 'memoryBase': 1024,
  9. 'STACKTOP': 0,
  10. 'STACK_MAX': memory.buffer.byteLength,
  11. };
  12. const imports = { env };
  13. fs.readFile('sum.wasm', (err, bytes) => {
  14. WebAssembly.instantiate(bytes, imports).then(wa => {
  15. const exports = wa.instance.exports;
  16. const sum = exports._sum;
  17. console.log(sum(39, 3));
  18. });
  19. });
Add Comment
Please, Sign In to add comment