Skip to content

Commit 0889e9d

Browse files
committed
Convert benchmark-runner.js to JS class syntax.
1 parent 3575bca commit 0889e9d

File tree

1 file changed

+55
-30
lines changed

1 file changed

+55
-30
lines changed

MotionMark/resources/runner/benchmark-runner.js

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,54 @@
1-
BenchmarkRunnerState = Utilities.createClass(
2-
function(suites)
1+
/*
2+
* Copyright (C) 2015-2020 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
class BenchmarkRunnerState {
27+
constructor(suites)
328
{
429
this._suites = suites;
530
this._suiteIndex = -1;
631
this._testIndex = 0;
732
this.next();
8-
}, {
33+
}
934

10-
currentSuite: function()
35+
currentSuite()
1136
{
1237
return this._suites[this._suiteIndex];
13-
},
38+
}
1439

15-
currentTest: function()
40+
currentTest()
1641
{
1742
var suite = this.currentSuite();
1843
return suite ? suite.tests[this._testIndex] : null;
19-
},
44+
}
2045

21-
isFirstTest: function()
46+
isFirstTest()
2247
{
2348
return !this._testIndex;
24-
},
49+
}
2550

26-
next: function()
51+
next()
2752
{
2853
this._testIndex++;
2954

@@ -35,9 +60,9 @@ BenchmarkRunnerState = Utilities.createClass(
3560
do {
3661
this._suiteIndex++;
3762
} while (this._suiteIndex < this._suites.length && this._suites[this._suiteIndex].disabled);
38-
},
63+
}
3964

40-
prepareCurrentTest: function(runner, frame)
65+
prepareCurrentTest(runner, frame)
4166
{
4267
var test = this.currentTest();
4368
var promise = new SimplePromise;
@@ -49,35 +74,35 @@ BenchmarkRunnerState = Utilities.createClass(
4974
frame.src = "tests/" + test.url;
5075
return promise;
5176
}
52-
});
77+
}
5378

54-
BenchmarkRunner = Utilities.createClass(
55-
function(suites, frameContainer, client)
79+
class BenchmarkRunner {
80+
constructor(suites, frameContainer, client)
5681
{
5782
this._suites = suites;
5883
this._client = client;
5984
this._frameContainer = frameContainer;
60-
}, {
85+
}
6186

62-
_appendFrame: function()
87+
_appendFrame()
6388
{
6489
var frame = document.createElement("iframe");
6590
frame.setAttribute("scrolling", "no");
6691

6792
this._frameContainer.insertBefore(frame, this._frameContainer.firstChild);
6893
this._frame = frame;
6994
return frame;
70-
},
95+
}
7196

72-
_removeFrame: function()
97+
_removeFrame()
7398
{
7499
if (this._frame) {
75100
this._frame.parentNode.removeChild(this._frame);
76101
this._frame = null;
77102
}
78-
},
103+
}
79104

80-
_runBenchmarkAndRecordResults: function(state)
105+
_runBenchmarkAndRecordResults(state)
81106
{
82107
var promise = new SimplePromise;
83108
var suite = state.currentSuite();
@@ -110,9 +135,9 @@ BenchmarkRunner = Utilities.createClass(
110135
});
111136

112137
return promise;
113-
},
138+
}
114139

115-
step: function(state)
140+
step(state)
116141
{
117142
if (!state) {
118143
state = new BenchmarkRunnerState(this._suites);
@@ -134,18 +159,18 @@ BenchmarkRunner = Utilities.createClass(
134159
return state.prepareCurrentTest(this, this._frame).then(function(prepareReturnValue) {
135160
return this._runBenchmarkAndRecordResults(state);
136161
}.bind(this));
137-
},
162+
}
138163

139-
runAllSteps: function(startingState)
164+
runAllSteps(startingState)
140165
{
141166
var nextCallee = this.runAllSteps.bind(this);
142167
this.step(startingState).then(function(nextState) {
143168
if (nextState)
144169
nextCallee(nextState);
145170
});
146-
},
171+
}
147172

148-
runMultipleIterations: function()
173+
runMultipleIterations()
149174
{
150175
var self = this;
151176
var currentIteration = 0;
@@ -164,9 +189,9 @@ BenchmarkRunner = Utilities.createClass(
164189
this._client.willStartFirstIteration();
165190

166191
this.runAllSteps();
167-
},
192+
}
168193

169-
_finalize: function()
194+
_finalize()
170195
{
171196
this._removeFrame();
172197

@@ -176,4 +201,4 @@ BenchmarkRunner = Utilities.createClass(
176201
if (this._runNextIteration)
177202
this._runNextIteration();
178203
}
179-
});
204+
}

0 commit comments

Comments
 (0)