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

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

Issue 989503002: Fix dart2js async error handling of finallies nested in finallies. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/async_throw_in_catch_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:_internal/compiler/js_lib/shared/async_await_error_codes.dart' 10 import 'package:_internal/compiler/js_lib/shared/async_await_error_codes.dart'
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 rewrittenBody = js.js.statement('while (true) {#}', rewrittenBody); 652 rewrittenBody = js.js.statement('while (true) {#}', rewrittenBody);
653 List<js.VariableInitialization> variables = 653 List<js.VariableInitialization> variables =
654 new List<js.VariableInitialization>(); 654 new List<js.VariableInitialization>();
655 655
656 variables.add(_makeVariableInitializer(goto, js.number(0))); 656 variables.add(_makeVariableInitializer(goto, js.number(0)));
657 variables.addAll(variableInitializations()); 657 variables.addAll(variableInitializations());
658 variables.add( 658 variables.add(
659 _makeVariableInitializer(handler, js.number(rethrowLabel))); 659 _makeVariableInitializer(handler, js.number(rethrowLabel)));
660 variables.add(_makeVariableInitializer(currentError, null)); 660 variables.add(_makeVariableInitializer(currentError, null));
661 if (analysis.hasFinally || (isAsyncStar && analysis.hasYield)) { 661 if (analysis.hasFinally || (isAsyncStar && analysis.hasYield)) {
662 variables.add(_makeVariableInitializer(next, null)); 662 variables.add(_makeVariableInitializer(next,
663 new js.ArrayInitializer(<js.Expression>[])));
663 } 664 }
664 if (analysis.hasThis && !isSyncStar) { 665 if (analysis.hasThis && !isSyncStar) {
665 // Sync* functions must remember `this` on the level of the outer 666 // Sync* functions must remember `this` on the level of the outer
666 // function. 667 // function.
667 variables.add(_makeVariableInitializer(self, js.js('this'))); 668 variables.add(_makeVariableInitializer(self, js.js('this')));
668 } 669 }
669 variables.addAll(localVariables.map( 670 variables.addAll(localVariables.map(
670 (js.VariableDeclaration declaration) { 671 (js.VariableDeclaration declaration) {
671 return new js.VariableInitialization(declaration, null); 672 return new js.VariableInitialization(declaration, null);
672 })); 673 }));
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1410
1410 js.Node last = jumpTargets.removeLast(); 1411 js.Node last = jumpTargets.removeLast();
1411 assert(last == node); 1412 assert(last == node);
1412 1413
1413 if (node.finallyPart == null) { 1414 if (node.finallyPart == null) {
1414 setErrorHandler(); 1415 setErrorHandler();
1415 addGoto(afterFinallyLabel); 1416 addGoto(afterFinallyLabel);
1416 } else { 1417 } else {
1417 // The handler is reset as the first thing in the finally block. 1418 // The handler is reset as the first thing in the finally block.
1418 addStatement( 1419 addStatement(
1419 js.js.statement("# = [#];", [next, js.number(afterFinallyLabel)])); 1420 js.js.statement("#.push(#);", [next, js.number(afterFinallyLabel)]));
1420 addGoto(finallyLabel); 1421 addGoto(finallyLabel);
1421 } 1422 }
1422 1423
1423 if (node.catchPart != null) { 1424 if (node.catchPart != null) {
1424 beginLabel(handlerLabel); 1425 beginLabel(handlerLabel);
1425 // [uncaughtLabel] is the handler for the code in the catch-part. 1426 // [uncaughtLabel] is the handler for the code in the catch-part.
1426 // It ensures that [nextName] is set up to run the right finally blocks. 1427 // It ensures that [nextName] is set up to run the right finally blocks.
1427 handlerLabels[node.catchPart] = uncaughtLabel; 1428 handlerLabels[node.catchPart] = uncaughtLabel;
1428 jumpTargets.add(node.catchPart); 1429 jumpTargets.add(node.catchPart);
1429 setErrorHandler(); 1430 setErrorHandler();
1430 // The catch declaration name can shadow outer variables, so a fresh name 1431 // The catch declaration name can shadow outer variables, so a fresh name
1431 // is needed to avoid collisions. See Ecma 262, 3rd edition, 1432 // is needed to avoid collisions. See Ecma 262, 3rd edition,
1432 // section 12.14. 1433 // section 12.14.
1433 String errorRename = freshName(node.catchPart.declaration.name); 1434 String errorRename = freshName(node.catchPart.declaration.name);
1434 localVariables.add(new js.VariableDeclaration(errorRename)); 1435 localVariables.add(new js.VariableDeclaration(errorRename));
1435 variableRenamings 1436 variableRenamings
1436 .add(new Pair(node.catchPart.declaration.name, errorRename)); 1437 .add(new Pair(node.catchPart.declaration.name, errorRename));
1437 addStatement(js.js.statement("# = #;", [errorRename, currentError])); 1438 addStatement(js.js.statement("# = #;", [errorRename, currentError]));
1438 visitStatement(node.catchPart.body); 1439 visitStatement(node.catchPart.body);
1439 variableRenamings.removeLast(); 1440 variableRenamings.removeLast();
1440 if (node.finallyPart != null) { 1441 if (node.finallyPart != null) {
1441 // The error has been caught, so after the finally, continue after the 1442 // The error has been caught, so after the finally, continue after the
1442 // try. 1443 // try.
1443 addStatement(js.js.statement("# = [#];", 1444 addStatement(
1444 [next, js.number(afterFinallyLabel)])); 1445 js.js.statement("#.push(#);",
1446 [next, js.number(afterFinallyLabel)]));
1445 addGoto(finallyLabel); 1447 addGoto(finallyLabel);
1446 } else { 1448 } else {
1447 addGoto(afterFinallyLabel); 1449 addGoto(afterFinallyLabel);
1448 } 1450 }
1449 js.Node last = jumpTargets.removeLast(); 1451 js.Node last = jumpTargets.removeLast();
1450 assert(last == node.catchPart); 1452 assert(last == node.catchPart);
1451 } 1453 }
1452 1454
1453 // The "uncaught"-handler tells the finally-block to continue with 1455 // The "uncaught"-handler tells the finally-block to continue with
1454 // the enclosing finally-blocks until the current catch-handler. 1456 // the enclosing finally-blocks until the current catch-handler.
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 return condition || body; 2476 return condition || body;
2475 } 2477 }
2476 2478
2477 @override 2479 @override
2478 bool visitDartYield(js.DartYield node) { 2480 bool visitDartYield(js.DartYield node) {
2479 hasYield = true; 2481 hasYield = true;
2480 visit(node.expression); 2482 visit(node.expression);
2481 return true; 2483 return true;
2482 } 2484 }
2483 } 2485 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/async_throw_in_catch_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698