@@ -64,12 +64,12 @@ class BenchmarkRunnerState {
64
64
65
65
prepareCurrentTest ( runner , frame )
66
66
{
67
- var test = this . currentTest ( ) ;
68
- var promise = new SimplePromise ;
69
-
70
- frame . onload = function ( ) {
71
- promise . resolve ( ) ;
72
- } ;
67
+ const test = this . currentTest ( ) ;
68
+ const promise = new Promise ( resolve => {
69
+ frame . onload = function ( ) {
70
+ resolve ( ) ;
71
+ } ;
72
+ } ) ;
73
73
74
74
frame . src = "tests/" + test . url ;
75
75
return promise ;
@@ -102,86 +102,80 @@ class BenchmarkRunner {
102
102
}
103
103
}
104
104
105
- _runBenchmarkAndRecordResults ( state )
105
+ async _runBenchmarkAndRecordResults ( state )
106
106
{
107
- var promise = new SimplePromise ;
108
- var suite = state . currentSuite ( ) ;
109
- var test = state . currentTest ( ) ;
107
+ const suite = state . currentSuite ( ) ;
108
+ const test = state . currentTest ( ) ;
110
109
111
110
if ( this . _client && this . _client . willRunTest )
112
111
this . _client . willRunTest ( suite , test ) ;
113
112
114
- var contentWindow = this . _frame . contentWindow ;
115
- var self = this ;
113
+ const contentWindow = this . _frame . contentWindow ;
116
114
117
- var options = { complexity : test . complexity } ;
115
+ const options = { complexity : test . complexity } ;
118
116
Utilities . extendObject ( options , this . _client . options ) ;
119
117
Utilities . extendObject ( options , Utilities . parseParameters ( contentWindow . location ) ) ;
120
118
121
- var benchmark = new contentWindow . benchmarkClass ( options ) ;
122
- document . body . style . backgroundColor = benchmark . backgroundColor ( ) ;
123
- benchmark . run ( ) . then ( function ( testData ) {
124
- var suiteResults = self . _suitesResults [ suite . name ] || { } ;
125
- suiteResults [ test . name ] = testData ;
126
- self . _suitesResults [ suite . name ] = suiteResults ;
119
+ const benchmark = new contentWindow . benchmarkClass ( options ) ;
120
+ document . body . style . backgroundColor = benchmark . backgroundColor ( ) ; // FIXME: Do this via a selector.
121
+
122
+ await benchmark . initialize ( options ) ;
123
+ const testData = await benchmark . run ( ) ;
124
+ const suiteResults = this . _suitesResults [ suite . name ] || { } ;
125
+ suiteResults [ test . name ] = testData ;
126
+ this . _suitesResults [ suite . name ] = suiteResults ;
127
127
128
- if ( self . _client && self . _client . didRunTest )
129
- self . _client . didRunTest ( testData ) ;
128
+ if ( this . _client && this . _client . didRunTest )
129
+ this . _client . didRunTest ( testData ) ;
130
130
131
- state . next ( ) ;
132
- if ( state . currentSuite ( ) != suite )
133
- self . _removeFrame ( ) ;
134
- promise . resolve ( state ) ;
135
- } ) ;
131
+ state . next ( ) ;
132
+ if ( state . currentSuite ( ) != suite )
133
+ this . _removeFrame ( ) ;
136
134
137
- return promise ;
135
+ return state ;
138
136
}
139
137
140
- step ( state )
138
+ async step ( state )
141
139
{
142
140
if ( ! state ) {
143
141
state = new BenchmarkRunnerState ( this . _suites ) ;
144
142
this . _suitesResults = { } ;
145
143
}
146
144
147
- var suite = state . currentSuite ( ) ;
145
+ const suite = state . currentSuite ( ) ;
148
146
if ( ! suite ) {
149
147
this . _finalize ( ) ;
150
- var promise = new SimplePromise ;
151
- promise . resolve ( ) ;
152
- return promise ;
148
+ return ;
153
149
}
154
150
155
- if ( state . isFirstTest ( ) ) {
151
+ if ( state . isFirstTest ( ) )
156
152
this . _appendFrame ( ) ;
157
- }
158
153
159
- return state . prepareCurrentTest ( this , this . _frame ) . then ( function ( prepareReturnValue ) {
160
- return this . _runBenchmarkAndRecordResults ( state ) ;
161
- } . bind ( this ) ) ;
154
+ await state . prepareCurrentTest ( this , this . _frame ) ;
155
+ const nextState = await this . _runBenchmarkAndRecordResults ( state ) ;
156
+ return nextState ;
162
157
}
163
158
164
159
runAllSteps ( startingState )
165
160
{
166
- var nextCallee = this . runAllSteps . bind ( this ) ;
167
- this . step ( startingState ) . then ( function ( nextState ) {
168
- if ( nextState )
169
- nextCallee ( nextState ) ;
161
+ this . step ( startingState ) . then ( nextState => {
162
+ if ( ! nextState )
163
+ return ;
164
+ this . runAllSteps ( nextState ) ;
170
165
} ) ;
171
166
}
172
167
173
168
runMultipleIterations ( )
174
169
{
175
- var self = this ;
176
- var currentIteration = 0 ;
170
+ let currentIteration = 0 ;
177
171
178
- this . _runNextIteration = function ( ) {
179
- currentIteration ++ ;
180
- if ( currentIteration < self . _client . iterationCount )
181
- self . runAllSteps ( ) ;
172
+ this . _runNextIteration = ( ) => {
173
+ ++ currentIteration ;
174
+ if ( currentIteration < this . _client . iterationCount )
175
+ this . runAllSteps ( ) ;
182
176
else if ( this . _client && this . _client . didFinishLastIteration ) {
183
- document . body . style . backgroundColor = "" ;
184
- self . _client . didFinishLastIteration ( ) ;
177
+ document . body . style . backgroundColor = "" ; // FIXME: Do this via a selector.
178
+ this . _client . didFinishLastIteration ( ) ;
185
179
}
186
180
}
187
181
0 commit comments