@@ -201,11 +201,13 @@ const fileLoader = (function() {
201201} ) ( ) ;
202202
203203class Driver {
204- constructor ( ) {
204+ constructor ( benchmarks ) {
205205 this . isReady = false ;
206206 this . isDone = false ;
207207 this . errors = [ ] ;
208- this . benchmarks = new Set ( ) ;
208+ // Make benchmark list unique and sort it.
209+ this . benchmarks = Array . from ( new Set ( benchmarks ) ) ;
210+ this . benchmarks . sort ( ( a , b ) => a . plan . name . toLowerCase ( ) < b . plan . name . toLowerCase ( ) ? 1 : - 1 ) ;
209211 // TODO: Cleanup / remove / merge `blobDataCache` and `loadCache` vs.
210212 // the global `fileLoader` cache.
211213 this . blobDataCache = { } ;
@@ -216,36 +218,6 @@ class Driver {
216218 this . counter . failedPreloadResources = 0 ;
217219 }
218220
219- enableBenchmark ( benchmark ) {
220- // TODO: Remove, make `this.benchmarks` immutable and set it once in the
221- // ctor instead of this and the global `addBenchmarksBy*` functions.
222- this . benchmarks . add ( benchmark ) ;
223- }
224-
225- enableBenchmarksByName ( name ) {
226- const benchmark = benchmarksByName . get ( name . toLowerCase ( ) ) ;
227-
228- if ( ! benchmark )
229- throw new Error ( `Couldn't find benchmark named "${ name } "` ) ;
230-
231- this . enableBenchmark ( benchmark ) ;
232- }
233-
234- enableBenchmarksByTag ( tag , excludeTags ) {
235- const benchmarks = benchmarksByTag . get ( tag . toLowerCase ( ) ) ;
236-
237- if ( ! benchmarks ) {
238- const validTags = Array . from ( benchmarksByTag . keys ( ) ) . join ( ", " ) ;
239- throw new Error ( `Couldn't find tag named: ${ tag } .\n Choices are ${ validTags } ` ) ;
240- }
241-
242- for ( const benchmark of benchmarks ) {
243- if ( excludeTags && benchmark . hasAnyTag ( ...excludeTags ) )
244- continue
245- this . enableBenchmark ( benchmark ) ;
246- }
247- }
248-
249221 async start ( ) {
250222 let statusElement = false ;
251223 let summaryElement = false ;
@@ -451,15 +423,9 @@ class Driver {
451423 } ) ;
452424 }
453425
454- initializeBenchmarks ( ) {
455- this . benchmarks = Array . from ( this . benchmarks ) ;
456- this . benchmarks . sort ( ( a , b ) => a . plan . name . toLowerCase ( ) < b . plan . name . toLowerCase ( ) ? 1 : - 1 ) ;
457- }
458-
459426 async initialize ( ) {
460427 if ( isInBrowser )
461428 window . addEventListener ( "error" , ( e ) => this . pushError ( "driver startup" , e . error ) ) ;
462- this . initializeBenchmarks ( ) ;
463429 await this . prefetchResources ( ) ;
464430 this . prepareToRun ( ) ;
465431 this . isReady = true ;
@@ -2273,34 +2239,62 @@ for (const benchmark of BENCHMARKS) {
22732239 }
22742240}
22752241
2276- this . JetStream = new Driver ( ) ;
2277-
22782242
22792243function processTestList ( testList )
22802244{
22812245 let benchmarkNames = [ ] ;
2246+ let benchmarks = [ ] ;
22822247
22832248 if ( testList instanceof Array )
22842249 benchmarkNames = testList ;
22852250 else
22862251 benchmarkNames = testList . split ( / [ \s , ] / ) ;
22872252
2288- for ( let name of benchmarkNames ) {
2289- name = name . toLowerCase ( ) ;
2253+ for ( const name of benchmarkNames ) {
22902254 if ( benchmarksByTag . has ( name ) )
2291- globalThis . JetStream . enableBenchmarksByTag ( name ) ;
2255+ benchmarks . push ( ... findBenchmarksByTag ( name ) ) ;
22922256 else
2293- globalThis . JetStream . enableBenchmarksByName ( name ) ;
2257+ benchmarks . push ( findBenchmarkByName ( name ) ) ;
22942258 }
2259+ return benchmarks ;
2260+ }
2261+
2262+
2263+ function findBenchmarkByName ( name ) {
2264+ const benchmark = benchmarksByName . get ( name . toLowerCase ( ) ) ;
2265+
2266+ if ( ! benchmark )
2267+ throw new Error ( `Couldn't find benchmark named "${ name } "` ) ;
2268+
2269+ return benchmark ;
22952270}
22962271
2272+
2273+ function findBenchmarksByTag ( tag , excludeTags ) {
2274+ let benchmarks = benchmarksByTag . get ( tag . toLowerCase ( ) ) ;
2275+ if ( ! benchmarks ) {
2276+ const validTags = Array . from ( benchmarksByTag . keys ( ) ) . join ( ", " ) ;
2277+ throw new Error ( `Couldn't find tag named: ${ tag } .\n Choices are ${ validTags } ` ) ;
2278+ }
2279+ if ( excludeTags ) {
2280+ benchmarks = benchmarks . filter ( benchmark => {
2281+ return ! benchmark . hasAnyTag ( ...excludeTags ) ;
2282+ } ) ;
2283+ }
2284+ return benchmarks ;
2285+ }
2286+
2287+
2288+ let benchmarks = [ ] ;
22972289const defaultDisabledTags = [ ] ;
22982290// FIXME: add better support to run Worker tests in shells.
22992291if ( ! isInBrowser )
23002292 defaultDisabledTags . push ( "WorkerTests" ) ;
23012293
23022294if ( globalThis . testList ?. length ) {
2303- processTestList ( globalThis . testList ) ;
2295+ benchmarks = processTestList ( globalThis . testList ) ;
23042296} else {
2305- globalThis . JetStream . enableBenchmarksByTag ( "Default" , defaultDisabledTags )
2297+ benchmarks = findBenchmarksByTag ( "Default" , defaultDisabledTags )
23062298}
2299+
2300+ this . JetStream = new Driver ( benchmarks ) ;
0 commit comments