@@ -220,6 +220,7 @@ impl ComponentGenerator for Js {
220220 // bindings is the actual `instantiate` method itself, created by this
221221 // structure.
222222 let mut instantiator = Instantiator {
223+ name,
223224 src : Source :: default ( ) ,
224225 gen : self ,
225226 modules,
@@ -434,7 +435,7 @@ impl Js {
434435 _fs = _fs || await import('fs/promises');
435436 return WebAssembly.compile(await _fs.readFile(url));
436437 }
437- return fetch(url).then(WebAssembly.compile );
438+ return fetch(url).then(WebAssembly.compileStreaming );
438439 }
439440 " )
440441 } else {
@@ -684,6 +685,7 @@ impl Js {
684685///
685686/// This is the main structure for parsing the output of Wasmtime.
686687struct Instantiator < ' a > {
688+ name : & ' a str ,
687689 src : Source ,
688690 gen : & ' a mut Js ,
689691 modules : & ' a PrimaryMap < StaticModuleIndex , ModuleTranslation < ' a > > ,
@@ -707,6 +709,7 @@ impl Instantiator<'_> {
707709
708710 // Setup the compilation promises
709711 let mut first = true ;
712+ let mut multiple = false ;
710713 for init in self . component . initializers . iter ( ) {
711714 if let GlobalInitializer :: InstantiateModule ( InstantiateModule :: Static ( idx, _) ) = init {
712715 // Get the compiled WebAssembly.Module objects in parallel
@@ -715,9 +718,12 @@ impl Instantiator<'_> {
715718 self . src . js . push_str ( "\n " ) ;
716719 }
717720 first = false ;
721+ } else {
722+ multiple = true ;
718723 }
724+
719725 let local_name = format ! ( "module{}" , idx. as_u32( ) ) ;
720- let name = format ! ( "module{}.wasm" , idx. as_u32 ( ) ) ;
726+ let name = self . gen . core_file_name ( & self . name , * idx) ;
721727 if self . gen . opts . instantiation {
722728 uwrite ! (
723729 self . src. js,
@@ -735,7 +741,7 @@ impl Instantiator<'_> {
735741
736742 // To avoid uncaught promise rejection errors, we attach an intermediate
737743 // Promise.all with a rejection handler, if there are multiple promises.
738- if first == false {
744+ if multiple {
739745 first = true ;
740746 self . src . js . push_str ( "Promise.all([" ) ;
741747 for init in self . component . initializers . iter ( ) {
0 commit comments