forked from WebKit/JetStream
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparams.js
More file actions
170 lines (147 loc) · 6.53 KB
/
params.js
File metadata and controls
170 lines (147 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"use strict";
/*
* Copyright (C) 2025 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
const defaultEmptyMap = Object.freeze({});
class Params {
// Enable a detailed developer menu to change the current Params.
developerMode = false;
startAutomatically = false;
report = false;
startDelay = undefined;
testList = [];
testIterationCount = undefined;
testWorstCaseCount = undefined;
prefetchResources = true;
// Display group details.
groupDetails = false
RAMification = false;
dumpJSONResults = false;
dumpTestList = false;
// Override iteration and worst-case counts per workload.
// Example:
// testIterationCountMap = { "acorn-wtb": 5 };
testIterationCountMap = defaultEmptyMap;
testWorstCaseCountMap = defaultEmptyMap;
customPreIterationCode = undefined;
customPostIterationCode = undefined;
constructor(sourceParams = undefined) {
if (sourceParams)
this._copyFromSearchParams(sourceParams);
if (!this.developerMode)
Object.freeze(this);
}
_copyFromSearchParams(sourceParams) {
this.startAutomatically = this._parseBooleanParam(sourceParams, "startAutomatically");
this.developerMode = this._parseBooleanParam(sourceParams, "developerMode");
this.report = this._parseBooleanParam(sourceParams, "report");
this.prefetchResources = this._parseBooleanParam(sourceParams, "prefetchResources");
this.RAMification = this._parseBooleanParam(sourceParams, "RAMification");
this.dumpJSONResults = this._parseBooleanParam(sourceParams, "dumpJSONResults");
this.groupDetails = this._parseBooleanParam(sourceParams, "groupDetails");
this.dumpTestList = this._parseBooleanParam(sourceParams, "dumpTestList");
this.customPreIterationCode = this._parseStringParam(sourceParams, "customPreIterationCode");
this.customPostIterationCode = this._parseStringParam(sourceParams, "customPostIterationCode");
this.startDelay = this._parseIntParam(sourceParams, "startDelay", 0);
if (!this.startDelay) {
if (this.report)
this.startDelay = 4000;
if (this.startAutomatically)
this.startDelay = 100;
}
for (const paramKey of ["tag", "tags", "test", "tests"])
this.testList = this._parseTestListParam(sourceParams, paramKey);
this.testIterationCount = this._parseIntParam(sourceParams, "iterationCount", 1);
this.testWorstCaseCount = this._parseIntParam(sourceParams, "worstCaseCount", 1);
const unused = Array.from(sourceParams.keys());
if (unused.length > 0)
console.error("Got unused source params", unused);
}
_parseTestListParam(sourceParams, key) {
if (!sourceParams.has(key))
return this.testList;
let testList = [];
if (sourceParams?.getAll) {
testList = sourceParams?.getAll(key);
} else {
// fallback for cli sourceParams which is just a Map;
testList = sourceParams.get(key).split(",");
}
sourceParams.delete(key);
if (this.testList.length > 0 && testList.length > 0)
throw new Error(`Overriding previous testList='${this.testList.join()}' with ${key} url-parameter.`);
return testList;
}
_parseStringParam(sourceParams, paramKey) {
if (!sourceParams.has(paramKey))
return DefaultJetStreamParams[paramKey];
const value = sourceParams.get(paramKey);
sourceParams.delete(paramKey);
return value;
}
_parseBooleanParam(sourceParams, paramKey) {
if (!sourceParams.has(paramKey))
return DefaultJetStreamParams[paramKey];
const value = sourceParams.get(paramKey).toLowerCase();
sourceParams.delete(paramKey);
return !(value === "false" || value === "0");
}
_parseIntParam(sourceParams, paramKey, minValue) {
if (!sourceParams.has(paramKey))
return DefaultJetStreamParams[paramKey];
const parsedValue = this._parseInt(sourceParams.get(paramKey), paramKey);
if (parsedValue < minValue)
throw new Error(`Invalid ${paramKey} param: '${parsedValue}', value must be >= ${minValue}.`);
sourceParams.delete(paramKey);
return parsedValue;
}
_parseInt(value, errorMessage) {
const number = Number(value);
if (!Number.isInteger(number) && errorMessage)
throw new Error(`Invalid ${errorMessage} param: '${value}', expected int.`);
return parseInt(number);
}
get isDefault() {
return this === DefaultJetStreamParams;
}
get nonDefaultParams() {
const diff = Object.create(null);
for (const [key, value] of Object.entries(this)) {
if (value !== DefaultJetStreamParams[key]) {
diff[key] = value;
}
}
return diff;
}
}
const DefaultJetStreamParams = new Params();
let maybeCustomParams = DefaultJetStreamParams;
if (globalThis?.JetStreamParamsSource) {
try {
maybeCustomParams = new Params(globalThis?.JetStreamParamsSource);
} catch (e) {
console.error("Invalid Params", e, "\nUsing defaults as fallback:", maybeCustomParams);
}
}
const JetStreamParams = maybeCustomParams;