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

Unified 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, 10 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
« no previous file with comments | « no previous file | tests/language/language_dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 66d94ab9baa42838cbcbb13757574dde4fa1f13f..1490ada8cc61d4082c436dbefdf0910dd5e23f9c 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -1770,14 +1770,33 @@ class SyncStarRewriter extends AsyncRewriterBase {
}
@override
- js.Fun finishFunction(List<js.Parameter> params,
+ js.Fun finishFunction(List<js.Parameter> parameters,
js.Statement rewrittenBody,
js.VariableDeclarationList variableDeclarations) {
+ // Each iterator invocation on the iterable should work on its own copy of
+ // the parameters.
+ // TODO(sigurdm): We only need to do this copying for parameters that are mutated.
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
+ List<js.VariableInitialization> declarations =
+ new List<js.VariableInitialization>();
+ List<js.Parameter> renamedParameters = new List<js.Parameter>();
+ for (js.Parameter parameter in parameters) {
+ String name = parameter.name;
+ String renamedName = freshName(name);
+ renamedParameters.add(new js.Parameter(renamedName));
+ declarations.add(
+ new js.VariableInitialization(new js.VariableDeclaration(name),
+ new js.VariableUse(renamedName)));
+ }
+ js.VariableDeclarationList copyParameters =
+ new js.VariableDeclarationList(declarations);
return js.js("""
- function (#params) {
+ function (#renamedParameters) {
if (#needsThis)
var #self = this;
return new #newIterable(function () {
+ if (#hasParameters) {
+ #copyParameters;
+ }
#varDecl;
return function #body(#errorCode, #result) {
if (#errorCode === #ERROR) {
@@ -1789,9 +1808,11 @@ class SyncStarRewriter extends AsyncRewriterBase {
});
}
""", {
- "params": params,
+ "renamedParameters": renamedParameters,
"needsThis": analysis.hasThis,
"helperBody": rewrittenBody,
+ "hasParameters": parameters.isNotEmpty,
+ "copyParameters": copyParameters,
"varDecl": variableDeclarations,
"errorCode": errorCodeName,
"newIterable": newIterable,
« 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