From 97968a879d0b55baccb5f72627fca84a6a015356 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 7 Dec 2016 14:08:41 -1000 Subject: handle imports in tables in interpreter --- src/wasm-js.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') 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); + } } } } -- cgit v1.2.3