Skip to content

Commit 5ff312f

Browse files
committed
Address review comments
1 parent b382dc5 commit 5ff312f

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

JetStreamDriver.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ if (!isInBrowser && globalThis.prefetchResources) {
9292
}
9393

9494
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`");
9696

9797
// Used for the promise representing the current benchmark run.
9898
this.currentResolve = null;
@@ -209,9 +209,8 @@ function isCompressed(name) {
209209
}
210210

211211
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);
215214
}
216215

217216
// TODO: Cleanup / remove / merge. This is only used for caching loads in the
@@ -674,7 +673,7 @@ class Scripts {
674673
class ShellScripts extends Scripts {
675674
constructor() {
676675
super();
677-
this.prefetchedResources = [];
676+
this.prefetchedResources = Object.create(null);;
678677
}
679678

680679
run() {
@@ -711,12 +710,9 @@ class ShellScripts extends Scripts {
711710
globalObject.ShellTextDecoder = TextDecoder;
712711
// Store shellPrefetchedResources on ShellPrefetchedResources so that
713712
// 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;
718714
} else {
719-
console.assert(this.prefetchedResources.length === 0, "Unexpected prefetched resources");
715+
console.assert(Object.values(this.prefetchedResources).length === 0, "Unexpected prefetched resources");
720716
}
721717

722718
globalObject.performance ??= performance;
@@ -727,7 +723,9 @@ class ShellScripts extends Scripts {
727723
}
728724

729725
addPrefetchedResources(prefetchedResources) {
730-
this.prefetchedResources.push(...prefetchedResources);
726+
for (let [file, bytes] of Object.entries(prefetchedResources)) {
727+
this.prefetchedResources[file] = bytes;
728+
}
731729
}
732730

733731
add(text) {
@@ -1140,11 +1138,9 @@ class Benchmark {
11401138

11411139
console.assert(this.preloads === null, "This initialization should be called only once.");
11421140
this.preloads = [];
1143-
this.shellPrefetchedResources = [];
1141+
this.shellPrefetchedResources = Object.create(null);
11441142
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)) {
11481144
const compressed = isCompressed(file);
11491145
if (compressed && !globalThis.prefetchResources) {
11501146
file = uncompressedName(file);
@@ -1155,7 +1151,7 @@ class Benchmark {
11551151
if (compressed) {
11561152
bytes = zlib.decompress(bytes);
11571153
}
1158-
this.shellPrefetchedResources.push([file, bytes]);
1154+
this.shellPrefetchedResources[file] = bytes;
11591155
}
11601156

11611157
this.preloads.push([name, file]);
@@ -1400,14 +1396,14 @@ class AsyncBenchmark extends DefaultBenchmark {
14001396
} else {
14011397
str += `
14021398
JetStream.getBinary = async function(path) {
1403-
if (ShellPrefetchedResources) {
1399+
if ("ShellPrefetchedResources" in globalThis) {
14041400
return ShellPrefetchedResources[path];
14051401
}
14061402
return new Int8Array(read(path, "binary"));
14071403
};
14081404
14091405
JetStream.getString = async function(path) {
1410-
if (ShellPrefetchedResources) {
1406+
if ("ShellPrefetchedResources" in globalThis) {
14111407
return new ShellTextDecoder().decode(ShellPrefetchedResources[path]);
14121408
}
14131409
return read(path);

0 commit comments

Comments
 (0)