Skip to content

Instantly share code, notes, and snippets.

@zzarcon
Created Jan 9, 2017
Embed
What would you like to do?
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