Chromium Code Reviews| 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 c2863c5d895c9e32fc00dcc6819e9818b200cf4d..2febf01a591957135ed0d2ba804e232c62821347 100644 |
| --- a/pkg/compiler/lib/src/js/rewrite_async.dart |
| +++ b/pkg/compiler/lib/src/js/rewrite_async.dart |
| @@ -399,11 +399,14 @@ abstract class AsyncRewriterBase extends js.NodeVisitor { |
| // Note that RegExes, js.ArrayInitializer and js.ObjectInitializer are not |
| // [js.Literal]s. |
| if (result is js.Literal) return result; |
| + |
| js.Expression tempVar = useTempVar(allocateTempVar()); |
| addStatement(js.js.statement('# = #;', [tempVar, result])); |
| return tempVar; |
| } |
| + // TODO(sigurdm): This is obsolete - all calls use store: false. Replace with |
| + // visitExpression(node); |
| withExpression(js.Expression node, fn(js.Expression result), {bool store}) { |
| int oldTempVarIndex = currentTempVarIndex; |
| js.Expression visited = visitExpression(node); |
| @@ -415,6 +418,43 @@ abstract class AsyncRewriterBase extends js.NodeVisitor { |
| return result; |
| } |
| + /// Calls [fn] with the result of evaluating [node]. Taking special care of |
| + /// property accesses. |
| + /// |
| + /// If [store] is true the result of evaluating [node] is stored in a |
| + /// temporary. |
| + /// |
| + /// We cannot rewrite `<receiver>.m()` to: |
| + /// temp = <receiver>.m; |
|
floitsch
2015/03/06 16:32:16
Make sure this is correct MD.
sigurdm
2015/03/09 14:34:11
Yes - indenting by 4 gives a code block
|
| + /// temp(); |
| + /// Because this leaves `this` unbound in the call. But because dart2js never |
| + /// changes function properties we write: |
|
floitsch
2015/03/06 16:32:16
Make sure to write a test for this.
Something lik
sigurdm
2015/03/09 14:34:12
Done.
|
| + /// temp = <receiver>; |
| + /// temp.m(); |
| + withExpressionDontStoreFunction(js.Expression node, |
|
floitsch
2015/03/06 16:32:15
I don't get the name.
sigurdm
2015/03/09 14:34:12
I changed it. Hopefully better.
|
| + fn(js.Expression result), {bool store}) { |
| + int oldTempVarIndex = currentTempVarIndex; |
| + js.Expression visited = visitExpression(node); |
| + js.Expression selector; |
| + if (store) { |
| + if (visited is js.PropertyAccess) { |
| + js.PropertyAccess propertyAccess = visited; |
| + selector = propertyAccess.selector; |
| + visited = propertyAccess.receiver; |
| + } |
| + visited = _storeIfNecessary(visited); |
|
floitsch
2015/03/06 16:32:15
Avoid updating visited.
Rather have a new variable
sigurdm
2015/03/09 14:34:11
Done.
|
| + } |
| + js.Expression result; |
| + if (selector == null) { |
| + result = fn(visited); |
| + } else { |
| + result = fn(new js.PropertyAccess(visited, selector)); |
| + } |
| + currentTempVarIndex = oldTempVarIndex; |
| + return result; |
| + } |
| + |
| + |
| /// Calls [fn] with the value of evaluating [node1] and [node2]. |
| /// |
| /// If `shouldTransform(node2)` the first expression is stored in a temporary |
| @@ -805,7 +845,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor { |
| @override |
| js.Expression visitCall(js.Call node) { |
| bool storeTarget = node.arguments.any(shouldTransform); |
| - return withExpression(node.target, (target) { |
| + return withExpressionDontStoreFunction(node.target, (target) { |
| return withExpressions(node.arguments, (List<js.Expression> arguments) { |
| return new js.Call(target, arguments); |
| }); |
| @@ -920,7 +960,8 @@ abstract class AsyncRewriterBase extends js.NodeVisitor { |
| bool oldInsideUntranslatedBreakable = insideUntranslatedBreakable; |
| insideUntranslatedBreakable = true; |
| withExpression(node.condition, (js.Expression condition) { |
| - addStatement(js.js.statement('do {#} while (#)', [node.body, condition])); |
| + addStatement(js.js.statement('do {#} while (#)', |
| + [node.body, condition])); |
| }, store: false); |
| insideUntranslatedBreakable = oldInsideUntranslatedBreakable; |
| return; |
| @@ -1148,7 +1189,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor { |
| @override |
| js.Expression visitNew(js.New node) { |
| bool storeTarget = node.arguments.any(shouldTransform); |
| - return withExpression(node.target, (target) { |
| + return withExpressionDontStoreFunction(node.target, (target) { |
| return withExpressions(node.arguments, (List<js.Expression> arguments) { |
| return new js.New(target, arguments); |
| }); |
| @@ -1777,7 +1818,8 @@ class SyncStarRewriter extends AsyncRewriterBase { |
| 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. |
| + // TODO(sigurdm): We only need to do this copying for parameters that are |
| + // mutated. |
| List<js.VariableInitialization> declarations = |
| new List<js.VariableInitialization>(); |
| List<js.Parameter> renamedParameters = new List<js.Parameter>(); |