Add --no-prefetch cli flag

--no-prefetch will directly use `load(...)` instead of
just injecting the script sources which makes it easier to navigate
and investigate profiles.

- Support more complex command line args and flags
- Add --help to cli.js

Bug: 411303884
Change-Id: Ic4714f823a7ed1a6f1edcdbf2e00ce34786fbd9b
Reviewed-on: https://chromium-review.googlesource.com/c/external/github.com/WebKit/JetStream/+/6483190
Reviewed-by: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
diff --git a/JetStreamDriver.js b/JetStreamDriver.js
index 60641ea..a521035 100644
--- a/JetStreamDriver.js
+++ b/JetStreamDriver.js
@@ -148,8 +148,11 @@
         }
 
         async _loadInternal(url) {
-            if (!isInBrowser)
+            if (!isInBrowser) {
+                if (!globalThis.prefetchResources)
+                    return Promise.resolve(`load("${url}");`);
                 return Promise.resolve(readFile(url));
+            }
 
             let fetchResponse = await fetch(new Request(url));
             if (url.indexOf(".js") !== -1)
diff --git a/cli.js b/cli.js
index b87d92c..565fa21 100644
--- a/cli.js
+++ b/cli.js
@@ -24,6 +24,8 @@
 */
 
 globalThis.isInBrowser = false;
+globalThis.prefetchResources = true;
+
 if (typeof console === 'undefined')
     var console = {}
 if (typeof console.log === 'undefined')
@@ -52,14 +54,33 @@
 if (isSpiderMonkey)
     globalThis.readFile = readRelativeToScript;
 
+
+let cliFlags = {};
+let cliArgs = [];
+
+if (typeof arguments != "undefined" && arguments.length > 0) {
+    for (const arg of arguments) {
+        if (arg.startsWith("--")) {
+            const parts = arg.split("=");
+            cliFlags[parts[0]] = parts.slice(1).join("=");
+        } else {
+            cliArgs.push(arg);
+        }
+    }
+}
+
 if (typeof testList === "undefined") {
-    if (typeof arguments != "undefined" && arguments.length > 0) {
-        testList = arguments.slice();
+    if (cliArgs.length > 0) {
+        testList = cliArgs;
     } else {
         testList = undefined;
     }
 }
 
+if ("--no-prefetch" in cliFlags || "--noprefetch" in cliFlags)
+   globalThis.prefetchResources = false
+
+
 if (typeof testIterationCount === "undefined")
     testIterationCount = undefined;
 
@@ -78,4 +99,17 @@
         console.log("JetStream2 failed: " + e);
     }
 }
-runJetStream();
+
+if ("--help" in cliFlags) {
+    print("JetStream Driver Help")
+    print("")
+    print("Options:")
+    print("   --no-prefetch: directly use load('...') for benchmark resources.")
+    print("")
+    print("Available tests:")
+    for (const test of testPlans)
+        print("  ", test.name)
+} else {
+    print("Running tests: " + testList)
+    runJetStream();
+}
diff --git a/index.html b/index.html
index be216c4..524969c 100644
--- a/index.html
+++ b/index.html
@@ -34,6 +34,9 @@
 
     <script>
     const isInBrowser = true;
+    const isD8 = false;
+    let prefetchResources = true;
+
     var allIsGood = true;
     window.onerror = function() { allIsGood = false; }