Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zzarcon
Created January 9, 2017 22:16
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 zzarcon/f41cb1fddaff4097c216bf38339a296b to your computer and use it in GitHub Desktop.
Save zzarcon/f41cb1fddaff4097c216bf38339a296b to your computer and use it in GitHub Desktop.
WebAssembly loader
module.exports = (filename) => {
return fetch(filename)
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.compile(buffer))
.then(module => {
const imports = {
env: {
memoryBase: 0,
tableBase: 0,
memory: new WebAssembly.Memory({
initial: 256
}),
table: new WebAssembly.Table({
initial: 0,
element: 'anyfunc'
})
}
};
return new WebAssembly.Instance(module, imports);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment