Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(953)

Side by Side Diff: pkg/compiler/lib/src/js/rewrite_async.dart

Issue 1235793006: Allow `return <expr>` in sync* and async* javascript. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js/async_await_js_transform_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import "dart:math" show max; 7 import "dart:math" show max;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:js_runtime/shared/async_await_error_codes.dart' 10 import 'package:js_runtime/shared/async_await_error_codes.dart'
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 return withExpression( 1274 return withExpression(
1275 node.value, (js.Expression value) => new js.Property(node.name, value), 1275 node.value, (js.Expression value) => new js.Property(node.name, value),
1276 store: false); 1276 store: false);
1277 } 1277 }
1278 1278
1279 @override 1279 @override
1280 js.Expression visitRegExpLiteral(js.RegExpLiteral node) => node; 1280 js.Expression visitRegExpLiteral(js.RegExpLiteral node) => node;
1281 1281
1282 @override 1282 @override
1283 void visitReturn(js.Return node) { 1283 void visitReturn(js.Return node) {
1284 assert(node.value == null || (!isSyncStar && !isAsyncStar));
1285 js.Node target = analysis.targets[node]; 1284 js.Node target = analysis.targets[node];
1286 if (node.value != null) { 1285 if (node.value != null) {
1287 withExpression(node.value, (js.Expression value) { 1286 if(isSyncStar || isAsyncStar) {
1288 addStatement(js.js.statement("# = #;", [returnValue, value])); 1287 // Even though `return expr;` is not allowed in the dart sync* and
1289 }, store: false); 1288 // async* code, the backend sometimes generated code like this.
1289 // It is interpreted as `expr; return;`
floitsch 2015/07/15 14:03:16 Add more comment of why this could ever be legal.
1290 visitExpressionIgnoreResult(node.value);
1291 } else {
1292 withExpression(node.value, (js.Expression value) {
1293 addStatement(js.js.statement("# = #;", [returnValue, value]));
1294 }, store: false);
1295 }
1290 } 1296 }
1291 translateJump(target, exitLabel); 1297 translateJump(target, exitLabel);
1292 } 1298 }
1293 1299
1294 @override 1300 @override
1295 void visitSwitch(js.Switch node) { 1301 void visitSwitch(js.Switch node) {
1296 if (!node.cases.any(shouldTransform)) { 1302 if (!node.cases.any(shouldTransform)) {
1297 // If only the key has an await, translation can be simplified. 1303 // If only the key has an await, translation can be simplified.
1298 bool oldInsideUntranslated = insideUntranslatedBreakable; 1304 bool oldInsideUntranslated = insideUntranslatedBreakable;
1299 insideUntranslatedBreakable = true; 1305 insideUntranslatedBreakable = true;
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 return condition || body; 2583 return condition || body;
2578 } 2584 }
2579 2585
2580 @override 2586 @override
2581 bool visitDartYield(js.DartYield node) { 2587 bool visitDartYield(js.DartYield node) {
2582 hasYield = true; 2588 hasYield = true;
2583 visit(node.expression); 2589 visit(node.expression);
2584 return true; 2590 return true;
2585 } 2591 }
2586 } 2592 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/async_await_js_transform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698