Created
April 12, 2018 18:53
-
-
Save campoy/3359edd9b8d4ba6f1b991502864a7622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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