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

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: Add TODO 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 // TODO(sigurdm): We only need to do this copying for parameters that are mu tated.
floitsch 2015/03/04 13:28:45 Long line.
sigurdm 2015/03/04 13:37:52 Somehow my editor lost the line showing me 80 char
1779 List<js.VariableInitialization> declarations =
1780 new List<js.VariableInitialization>();
1781 List<js.Parameter> renamedParameters = new List<js.Parameter>();
1782 for (js.Parameter parameter in parameters) {
1783 String name = parameter.name;
1784 String renamedName = freshName(name);
1785 renamedParameters.add(new js.Parameter(renamedName));
1786 declarations.add(
1787 new js.VariableInitialization(new js.VariableDeclaration(name),
1788 new js.VariableUse(renamedName)));
1789 }
1790 js.VariableDeclarationList copyParameters =
1791 new js.VariableDeclarationList(declarations);
1776 return js.js(""" 1792 return js.js("""
1777 function (#params) { 1793 function (#renamedParameters) {
1778 if (#needsThis) 1794 if (#needsThis)
1779 var #self = this; 1795 var #self = this;
1780 return new #newIterable(function () { 1796 return new #newIterable(function () {
1797 if (#hasParameters) {
1798 #copyParameters;
1799 }
1781 #varDecl; 1800 #varDecl;
1782 return function #body(#errorCode, #result) { 1801 return function #body(#errorCode, #result) {
1783 if (#errorCode === #ERROR) { 1802 if (#errorCode === #ERROR) {
1784 #currentError = #result; 1803 #currentError = #result;
1785 #goto = #handler; 1804 #goto = #handler;
1786 } 1805 }
1787 #helperBody; 1806 #helperBody;
1788 }; 1807 };
1789 }); 1808 });
1790 } 1809 }
1791 """, { 1810 """, {
1792 "params": params, 1811 "renamedParameters": renamedParameters,
1793 "needsThis": analysis.hasThis, 1812 "needsThis": analysis.hasThis,
1794 "helperBody": rewrittenBody, 1813 "helperBody": rewrittenBody,
1814 "hasParameters": parameters.isNotEmpty,
1815 "copyParameters": copyParameters,
1795 "varDecl": variableDeclarations, 1816 "varDecl": variableDeclarations,
1796 "errorCode": errorCodeName, 1817 "errorCode": errorCodeName,
1797 "newIterable": newIterable, 1818 "newIterable": newIterable,
1798 "body": bodyName, 1819 "body": bodyName,
1799 "self": selfName, 1820 "self": selfName,
1800 "result": resultName, 1821 "result": resultName,
1801 "goto": goto, 1822 "goto": goto,
1802 "handler": handler, 1823 "handler": handler,
1803 "currentError": currentErrorName, 1824 "currentError": currentErrorName,
1804 "ERROR": js.number(error_codes.ERROR), 1825 "ERROR": js.number(error_codes.ERROR),
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 return condition || body; 2474 return condition || body;
2454 } 2475 }
2455 2476
2456 @override 2477 @override
2457 bool visitDartYield(js.DartYield node) { 2478 bool visitDartYield(js.DartYield node) {
2458 hasYield = true; 2479 hasYield = true;
2459 visit(node.expression); 2480 visit(node.expression);
2460 return true; 2481 return true;
2461 } 2482 }
2462 } 2483 }
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