diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-01 10:54:30 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-01 11:04:58 -0800 |
commit | 9b3e915cb4e8bde6c371fcbe7dbfac1684fc0f7b (patch) | |
tree | 2fcc6bb255c1e338500373f48726f48ab25403eb /src/js | |
parent | 2f724fe14e6ad05da26ba918a826466091bc3a20 (diff) | |
download | binaryen-9b3e915cb4e8bde6c371fcbe7dbfac1684fc0f7b.tar.gz binaryen-9b3e915cb4e8bde6c371fcbe7dbfac1684fc0f7b.tar.bz2 binaryen-9b3e915cb4e8bde6c371fcbe7dbfac1684fc0f7b.zip |
wasm.js imports refactoring, and temporary flattening of imports for native wasm
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/post.js | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/js/post.js b/src/js/post.js index 7703d4a84..7f7ca9c1e 100644 --- a/src/js/post.js +++ b/src/js/post.js @@ -13,6 +13,29 @@ function integrateWasmJS(Module) { return; } + var asm2wasmImports = { // special asm2wasm imports + "f64-rem": function(x, y) { + return x % y; + }, + "f64-to-int": function(x) { + return x | 0; + }, + "debugger": function() { + debugger; + }, + }; + + function flatten(obj) { + var ret = {}; + 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]; + } + } + return ret; + } + // wasm lacks globals, so asm2wasm maps them into locations in memory. that information cannot // be present in the wasm output of asm2wasm, so we store it in a side file. If we load asm2wasm // output, either generated ahead of time or on the client, we need to apply those mapped @@ -42,10 +65,11 @@ function integrateWasmJS(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, { + var instance = WASM.instantiateModule(binary, flatten({ // XXX for now, flatten the imports "global.Math": global.Math, - "env": env - }); + "env": env, + "asm2wasm": asm2wasmImports + })); // The wasm instance creates its memory. But static init code might have written to // buffer already, and we must copy it over. @@ -91,17 +115,7 @@ function integrateWasmJS(Module) { var info = wasmJS['info'] = { global: null, env: null, - asm2wasm: { // special asm2wasm imports - "f64-rem": function(x, y) { - return x % y; - }, - "f64-to-int": function(x) { - return x | 0; - }, - "debugger": function() { - debugger; - }, - }, + asm2wasm: asm2wasmImports, parent: Module // Module inside wasm-js.cpp refers to wasm-js.cpp; this allows access to the outside program. }; |