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

Unified 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: Address review. Added test. 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/js/rewrite_async.dart
diff --git a/pkg/compiler/lib/src/js/rewrite_async.dart b/pkg/compiler/lib/src/js/rewrite_async.dart
index 41a84661af3be219797ab4975d6421f025ff78da..1282401f3f4a7d2e97f87283539040660958b69a 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -1281,12 +1281,20 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
@override
void visitReturn(js.Return node) {
- assert(node.value == null || (!isSyncStar && !isAsyncStar));
js.Node target = analysis.targets[node];
if (node.value != null) {
- withExpression(node.value, (js.Expression value) {
- addStatement(js.js.statement("# = #;", [returnValue, value]));
- }, store: false);
+ if(isSyncStar || isAsyncStar) {
+ // Even though `return expr;` is not allowed in the dart sync* and
+ // async* code, the backend sometimes generates code like this, but
+ // only when it is known that the 'expr' throws, and the return is just
+ // to tell the JavaScript VM that the code won't continue here.
+ // It is therefore interpreted as `expr; return;`
+ visitExpressionIgnoreResult(node.value);
+ } else {
+ withExpression(node.value, (js.Expression value) {
+ addStatement(js.js.statement("# = #;", [returnValue, value]));
+ }, store: false);
+ }
}
translateJump(target, exitLabel);
}
« no previous file with comments | « no previous file | tests/compiler/dart2js/async_await_js_transform_test.dart » ('j') | tests/language/syncstar_less_than_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698