Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library rewrite_async; | 5 library rewrite_async; |
| 6 | 6 |
| 7 // TODO(sigurdm): Throws in catch-handlers are handled wrong. | 7 // TODO(sigurdm): Throws in catch-handlers are handled wrong. |
| 8 // TODO(sigurdm): Avoid using variables in templates. It could blow up memory | 8 // TODO(sigurdm): Avoid using variables in templates. It could blow up memory |
| 9 // use. | 9 // use. |
| 10 | 10 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 /// Contructor used to initialize the [completerName] variable. | 179 /// Contructor used to initialize the [completerName] variable. |
| 180 /// | 180 /// |
| 181 /// Specific to async methods. | 181 /// Specific to async methods. |
| 182 final js.Expression newCompleter; | 182 final js.Expression newCompleter; |
| 183 | 183 |
| 184 /// Contructor used to initialize the [controllerName] variable. | 184 /// Contructor used to initialize the [controllerName] variable. |
| 185 /// | 185 /// |
| 186 /// Specific to async* methods. | 186 /// Specific to async* methods. |
| 187 final js.Expression newController; | 187 final js.Expression newController; |
| 188 | 188 |
| 189 /// Used to get the `Stream` out of the [controllerName] variable. | |
| 190 /// | |
| 191 /// Sepcific to async* methods. | |
|
floitsch
2015/02/10 13:27:50
Specific
sigurdm
2015/02/10 13:35:52
Done.
| |
| 192 final js.Expression streamOfController; | |
| 193 | |
| 189 /// Contructor creating the Iterable for a sync* method. Called with | 194 /// Contructor creating the Iterable for a sync* method. Called with |
| 190 /// [helperName]. | 195 /// [helperName]. |
| 191 final js.Expression newIterable; | 196 final js.Expression newIterable; |
| 192 | 197 |
| 193 /// A JS Expression that creates a marker showing that iteration is over. | 198 /// A JS Expression that creates a marker showing that iteration is over. |
| 194 /// | 199 /// |
| 195 /// Called without arguments. | 200 /// Called without arguments. |
| 196 final js.Expression endOfIteration; | 201 final js.Expression endOfIteration; |
| 197 | 202 |
| 198 /// A JS Expression that creates a marker indicating a 'yield' statement. | 203 /// A JS Expression that creates a marker indicating a 'yield' statement. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 225 | 230 |
| 226 bool get isSync => async == const js.AsyncModifier.sync(); | 231 bool get isSync => async == const js.AsyncModifier.sync(); |
| 227 bool get isAsync => async == const js.AsyncModifier.async(); | 232 bool get isAsync => async == const js.AsyncModifier.async(); |
| 228 bool get isSyncStar => async == const js.AsyncModifier.syncStar(); | 233 bool get isSyncStar => async == const js.AsyncModifier.syncStar(); |
| 229 bool get isAsyncStar => async == const js.AsyncModifier.asyncStar(); | 234 bool get isAsyncStar => async == const js.AsyncModifier.asyncStar(); |
| 230 | 235 |
| 231 AsyncRewriter(this.diagnosticListener, | 236 AsyncRewriter(this.diagnosticListener, |
| 232 spannable, | 237 spannable, |
| 233 {this.thenHelper, | 238 {this.thenHelper, |
| 234 this.streamHelper, | 239 this.streamHelper, |
| 240 this.streamOfController, | |
| 235 this.newCompleter, | 241 this.newCompleter, |
| 236 this.newController, | 242 this.newController, |
| 237 this.endOfIteration, | 243 this.endOfIteration, |
| 238 this.newIterable, | 244 this.newIterable, |
| 239 this.yieldExpression, | 245 this.yieldExpression, |
| 240 this.yieldStarExpression, | 246 this.yieldStarExpression, |
| 241 this.safeVariableName}) | 247 this.safeVariableName}) |
| 242 : _spannable = spannable; | 248 : _spannable = spannable; |
| 243 | 249 |
| 244 /// Main entry point. | 250 /// Main entry point. |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 /// Returns the [Future]/[Stream] coming from [completerName]/ | 588 /// Returns the [Future]/[Stream] coming from [completerName]/ |
| 583 /// [controllerName]. | 589 /// [controllerName]. |
| 584 js.Statement generateInitializer() { | 590 js.Statement generateInitializer() { |
| 585 if (isAsync) { | 591 if (isAsync) { |
| 586 return js.js.statement( | 592 return js.js.statement( |
| 587 "return #thenHelper(null, $helperName, $completerName, null);", { | 593 "return #thenHelper(null, $helperName, $completerName, null);", { |
| 588 "thenHelper": thenHelper | 594 "thenHelper": thenHelper |
| 589 }); | 595 }); |
| 590 } else if (isAsyncStar) { | 596 } else if (isAsyncStar) { |
| 591 return js.js.statement( | 597 return js.js.statement( |
| 592 "return #streamHelper(null, $helperName, $controllerName, null);", { | 598 "return #streamOfController($controllerName);", { |
| 593 "streamHelper": streamHelper | 599 "streamOfController": streamOfController |
| 594 }); | 600 }); |
| 595 } else { | 601 } else { |
| 596 throw diagnosticListener.internalError( | 602 throw diagnosticListener.internalError( |
| 597 spannable, "Unexpected asyncModifier: $async"); | 603 spannable, "Unexpected asyncModifier: $async"); |
| 598 } | 604 } |
| 599 } | 605 } |
| 600 | 606 |
| 601 /// Rewrites an async/sync*/async* function to a normal Javascript function. | 607 /// Rewrites an async/sync*/async* function to a normal Javascript function. |
| 602 /// | 608 /// |
| 603 /// The control flow is flattened by simulating 'goto' using a switch in a | 609 /// The control flow is flattened by simulating 'goto' using a switch in a |
| (...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2144 loopsAndSwitches.removeLast(); | 2150 loopsAndSwitches.removeLast(); |
| 2145 return condition || body; | 2151 return condition || body; |
| 2146 } | 2152 } |
| 2147 | 2153 |
| 2148 @override | 2154 @override |
| 2149 bool visitDartYield(js.DartYield node) { | 2155 bool visitDartYield(js.DartYield node) { |
| 2150 visit(node.expression); | 2156 visit(node.expression); |
| 2151 return true; | 2157 return true; |
| 2152 } | 2158 } |
| 2153 } | 2159 } |
| OLD | NEW |