Skip to content

Commit 8c4dcd5

Browse files
joyeecheungrichardlau
authored andcommitted
esm: sync-ify module translation
This completes the TODO to compile WASM synchronously and thus making translation (i.e. compilation + instantiation) synchronous. PR-URL: #59453 Refs: #55782 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 85b8d25 commit 8c4dcd5

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/internal/modules/esm/loader.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class ModuleLoader {
527527
* matching translators.
528528
* @param {ModuleSource} source Source of the module to be translated.
529529
* @param {boolean} isMain Whether the module to be translated is the entry point.
530-
* @returns {ModuleWrap | Promise<ModuleWrap>}
530+
* @returns {ModuleWrap}
531531
*/
532532
#translate(url, format, source, isMain) {
533533
this.validateLoadResult(url, format);
@@ -537,7 +537,9 @@ class ModuleLoader {
537537
throw new ERR_UNKNOWN_MODULE_FORMAT(format, url);
538538
}
539539

540-
return FunctionPrototypeCall(translator, this, url, source, isMain);
540+
const result = FunctionPrototypeCall(translator, this, url, source, isMain);
541+
assert(result instanceof ModuleWrap);
542+
return result;
541543
}
542544

543545
/**

lib/internal/modules/esm/translators.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,14 @@ translators.set('json', function jsonStrategy(url, source) {
432432
* >} [[Instance]] slot proxy for WebAssembly Module Record
433433
*/
434434
const wasmInstances = new SafeWeakMap();
435-
translators.set('wasm', async function(url, source) {
435+
translators.set('wasm', function(url, source) {
436436
assertBufferSource(source, false, 'load');
437437

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

440440
let compiled;
441441
try {
442-
// TODO(joyeecheung): implement a translator that just uses
443-
// compiled = new WebAssembly.Module(source) to compile it
444-
// synchronously.
445-
compiled = await WebAssembly.compile(source, {
442+
compiled = new WebAssembly.Module(source, {
446443
builtins: ['js-string'],
447444
});
448445
} catch (err) {

0 commit comments

Comments
 (0)