@@ -905,8 +905,11 @@ class Benchmark {
905905 }
906906 if ( this . plan . preload ) {
907907 let preloadCode = "" ;
908- for ( let [ variableName , blobURLOrPath ] of this . preloads )
908+ for ( let [ variableName , blobURLOrPath ] of this . preloads ) {
909+ console . assert ( variableName ?. length > 0 , "Invalid preload name." ) ;
910+ console . assert ( blobURLOrPath ?. length > 0 , "Invalid preload data." ) ;
909911 preloadCode += `JetStream.preload[${ JSON . stringify ( variableName ) } ] = "${ blobURLOrPath } ";\n` ;
912+ }
910913 scripts . add ( preloadCode ) ;
911914 }
912915
@@ -1060,8 +1063,8 @@ class Benchmark {
10601063
10611064 if ( this . plan . preload ) {
10621065 this . preloads = [ ] ;
1063- for ( let prop of Object . getOwnPropertyNames ( this . plan . preload ) ) {
1064- promises . push ( this . loadBlob ( "preload" , prop , this . plan . preload [ prop ] ) . then ( ( blobData ) => {
1066+ for ( const [ name , resource ] of Object . entries ( this . plan . preload ) ) {
1067+ promises . push ( this . loadBlob ( "preload" , name , resource ) . then ( ( blobData ) => {
10651068 if ( ! globalThis . allIsGood )
10661069 return ;
10671070 this . preloads . push ( [ blobData . prop , blobData . blobURL ] ) ;
@@ -1070,7 +1073,7 @@ class Benchmark {
10701073 // We'll try again later in retryPrefetchResourceForBrowser(). Don't throw an error.
10711074 if ( ! this . failedPreloads )
10721075 this . failedPreloads = { } ;
1073- this . failedPreloads [ prop ] = true ;
1076+ this . failedPreloads [ name ] = true ;
10741077 JetStream . counter . failedPreloadResources ++ ;
10751078 } ) ) ;
10761079 }
@@ -1127,9 +1130,8 @@ class Benchmark {
11271130 }
11281131
11291132 if ( this . plan . preload ) {
1130- for ( const prop of Object . getOwnPropertyNames ( this . plan . preload ) ) {
1131- const resource = this . plan . preload [ prop ] ;
1132- const allDone = await this . retryPrefetchResource ( "preload" , prop , resource ) ;
1133+ for ( const [ name , resource ] of Object . entries ( this . plan . preload ) ) {
1134+ const allDone = await this . retryPrefetchResource ( "preload" , name , resource ) ;
11331135 if ( allDone )
11341136 return true ; // All resources loaded, nothing more to do.
11351137 }
@@ -1149,21 +1151,21 @@ class Benchmark {
11491151 if ( ! this . plan . preload ) {
11501152 return ;
11511153 }
1152- for ( let [ name , file ] of Object . entries ( this . plan . preload ) ) {
1153- const compressed = isCompressed ( file ) ;
1154+ for ( let [ name , resource ] of Object . entries ( this . plan . preload ) ) {
1155+ const compressed = isCompressed ( resource ) ;
11541156 if ( compressed && ! JetStreamParams . prefetchResources ) {
1155- file = uncompressedName ( file ) ;
1157+ resource = uncompressedName ( resource ) ;
11561158 }
11571159
11581160 if ( JetStreamParams . prefetchResources ) {
1159- let bytes = new Int8Array ( read ( file , "binary" ) ) ;
1161+ let bytes = new Int8Array ( read ( resource , "binary" ) ) ;
11601162 if ( compressed ) {
11611163 bytes = zlib . decompress ( bytes ) ;
11621164 }
1163- this . shellPrefetchedResources [ file ] = bytes ;
1165+ this . shellPrefetchedResources [ resource ] = bytes ;
11641166 }
11651167
1166- this . preloads . push ( [ name , file ] ) ;
1168+ this . preloads . push ( [ name , resource ] ) ;
11671169 }
11681170 }
11691171
@@ -1753,10 +1755,10 @@ class WasmLegacyBenchmark extends Benchmark {
17531755 }
17541756
17551757 str += "};\n" ;
1756-
1757- const keys = Object . keys ( this . plan . preload ) ;
1758- for ( let i = 0 ; i < keys . length ; ++ i ) {
1759- str += `JetStream.loadBlob(" ${ keys [ i ] } " , "${ this . plan . preload [ keys [ i ] ] } ", () => {\n` ;
1758+ let preloadCount = 0 ;
1759+ for ( const [ name , resource ] of Object . entries ( this . plan . preload ) ) {
1760+ preloadCount ++ ;
1761+ str += `JetStream.loadBlob(${ JSON . stringify ( name ) } , "${ resource } ", () => {\n` ;
17601762 }
17611763 if ( this . plan . async ) {
17621764 str += `doRun().catch((e) => {
@@ -1767,7 +1769,7 @@ class WasmLegacyBenchmark extends Benchmark {
17671769 } else {
17681770 str += `doRun();`
17691771 }
1770- for ( let i = 0 ; i < keys . length ; ++ i ) {
1772+ for ( let i = 0 ; i < preloadCount ; ++ i ) {
17711773 str += `})` ;
17721774 }
17731775 str += `;` ;
0 commit comments