Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] esm: basic wasm module env #27815

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
Expand Down