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

Side by Side Diff: pkg/kernel/lib/transformations/continuation.dart

Issue 2782053003: Await cancellation in the Kernel await transformer (Closed)
Patch Set: Created 3 years, 8 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/language/language_kernel.status » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 kernel.transformations.continuation; 5 library kernel.transformations.continuation;
6 6
7 import 'dart:math' as math; 7 import 'dart:math' as math;
8 8
9 import '../ast.dart'; 9 import '../ast.dart';
10 import '../core_types.dart'; 10 import '../core_types.dart';
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 // To: 547 // To:
548 // 548 //
549 // { 549 // {
550 // var :for-iterator = new StreamIterator(<stream-expression>); 550 // var :for-iterator = new StreamIterator(<stream-expression>);
551 // try { 551 // try {
552 // while (await :for-iterator.moveNext()) { 552 // while (await :for-iterator.moveNext()) {
553 // var <variable> = :for-iterator.current; 553 // var <variable> = :for-iterator.current;
554 // ... 554 // ...
555 // } 555 // }
556 // } finally { 556 // } finally {
557 // :for-iterator.cancel(); 557 // await :for-iterator.cancel();
558 // } 558 // }
559 // } 559 // }
560 var iteratorVariable = new VariableDeclaration(':for-iterator', 560 var iteratorVariable = new VariableDeclaration(':for-iterator',
561 initializer: new ConstructorInvocation( 561 initializer: new ConstructorInvocation(
562 helper.streamIteratorConstructor, 562 helper.streamIteratorConstructor,
563 new Arguments(<Expression>[stmt.iterable], 563 new Arguments(<Expression>[stmt.iterable],
564 types: [const DynamicType()]))); 564 types: [const DynamicType()])));
565 565
566 // await iterator.moveNext() 566 // await iterator.moveNext()
567 var condition = new AwaitExpression(new MethodInvocation( 567 var condition = new AwaitExpression(new MethodInvocation(
568 new VariableGet(iteratorVariable), 568 new VariableGet(iteratorVariable),
569 new Name('moveNext'), 569 new Name('moveNext'),
570 new Arguments(<Expression>[])))..fileOffset = stmt.fileOffset; 570 new Arguments(<Expression>[])))..fileOffset = stmt.fileOffset;
571 571
572 // var <variable> = iterator.current; 572 // var <variable> = iterator.current;
573 var valueVariable = stmt.variable; 573 var valueVariable = stmt.variable;
574 valueVariable.initializer = new PropertyGet( 574 valueVariable.initializer = new PropertyGet(
575 new VariableGet(iteratorVariable), new Name('current')); 575 new VariableGet(iteratorVariable), new Name('current'));
576 valueVariable.initializer.parent = valueVariable; 576 valueVariable.initializer.parent = valueVariable;
577 577
578 var whileBody = new Block(<Statement>[valueVariable, stmt.body]); 578 var whileBody = new Block(<Statement>[valueVariable, stmt.body]);
579 var tryBody = new WhileStatement(condition, whileBody); 579 var tryBody = new WhileStatement(condition, whileBody);
580 580
581 // iterator.cancel(); 581 // iterator.cancel();
582 var tryFinalizer = new ExpressionStatement(new MethodInvocation( 582 var tryFinalizer = new ExpressionStatement(new AwaitExpression(
583 new VariableGet(iteratorVariable), 583 new MethodInvocation(new VariableGet(iteratorVariable),
584 new Name('cancel'), 584 new Name('cancel'), new Arguments(<Expression>[]))));
585 new Arguments(<Expression>[])));
586 585
587 var tryFinally = new TryFinally(tryBody, tryFinalizer); 586 var tryFinally = new TryFinally(tryBody, tryFinalizer);
588 587
589 var block = new Block(<Statement>[iteratorVariable, tryFinally]); 588 var block = new Block(<Statement>[iteratorVariable, tryFinally]);
590 block.accept(this); 589 block.accept(this);
591 } else { 590 } else {
592 stmt.iterable = expressionRewriter.rewrite(stmt.iterable, statements) 591 stmt.iterable = expressionRewriter.rewrite(stmt.iterable, statements)
593 ..parent = stmt; 592 ..parent = stmt;
594 stmt.body = visitDelimited(stmt.body)..parent = stmt; 593 stmt.body = visitDelimited(stmt.body)..parent = stmt;
595 statements.add(stmt); 594 statements.add(stmt);
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 coreTypes.getMember('dart:core', '_SyncIterable', ''), 913 coreTypes.getMember('dart:core', '_SyncIterable', ''),
915 coreTypes.getMember('dart:async', '_StreamIterator', ''), 914 coreTypes.getMember('dart:async', '_StreamIterator', ''),
916 coreTypes.getMember('dart:async', 'Future', 'microtask'), 915 coreTypes.getMember('dart:async', 'Future', 'microtask'),
917 coreTypes.getMember('dart:async', '_AsyncStarStreamController', ''), 916 coreTypes.getMember('dart:async', '_AsyncStarStreamController', ''),
918 coreTypes.getTopLevelMember('dart:async', '_asyncThenWrapperHelper'), 917 coreTypes.getTopLevelMember('dart:async', '_asyncThenWrapperHelper'),
919 coreTypes.getTopLevelMember('dart:async', '_asyncErrorWrapperHelper'), 918 coreTypes.getTopLevelMember('dart:async', '_asyncErrorWrapperHelper'),
920 coreTypes.getTopLevelMember('dart:async', '_awaitHelper'), 919 coreTypes.getTopLevelMember('dart:async', '_awaitHelper'),
921 coreTypes); 920 coreTypes);
922 } 921 }
923 } 922 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language_kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698