@@ -92,7 +92,7 @@ if (!isInBrowser && globalThis.prefetchResources) {
92
92
}
93
93
94
94
if ( ! globalThis . prefetchResources )
95
- console . warn ( "Disabling resource prefetching! All compressed files must have been decompressed using `node utils/compress.mjs -d`" ) ;
95
+ console . warn ( "Disabling resource prefetching! All compressed files must have been decompressed using `node utils/compress.mjs -d -k `" ) ;
96
96
97
97
// Used for the promise representing the current benchmark run.
98
98
this . currentResolve = null ;
@@ -209,9 +209,8 @@ function isCompressed(name) {
209
209
}
210
210
211
211
function uncompressedName ( name ) {
212
- if ( name . endsWith ( ".z" ) )
213
- return name . slice ( 0 , - 2 ) ;
214
- return name ;
212
+ console . assert ( isCompressed ( name ) ) ;
213
+ return name . slice ( 0 , - 2 ) ;
215
214
}
216
215
217
216
// TODO: Cleanup / remove / merge. This is only used for caching loads in the
@@ -674,7 +673,7 @@ class Scripts {
674
673
class ShellScripts extends Scripts {
675
674
constructor ( ) {
676
675
super ( ) ;
677
- this . prefetchedResources = [ ] ;
676
+ this . prefetchedResources = Object . create ( null ) ; ;
678
677
}
679
678
680
679
run ( ) {
@@ -711,12 +710,9 @@ class ShellScripts extends Scripts {
711
710
globalObject . ShellTextDecoder = TextDecoder ;
712
711
// Store shellPrefetchedResources on ShellPrefetchedResources so that
713
712
// getBinary and getString can find them.
714
- globalObject . ShellPrefetchedResources = { } ;
715
- for ( const [ name , value ] of this . prefetchedResources ) {
716
- globalObject . ShellPrefetchedResources [ name ] = value ;
717
- }
713
+ globalObject . ShellPrefetchedResources = this . prefetchedResources ;
718
714
} else {
719
- console . assert ( this . prefetchedResources . length === 0 , "Unexpected prefetched resources" ) ;
715
+ console . assert ( Object . values ( this . prefetchedResources ) . length === 0 , "Unexpected prefetched resources" ) ;
720
716
}
721
717
722
718
globalObject . performance ??= performance ;
@@ -727,7 +723,9 @@ class ShellScripts extends Scripts {
727
723
}
728
724
729
725
addPrefetchedResources ( prefetchedResources ) {
730
- this . prefetchedResources . push ( ...prefetchedResources ) ;
726
+ for ( let [ file , bytes ] of Object . entries ( prefetchedResources ) ) {
727
+ this . prefetchedResources [ file ] = bytes ;
728
+ }
731
729
}
732
730
733
731
add ( text ) {
@@ -1140,11 +1138,9 @@ class Benchmark {
1140
1138
1141
1139
console . assert ( this . preloads === null , "This initialization should be called only once." ) ;
1142
1140
this . preloads = [ ] ;
1143
- this . shellPrefetchedResources = [ ] ;
1141
+ this . shellPrefetchedResources = Object . create ( null ) ;
1144
1142
if ( this . plan . preload ) {
1145
- for ( let name of Object . getOwnPropertyNames ( this . plan . preload ) ) {
1146
- let file = this . plan . preload [ name ] ;
1147
-
1143
+ for ( let [ name , file ] of Object . entries ( this . plan . preload ) ) {
1148
1144
const compressed = isCompressed ( file ) ;
1149
1145
if ( compressed && ! globalThis . prefetchResources ) {
1150
1146
file = uncompressedName ( file ) ;
@@ -1155,7 +1151,7 @@ class Benchmark {
1155
1151
if ( compressed ) {
1156
1152
bytes = zlib . decompress ( bytes ) ;
1157
1153
}
1158
- this . shellPrefetchedResources . push ( [ file , bytes ] ) ;
1154
+ this . shellPrefetchedResources [ file ] = bytes ;
1159
1155
}
1160
1156
1161
1157
this . preloads . push ( [ name , file ] ) ;
@@ -1400,14 +1396,14 @@ class AsyncBenchmark extends DefaultBenchmark {
1400
1396
} else {
1401
1397
str += `
1402
1398
JetStream.getBinary = async function(path) {
1403
- if (ShellPrefetchedResources) {
1399
+ if (" ShellPrefetchedResources" in globalThis ) {
1404
1400
return ShellPrefetchedResources[path];
1405
1401
}
1406
1402
return new Int8Array(read(path, "binary"));
1407
1403
};
1408
1404
1409
1405
JetStream.getString = async function(path) {
1410
- if (ShellPrefetchedResources) {
1406
+ if (" ShellPrefetchedResources" in globalThis ) {
1411
1407
return new ShellTextDecoder().decode(ShellPrefetchedResources[path]);
1412
1408
}
1413
1409
return read(path);
0 commit comments