summaryrefslogtreecommitdiff
path: root/src/wasm-js.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-12-27 21:42:44 -0500
committerGitHub <noreply@github.com>2016-12-27 21:42:44 -0500
commit575d695762f545e1c2784595d9c926488062f383 (patch)
tree5f18013a7cb2fa39c7a62aa11b2753e86725477c /src/wasm-js.cpp
parente5704f392404b1f69d762217b89e3b8736277f08 (diff)
parent97968a879d0b55baccb5f72627fca84a6a015356 (diff)
downloadbinaryen-575d695762f545e1c2784595d9c926488062f383.tar.gz
binaryen-575d695762f545e1c2784595d9c926488062f383.tar.bz2
binaryen-575d695762f545e1c2784595d9c926488062f383.zip
Merge pull request #859 from WebAssembly/linking
Dynamic linking
Diffstat (limited to 'src/wasm-js.cpp')
-rw-r--r--src/wasm-js.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index e5032264a..2735f84f8 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -227,9 +227,18 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() {
Address offset = ConstantExpressionRunner(instance.globals).visit(segment.offset).value.geti32();
assert(offset + segment.data.size() <= wasm.table.initial);
for (size_t i = 0; i != segment.data.size(); ++i) {
- EM_ASM_({
- Module['outside']['wasmTable'][$0] = $1;
- }, offset + i, wasm.getFunction(segment.data[i]));
+ Name name = segment.data[i];
+ auto* func = wasm.checkFunction(name);
+ if (func) {
+ EM_ASM_({
+ Module['outside']['wasmTable'][$0] = $1;
+ }, offset + i, func);
+ } else {
+ auto* import = wasm.getImport(name);
+ EM_ASM_({
+ Module['outside']['wasmTable'][$0] = Module['lookupImport'](Pointer_stringify($1), Pointer_stringify($2));
+ }, offset + i, import->module.str, import->base.str);
+ }
}
}
}