Skip to content

Commit b56d8af

Browse files
joyeecheungtargos
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 <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>
1 parent dd5f835 commit b56d8af

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

‎lib/internal/modules/esm/loader.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class ModuleLoader {
537537
* matching translators.
538538
* @param {ModuleSource} source Source of the module to be translated.
539539
* @param {boolean} isMain Whether the module to be translated is the entry point.
540-
* @returns {ModuleWrap | Promise<ModuleWrap>}
540+
* @returns {ModuleWrap}
541541
*/
542542
#translate(url,format,source,isMain){
543543
this.validateLoadResult(url,format);
@@ -547,7 +547,9 @@ class ModuleLoader {
547547
thrownewERR_UNKNOWN_MODULE_FORMAT(format,url);
548548
}
549549

550-
returnFunctionPrototypeCall(translator,this,url,source,isMain);
550+
constresult=FunctionPrototypeCall(translator,this,url,source,isMain);
551+
assert(resultinstanceofModuleWrap);
552+
returnresult;
551553
}
552554

553555
/**

‎lib/internal/modules/esm/translators.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,18 +494,14 @@ translators.set('json', function jsonStrategy(url, source) {
494494
* >} [[Instance]] slot proxy for WebAssembly Module Record
495495
*/
496496
constwasmInstances=newSafeWeakMap();
497-
translators.set('wasm',asyncfunction(url,source){
497+
translators.set('wasm',function(url,source){
498498
assertBufferSource(source,false,'load');
499499

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

502502
letcompiled;
503503
try{
504-
// TODO(joyeecheung): implement a translator that just uses
505-
// compiled = new WebAssembly.Module(source) to compile it
506-
// synchronously.
507-
compiled=awaitWebAssembly.compile(source,{
508-
// The ESM Integration auto-enables Wasm JS builtins by default when available.
504+
compiled=newWebAssembly.Module(source,{
509505
builtins: ['js-string'],
510506
});
511507
}catch(err){

0 commit comments

Comments
 (0)