Created
January 9, 2017 22:16
-
-
Save zzarcon/f41cb1fddaff4097c216bf38339a296b to your computer and use it in GitHub Desktop.
WebAssembly loader
This file contains hidden or 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
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