summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/js/wasm.js-post.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js
index bdb825573..75a91d4d4 100644
--- a/src/js/wasm.js-post.js
+++ b/src/js/wasm.js-post.js
@@ -45,7 +45,9 @@ function integrateWasmJS(Module) {
for (var x in obj) {
for (var y in obj[x]) {
if (ret[y]) Module['printErr']('warning: flatten dupe: ' + y);
- ret[y] = obj[x][y];
+ if (typeof obj[x][y] === 'function') {
+ ret[y] = obj[x][y];
+ }
}
}
return ret;
@@ -90,21 +92,27 @@ function integrateWasmJS(Module) {
}
}
- if (typeof WASM === 'object') {
+ if (typeof WASM === 'object' || typeof wasmEval === 'function') {
// Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate
// 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 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, flatten({ // XXX for now, flatten the imports
+ var importObj = {
"global.Math": global.Math,
"env": env,
"asm2wasm": asm2wasmImports
- }));
-
+ };
+ var instance;
+ if (typeof WASM === 'object') {
+ instance = WASM.instantiateModule(binary, flatten(importObj));
+ } else if (typeof wasmEval === 'function') {
+ instance = wasmEval(binary.buffer, importObj);
+ } else {
+ throw 'how to wasm?';
+ }
mergeMemory(instance.memory);
applyMappedGlobals();