| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 closureToClassMapper; | 5 library closureToClassMapper; |
| 6 | 6 |
| 7 import "elements/elements.dart"; | 7 import "elements/elements.dart"; |
| 8 import "dart2jslib.dart"; | 8 import "dart2jslib.dart"; |
| 9 import "dart_types.dart"; | 9 import "dart_types.dart"; |
| 10 import "scanner/scannerlib.dart" show Token; | 10 import "scanner/scannerlib.dart" show Token; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 // optimization: factories have type parameters as function | 447 // optimization: factories have type parameters as function |
| 448 // parameters, and type parameters are declared in the class, not | 448 // parameters, and type parameters are declared in the class, not |
| 449 // the factory. | 449 // the factory. |
| 450 if (insideClosure && | 450 if (insideClosure && |
| 451 element.enclosingElement != currentElement && | 451 element.enclosingElement != currentElement && |
| 452 element != currentElement) { | 452 element != currentElement) { |
| 453 assert(closureData.freeVariableMapping[element] == null || | 453 assert(closureData.freeVariableMapping[element] == null || |
| 454 closureData.freeVariableMapping[element] == element); | 454 closureData.freeVariableMapping[element] == element); |
| 455 closureData.freeVariableMapping[element] = element; | 455 closureData.freeVariableMapping[element] = element; |
| 456 } else if (inTryStatement) { | 456 } else if (inTryStatement) { |
| 457 // Don't mark the this-element. This would complicate things in the | 457 // Don't mark the this-element or a self-reference. This would complicate |
| 458 // builder. | 458 // things in the builder. |
| 459 if (element != closureData.thisElement) { | 459 // Note that nested (named) functions are immutable. |
| 460 if (element != closureData.thisElement && |
| 461 element != closureData.closureElement) { |
| 460 // TODO(ngeoffray): only do this if the variable is mutated. | 462 // TODO(ngeoffray): only do this if the variable is mutated. |
| 461 closureData.usedVariablesInTry.add(element); | 463 closureData.usedVariablesInTry.add(element); |
| 462 } | 464 } |
| 463 } | 465 } |
| 464 } | 466 } |
| 465 | 467 |
| 466 void declareLocal(Element element) { | 468 void declareLocal(Element element) { |
| 467 scopeVariables.add(element); | 469 scopeVariables.add(element); |
| 468 } | 470 } |
| 469 | 471 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 } | 856 } |
| 855 | 857 |
| 856 visitTryStatement(TryStatement node) { | 858 visitTryStatement(TryStatement node) { |
| 857 // TODO(ngeoffray): implement finer grain state. | 859 // TODO(ngeoffray): implement finer grain state. |
| 858 bool oldInTryStatement = inTryStatement; | 860 bool oldInTryStatement = inTryStatement; |
| 859 inTryStatement = true; | 861 inTryStatement = true; |
| 860 node.visitChildren(this); | 862 node.visitChildren(this); |
| 861 inTryStatement = oldInTryStatement; | 863 inTryStatement = oldInTryStatement; |
| 862 } | 864 } |
| 863 } | 865 } |
| OLD | NEW |