esm: sync-ify module translation
Some checks failed
Coverage Windows / coverage-windows (push) Waiting to run
Coverage Linux (without intl) / coverage-linux-without-intl (push) Failing after 1m30s
Test and upload documentation to artifacts / build-docs (push) Failing after 5m28s
Linters / format-cpp (push) Has been skipped
Linters / lint-cpp (push) Successful in 3m56s
Linters / lint-py (push) Successful in 3m3s
Linters / lint-sh (push) Failing after 1m52s
Linters / lint-pr-url (push) Has been skipped
Linters / lint-readme (push) Successful in 1m27s
Notify on Push / Notify on Force Push on `main` (push) Has been skipped
Notify on Push / Notify on Push on `main` that lacks metadata (push) Has been skipped
Scorecard supply-chain security / Scorecard analysis (push) Failing after 52s
Coverage Linux / coverage-linux (push) Failing after 57s
Linters / lint-addon-docs (push) Successful in 2m6s
Linters / lint-yaml (push) Successful in 2m42s
Linters / lint-codeowners (push) Failing after 59s
Linters / lint-js-and-md (push) Successful in 13m14s

This completes the TODO to compile WASM synchronously and thus
making translation (i.e. compilation + instantiation) synchronous.

PR-URL: https://github.com/nodejs/node/pull/59453
Refs: https://github.com/nodejs/node/issues/55782
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
Joyee Cheung 2025-08-14 16:28:40 +02:00 committed by GitHub
parent 91f035e597
commit af5d1c93ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 8 deletions

View file

@ -537,7 +537,7 @@ class ModuleLoader {
* matching translators. * matching translators.
* @param {ModuleSource} source Source of the module to be translated. * @param {ModuleSource} source Source of the module to be translated.
* @param {boolean} isMain Whether the module to be translated is the entry point. * @param {boolean} isMain Whether the module to be translated is the entry point.
* @returns {ModuleWrap | Promise<ModuleWrap>} * @returns {ModuleWrap}
*/ */
#translate(url, format, source, isMain) { #translate(url, format, source, isMain) {
this.validateLoadResult(url, format); this.validateLoadResult(url, format);
@ -547,7 +547,9 @@ class ModuleLoader {
throw new ERR_UNKNOWN_MODULE_FORMAT(format, url); 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;
} }
/** /**

View file

@ -494,18 +494,14 @@ translators.set('json', function jsonStrategy(url, source) {
* >} [[Instance]] slot proxy for WebAssembly Module Record * >} [[Instance]] slot proxy for WebAssembly Module Record
*/ */
const wasmInstances = new SafeWeakMap(); const wasmInstances = new SafeWeakMap();
translators.set('wasm', async function(url, source) { translators.set('wasm', function(url, source) {
assertBufferSource(source, false, 'load'); assertBufferSource(source, false, 'load');
debug(`Translating WASMModule ${url}`); debug(`Translating WASMModule ${url}`);
let compiled; let compiled;
try { try {
// TODO(joyeecheung): implement a translator that just uses compiled = new WebAssembly.Module(source, {
// 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'], builtins: ['js-string'],
}); });
} catch (err) { } catch (err) {