Skip to content

Commit 3575bca

Browse files
committed
Convert classes in motionmark.js and debug-runner.js to JS class syntax.
1 parent 0904796 commit 3575bca

File tree

2 files changed

+55
-53
lines changed

2 files changed

+55
-53
lines changed

MotionMark/resources/debug-runner/debug-runner.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,35 @@
2222
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
25-
ProgressBar = Utilities.createClass(
26-
function(element, ranges)
25+
26+
class ProgressBar {
27+
constructor(element, ranges)
2728
{
2829
this._element = element;
2930
this._ranges = ranges;
3031
this._currentRange = 0;
3132
this._updateElement();
32-
}, {
33+
}
3334

34-
_updateElement: function()
35+
_updateElement()
3536
{
3637
this._element.style.width = (this._currentRange * (100 / this._ranges)) + "%";
37-
},
38+
}
3839

39-
incrementRange: function()
40+
incrementRange()
4041
{
4142
++this._currentRange;
4243
this._updateElement();
4344
}
44-
});
45+
}
4546

46-
DeveloperResultsTable = Utilities.createSubclass(ResultsTable,
47-
function(element, headers)
47+
class DeveloperResultsTable extends ResultsTable {
48+
constructor(element, headers)
4849
{
49-
ResultsTable.call(this, element, headers);
50-
}, {
50+
super(element, headers);
51+
}
5152

52-
_addGraphButton: function(td, testName, testResult, testData)
53+
_addGraphButton(td, testName, testResult, testData)
5354
{
5455
var button = Utilities.createElement("button", { class: "small-button" }, td);
5556
button.textContent = Strings.text.graph + "…";
@@ -60,9 +61,9 @@ DeveloperResultsTable = Utilities.createSubclass(ResultsTable,
6061
button.addEventListener("click", function(e) {
6162
benchmarkController.showTestGraph(e.target.testName, e.target.testResult, e.target.testData);
6263
});
63-
},
64+
}
6465

65-
_isNoisyMeasurement: function(jsonExperiment, data, measurement, options)
66+
_isNoisyMeasurement(jsonExperiment, data, measurement, options)
6667
{
6768
const percentThreshold = 10;
6869
const averageThreshold = 2;
@@ -74,9 +75,9 @@ DeveloperResultsTable = Utilities.createSubclass(ResultsTable,
7475
return Math.abs(data[Strings.json.measurements.average] - options["frame-rate"]) >= averageThreshold;
7576

7677
return false;
77-
},
78+
}
7879

79-
_addTest: function(testName, testResult, options, testData)
80+
_addTest(testName, testResult, options, testData)
8081
{
8182
var row = Utilities.createElement("tr", {}, this.element);
8283

@@ -120,7 +121,7 @@ DeveloperResultsTable = Utilities.createSubclass(ResultsTable,
120121
td.textContent = header.text(testResult);
121122
}, this);
122123
}
123-
});
124+
}
124125

125126
Utilities.extendObject(window.benchmarkRunnerClient, {
126127
testsCount: null,

MotionMark/resources/runner/motionmark.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Apple Inc. All rights reserved.
2+
* Copyright (C) 2018-2024 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -22,8 +22,9 @@
2222
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
25-
ResultsDashboard = Utilities.createClass(
26-
function(version, options, testData)
25+
26+
class ResultsDashboard {
27+
constructor(version, options, testData)
2728
{
2829
this._iterationsSamplers = [];
2930
this._options = options;
@@ -35,14 +36,14 @@
3536
this._iterationsSamplers = testData;
3637
this._processData();
3738
}
38-
}, {
39+
}
3940

40-
push: function(suitesSamplers)
41+
push(suitesSamplers)
4142
{
4243
this._iterationsSamplers.push(suitesSamplers);
43-
},
44+
}
4445

45-
_processData: function()
46+
_processData()
4647
{
4748
this._results = {};
4849
this._results[Strings.json.results.iterations] = [];
@@ -89,9 +90,9 @@
8990
this._results[Strings.json.score] = Statistics.sampleMean(iterationsScores.length, iterationsScores.reduce(function(a, b) { return a + b; }));
9091
this._results[Strings.json.scoreLowerBound] = this._results[Strings.json.results.iterations][0][Strings.json.scoreLowerBound];
9192
this._results[Strings.json.scoreUpperBound] = this._results[Strings.json.results.iterations][0][Strings.json.scoreUpperBound];
92-
},
93+
}
9394

94-
calculateScore: function(data)
95+
calculateScore(data)
9596
{
9697
var result = {};
9798
data[Strings.json.result] = result;
@@ -250,57 +251,57 @@
250251
result[Strings.json.scoreLowerBound] = result[Strings.json.score] - averageFrameLength.standardDeviation();
251252
result[Strings.json.scoreUpperBound] = result[Strings.json.score] + averageFrameLength.standardDeviation();
252253
}
253-
},
254+
}
254255

