Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
esm: sync-ify module translation
This completes the TODO to compile WASM synchronously and thus
making translation (i.e. compilation + instantiation) synchronous.
  • Loading branch information
joyeecheung committed Aug 12, 2025
commit 0443ae7398b5d2269272e595054b85f6b3642d00
6 changes: 4 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class ModuleLoader {
* matching translators.
* @param {ModuleSource} source Source of the module to be translated.
* @param {boolean} isMain Whether the module to be translated is the entry point.
* @returns {ModuleWrap | Promise<ModuleWrap>}
* @returns {ModuleWrap}
*/
#translate(url, format, source, isMain) {
this.validateLoadResult(url, format);
Expand All @@ -547,7 +547,9 @@ class ModuleLoader {
throw new ERR_UNKNOWN_MODULE_FORMAT(format, url);
}

return FunctionPrototypeCall(translator, this, url, source, isMain);
const result = FunctionPrototypeCall(translator, this, url, source, isMain);
assert(result instanceof ModuleWrap);
return result;
}

/**
Expand Down
10 changes: 3 additions & 7 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,15 @@
* >} [[Instance]] slot proxy for WebAssembly Module Record
*/
const wasmInstances = new SafeWeakMap();
translators.set('wasm', async function(url, source) {
translators.set('wasm', function(url, source) {
assertBufferSource(source, false, 'load');

debug(`Translating WASMModule ${url}`);

let compiled;
try {
// TODO(joyeecheung): implement a translator that just uses
// compiled = new WebAssembly.Module(source) to compile it
// synchronously.
compiled = await WebAssembly.compile(source, {
// The ESM Integration auto-enables Wasm JS builtins by default when available.
builtins: ['js-string'],
compiled = new WebAssembly.Module(source, {
builtins: ['js-string']

Check failure on line 505 in lib/internal/modules/esm/translators.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});
} catch (err) {
err.message = errPath(url) + ': ' + err.message;
Expand Down
Loading