@@ -511,22 +511,23 @@ translators.set('wasm', async function(url, source) {
511511 throw err ;
512512 }
513513
514- const wasmImports = WebAssembly . Module . imports ( compiled ) ;
515- const wasmGlobalImports = ArrayPrototypeFilter ( wasmImports , ( { kind } ) => kind === 'global' ) ;
516-
517- const wasmExports = WebAssembly . Module . exports ( compiled ) ;
518- const wasmGlobalExports = new SafeSet ( ArrayPrototypeMap (
519- ArrayPrototypeFilter ( wasmExports , ( { kind } ) => kind === 'global' ) ,
520- ( { name } ) => name ,
521- ) ) ;
514+ const importsList = new SafeSet ( ) ;
515+ const wasmGlobalImports = [ ] ;
516+ for ( const impt of WebAssembly . Module . imports ( compiled ) ) {
517+ if ( impt . kind === 'global' ) ArrayPrototypePush ( wasmGlobalImports , impt ) ;
518+ importsList . add ( impt . module ) ;
519+ }
522520
523- const importsList = new SafeSet ( ArrayPrototypeMap ( wasmImports , ( { module } ) => module ) ) ;
524- const exportsList = ArrayPrototypeMap ( wasmExports , ( { name } ) => name ) ;
521+ const exportsList = new SafeSet ( ) ;
522+ const wasmGlobalExports = new SafeSet ( ) ;
523+ for ( const expt of WebAssembly . Module . exports ( compiled ) ) {
524+ if ( expt . kind === 'global' ) ArrayPrototypePush ( wasmGlobalExports , expt . name ) ;
525+ exportsList . add ( expt . name ) ;
526+ }
525527
526- const createDynamicModule = require (
527- 'internal/modules/esm/create_dynamic_module' ) ;
528+ const createDynamicModule = require ( 'internal/modules/esm/create_dynamic_module' ) ;
528529
529- const { module } = createDynamicModule ( [ ... importsList ] , exportsList , url , ( reflect ) => {
530+ const { module } = createDynamicModule ( importsList , exportsList , url , ( reflect ) => {
530531 for ( const impt of importsList ) {
531532 const importNs = reflect . imports [ impt ] ;
532533 const wasmInstance = wasmInstances . get ( importNs ) ;
@@ -544,18 +545,17 @@ translators.set('wasm', async function(url, source) {
544545 }
545546 }
546547 // In cycles importing unexecuted Wasm, wasmInstance will be undefined, which will fail during
547- // instantiation, since all bindings will be in TDZ.
548+ // instantiation, since all bindings will be in the Temporal Deadzone ( TDZ) .
548549 const { exports } = new WebAssembly . Instance ( compiled , reflect . imports ) ;
549550 wasmInstances . set ( module . getNamespace ( ) , exports ) ;
550551 for ( const expt of exportsList ) {
551552 let val = exports [ expt ] ;
552553 // Unwrap WebAssembly.Global for JS bindings
553554 if ( wasmGlobalExports . has ( expt ) ) {
554- // v128 doesn't support ToJsValue() -> undefined (ideally should stay in TDZ)
555555 try {
556556 val = val . value ;
557557 } catch {
558- val = undefined ;
558+ // v128 doesn't support ToJsValue() -> undefined (ideally should stay in TDZ)
559559 continue ;
560560 }
561561 }
0 commit comments