255256
get data()
256257
{
257258
return this._iterationsSamplers;
258-
},
259+
}
259260

260261
get results()
261262
{
262263
if (this._results)
263264
return this._results[Strings.json.results.iterations];
264265
this._processData();
265266
return this._results[Strings.json.results.iterations];
266-
},
267+
}
267268

268269
get options()
269270
{
270271
return this._options;
271-
},
272+
}
272273

273274
get version()
274275
{
275276
return this._version;
276-
},
277+
}
277278

278-
_getResultsProperty: function(property)
279+
_getResultsProperty(property)
279280
{
280281
if (this._results)
281282
return this._results[property];
282283
this._processData();
283284
return this._results[property];
284-
},
285+
}
285286

286287
get score()
287288
{
288289
return this._getResultsProperty(Strings.json.score);
289-
},
290+
}
290291

291292
get scoreLowerBound()
292293
{
293294
return this._getResultsProperty(Strings.json.scoreLowerBound);
294-
},
295+
}
295296

296297
get scoreUpperBound()
297298
{
298299
return this._getResultsProperty(Strings.json.scoreUpperBound);
299300
}
300-
});
301+
}
301302

302-
ResultsTable = Utilities.createClass(
303-
function(element, headers)
303+
class ResultsTable {
304+
constructor(element, headers)
304305
{
305306
this.element = element;
306307
this._headers = headers;
@@ -321,14 +322,14 @@ ResultsTable = Utilities.createClass(
321322
});
322323

323324
this.clear();
324-
}, {
325+
}
325326

326-
clear: function()
327+
clear()
327328
{
328329
this.element.textContent = "";
329-
},
330+
}
330331

331-
_addHeader: function()
332+
_addHeader()
332333
{
333334
var thead = Utilities.createElement("thead", {}, this.element);
334335
var row = Utilities.createElement("tr", {}, thead);
@@ -343,22 +344,22 @@ ResultsTable = Utilities.createClass(
343344
if (header.children)
344345
th.colSpan = header.children.length;
345346
});
346-
},
347+
}
347348

348-
_addBody: function()
349+
_addBody()
349350
{
350351
this.tbody = Utilities.createElement("tbody", {}, this.element);
351-
},
352+
}
352353

353-
_addEmptyRow: function()
354+
_addEmptyRow()
354355
{
355356
var row = Utilities.createElement("tr", {}, this.tbody);
356357
this._flattenedHeaders.forEach(function (header) {
357358
return Utilities.createElement("td", { class: "suites-separator" }, row);
358359
});
359-
},
360+
}
360361

361-
_addTest: function(testName, testResult, options)
362+
_addTest(testName, testResult, options)
362363
{
363364
var row = Utilities.createElement("tr", {}, this.tbody);
364365

@@ -374,9 +375,9 @@ ResultsTable = Utilities.createClass(
374375
} else
375376
td.innerHTML = header.text(testResult);
376377
}, this);
377-
},
378+
}
378379

379-
_addIteration: function(iterationResult, iterationData, options)
380+
_addIteration(iterationResult, iterationData, options)
380381
{
381382
var testsResults = iterationResult[Strings.json.results.tests];
382383
for (var suiteName in testsResults) {
@@ -386,9 +387,9 @@ ResultsTable = Utilities.createClass(
386387
for (var testName in suiteResult)
387388
this._addTest(testName, suiteResult[testName], options, suiteData[testName]);
388389
}
389-
},
390+
}
390391

391-
showIterations: function(dashboard)
392+
showIterations(dashboard)
392393
{
393394
this.clear();
394395
this._addHeader();
@@ -399,7 +400,7 @@ ResultsTable = Utilities.createClass(
399400
this._addIteration(iterationResult, dashboard.data[index], dashboard.options);
400401
}, this);
401402
}
402-
});
403+
}
403404

404405
window.benchmarkRunnerClient = {
405406
iterationCount: 1,

0 commit comments

Comments
 (0)