From d5239f9ca17afc88d18184161c80f4b0f1d7e929 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Wed, 22 May 2019 03:33:45 -0400 Subject: [PATCH] esm: basic wasm module env --- lib/internal/modules/esm/translators.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 4ca9be4d622faa..6effdb8391be83 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -159,11 +159,25 @@ translators.set('wasm', async function(url) { } const imports = - WebAssembly.Module.imports(compiled).map(({ module }) => module); + WebAssembly.Module.imports(compiled).map(({ module }) => module).filter((module) => module != 'env'); const exports = WebAssembly.Module.exports(compiled).map(({ name }) => name); return createDynamicModule(imports, exports, url, (reflect) => { - const { exports } = new WebAssembly.Instance(compiled, reflect.imports); + const env = { + __memory_base: 0, + memory: new WebAssembly.Memory({ + initial: 512 + }), + __table_base: 0, + table: new WebAssembly.Table({ + initial: 0, + element: 'anyfunc' + }) + }; + const { exports } = new WebAssembly.Instance(compiled, { + ...reflect.imports, + env + }); for (const expt of Object.keys(exports)) reflect.exports[expt].set(exports[expt]); });