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

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

Issue 977053003: Copy the parameters to a sync* function for each invocation of .iterator (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/language_dart2js.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) 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 1752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 void addYield(js.DartYield node, js.Expression expression) { 1763 void addYield(js.DartYield node, js.Expression expression) {
1764 if (node.hasStar) { 1764 if (node.hasStar) {
1765 addStatement( 1765 addStatement(
1766 new js.Return(new js.Call(yieldStarExpression, [expression]))); 1766 new js.Return(new js.Call(yieldStarExpression, [expression])));
1767 } else { 1767 } else {
1768 addStatement(new js.Return(expression)); 1768 addStatement(new js.Return(expression));
1769 } 1769 }
1770 } 1770 }
1771 1771
1772 @override 1772 @override
1773 js.Fun finishFunction(List<js.Parameter> params, 1773 js.Fun finishFunction(List<js.Parameter> parameters,
1774 js.Statement rewrittenBody, 1774 js.Statement rewrittenBody,
1775 js.VariableDeclarationList variableDeclarations) { 1775 js.VariableDeclarationList variableDeclarations) {
1776 // Each iterator invocation on the iterable should work on its own copy of
1777 // the parameters.
1778 List<js.VariableInitialization> declarations =
1779 new List<js.VariableInitialization>();
1780 List<js.Parameter> renamedParameters = new List<js.Parameter>();
1781 for (js.Parameter parameter in parameters) {
1782 String name = parameter.name;
1783 String renamedName = freshName(name);
1784 renamedParameters.add(new js.Parameter(renamedName));
1785 declarations.add(
1786 new js.VariableInitialization(new js.VariableDeclaration(name),
1787 new js.VariableUse(renamedName)));
1788 }
1789 js.VariableDeclarationList copyParameters =
floitsch 2015/03/04 13:03:02 Add a TODO that you don't need to do this if the p
sigurdm 2015/03/04 13:05:47 Done.
1790 new js.VariableDeclarationList(declarations);
1776 return js.js(""" 1791 return js.js("""
1777 function (#params) { 1792 function (#renamedParameters) {
1778 if (#needsThis) 1793 if (#needsThis)
1779 var #self = this; 1794 var #self = this;
1780 return new #newIterable(function () { 1795 return new #newIterable(function () {
1796 if (#hasParameters) {
1797 #copyParameters;
1798 }
1781 #varDecl; 1799 #varDecl;
1782 return function #body(#errorCode, #result) { 1800 return function #body(#errorCode, #result) {
1783 if (#errorCode === #ERROR) { 1801 if (#errorCode === #ERROR) {
1784 #currentError = #result; 1802 #currentError = #result;
1785 #goto = #handler; 1803 #goto = #handler;
1786 } 1804 }
1787 #helperBody; 1805 #helperBody;
1788 }; 1806 };
1789 }); 1807 });
1790 } 1808 }
1791 """, { 1809 """, {
1792 "params": params, 1810 "renamedParameters": renamedParameters,
1793 "needsThis": analysis.hasThis, 1811 "needsThis": analysis.hasThis,
1794 "helperBody": rewrittenBody, 1812 "helperBody": rewrittenBody,
1813 "hasParameters": parameters.isNotEmpty,
1814 "copyParameters": copyParameters,
1795 "varDecl": variableDeclarations, 1815 "varDecl": variableDeclarations,
1796 "errorCode": errorCodeName, 1816 "errorCode": errorCodeName,
1797 "newIterable": newIterable, 1817 "newIterable": newIterable,
1798 "body": bodyName, 1818 "body": bodyName,
1799 "self": selfName, 1819 "self": selfName,
1800 "result": resultName, 1820 "result": resultName,
1801 "goto": goto, 1821 "goto": goto,
1802 "handler": handler, 1822 "handler": handler,
1803 "currentError": currentErrorName, 1823 "currentError": currentErrorName,
1804 "ERROR": js.number(error_codes.ERROR), 1824 "ERROR": js.number(error_codes.ERROR),
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 return condition || body; 2473 return condition || body;
2454 } 2474 }
2455 2475
2456 @override 2476 @override
2457 bool visitDartYield(js.DartYield node) { 2477 bool visitDartYield(js.DartYield node) {
2458 hasYield = true; 2478 hasYield = true;
2459 visit(node.expression); 2479 visit(node.expression);
2460 return true; 2480 return true;
2461 } 2481 }
2462 } 2482 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698