summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-01 19:57:03 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-01 19:57:03 -0800
commitd96c63dc0e6b0a9ccf0c327d8c6c0cb61f95d57f (patch)
tree828b1a47c2078fe7ec60c162fc57c2aa03e8cccf /src/js
parent90304bf9703e768fcdf87914e6117f87beea3f59 (diff)
downloadbinaryen-d96c63dc0e6b0a9ccf0c327d8c6c0cb61f95d57f.tar.gz
binaryen-d96c63dc0e6b0a9ccf0c327d8c6c0cb61f95d57f.tar.bz2
binaryen-d96c63dc0e6b0a9ccf0c327d8c6c0cb61f95d57f.zip
refactor a lookupImport method
Diffstat (limited to 'src/js')
-rw-r--r--src/js/post.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/js/post.js b/src/js/post.js
index fe9e1b516..c9e29f6e8 100644
--- a/src/js/post.js
+++ b/src/js/post.js
@@ -31,12 +31,29 @@
parent: Module // Module inside wasm-js.cpp refers to wasm-js.cpp; this allows access to the outside program.
};
+ wasmJS['lookupImport'] = function(mod, base) {
+ var lookup = info;
+ if (mod.indexOf('.') < 0) {
+ lookup = (lookup || {})[mod];
+ } else {
+ var parts = mod.split('.');
+ lookup = (lookup || {})[parts[0]];
+ lookup = (lookup || {})[parts[1]];
+ }
+ lookup = (lookup || {})[base];
+ if (!lookup) {
+ abort('bad CallImport to (' + mod + ').' + base);
+ }
+ return lookup;
+ }
+
// The asm.js function, called to "link" the asm.js module.
Module['asm'] = function(global, env, buffer) {
assert(buffer === theBuffer); // we should not even need to pass it as a 3rd arg for wasm, but that's the asm.js way.
// write the provided data to a location the wasm instance can get at it.
info.global = global;
info.env = env;
+ wasmJS['_load_mapped_globals'](); // now that we have global and env, we can ready the provided imported globals, copying them to their mapped locations.
return wasmJS['asmExports'];
};
})();