summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-21 20:47:00 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-21 20:47:00 -0800
commit021e145f74b217aa83d088d3da32692c79fcc80d (patch)
treea1f9154b0eb49d4871f377d721c309755564718b /src
parent54c460ea4e4d23cdba56c2d5f1d3407cf5f676d9 (diff)
downloadbinaryen-021e145f74b217aa83d088d3da32692c79fcc80d.tar.gz
binaryen-021e145f74b217aa83d088d3da32692c79fcc80d.tar.bz2
binaryen-021e145f74b217aa83d088d3da32692c79fcc80d.zip
simplify wasm.js loading code, since we are now embedded where we can use the outside module's
Diffstat (limited to 'src')
-rw-r--r--src/js/post.js36
1 files changed, 6 insertions, 30 deletions
diff --git a/src/js/post.js b/src/js/post.js
index a4a80ddd1..5a2bc7922 100644
--- a/src/js/post.js
+++ b/src/js/post.js
@@ -5,31 +5,15 @@ function integrateWasmJS(Module) {
// the wasm module at that time, and it receives imports and provides exports and so forth, the app
// doesn't need to care that it is wasm and not asm.
Module['asm'] = function(global, env, providedBuffer) {
- // Load the binary wasm module
- var filename = Module['wasmCodeFile'];
- var binary;
- if (typeof read === 'function') {
- // spidermonkey or v8 shells
- if (typeof readbuffer === 'function') {
- binary = new Uint8Array(readbuffer(filename));
- } else {
- binary = read(f, 'binary');
- }
- } else if (typeof process === 'object' && typeof require === 'function') {
- // node.js
- binary = require('fs')['readFileSync'](filename);
- if (!binary.buffer) { // handle older node.js not returning a proper typed array
- binary = new Uint8Array(ret);
- }
- } else {
- throw 'TODO: binary loading in other platforms';
- }
- assert(binary.buffer);
+ // Load the wasm module
+ var binary = Module['readBinary'](Module['wasmCodeFile']);
+
// Create an instance of the module using native support in the JS engine.
var instance = WASM.instantiateModule(binary, {
"global.Math": global.Math,
"env": env
});
+
// The wasm instance creates its memory. But static init code might have written to
// buffer already, and we must copy it over.
// TODO: avoid this copy, by avoiding such static init writes
@@ -43,6 +27,7 @@ function integrateWasmJS(Module) {
Module['reallocBuffer'] = function(size) {
abort('no memory growth quite yet, but easy to add');
};
+
return instance;
};
return;
@@ -94,16 +79,7 @@ function integrateWasmJS(Module) {
assert(providedBuffer === Module['buffer']); // we should not even need to pass it as a 3rd arg for wasm, but that's the asm.js way.
// Generate a module instance of the asm.js converted into wasm.
- var code;
- if (typeof read === 'function') {
- // spidermonkey or v8 shells
- code = read(Module['asmjsCodeFile']);
- } else if (typeof process === 'object' && typeof require === 'function') {
- // node.js
- code = require('fs')['readFileSync'](Module['asmjsCodeFile']).toString();
- } else {
- throw 'TODO: loading in other platforms';
- }
+ var code = Module['read'](Module['asmjsCodeFile']);
// wasm code would create its own buffer, at this time. But static init code might have
// written to the buffer already, and we must copy it over. We could just avoid