Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8c4dcd5

Browse filesBrowse 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 <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 85b8d25 commit 8c4dcd5
Copy full SHA for 8c4dcd5

File tree

Expand file treeCollapse file tree

2 files changed

+6
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-7
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/loader.js
+4-2Lines 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
/**
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/translators.js
+2-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.