| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 closure0() { | 7 closure0() { |
| 8 // f and g will both capture a variable named 'x'. If we use the original | 8 // f and g will both capture a variable named 'x'. If we use the original |
| 9 // name in the (shared) box then there will be troubles. | 9 // name in the (shared) box then there will be troubles. |
| 10 var f; | 10 var f; |
| 11 var g; | 11 var g; |
| 12 { | 12 { |
| 13 var x = 499; | 13 var x = 499; |
| 14 // TODO(floitsch): remove name from functions. | 14 f = () { return x; }; |
| 15 f = fun() { return x; }; | |
| 16 x++; | 15 x++; |
| 17 } | 16 } |
| 18 { | 17 { |
| 19 var x = 42; | 18 var x = 42; |
| 20 // TODO(floitsch): remove name from functions. | 19 g = () { return x; }; |
| 21 g = fun() { return x; }; | |
| 22 x++; | 20 x++; |
| 23 } | 21 } |
| 24 Expect.equals(500, f()); | 22 Expect.equals(500, f()); |
| 25 Expect.equals(43, g()); | 23 Expect.equals(43, g()); |
| 26 } | 24 } |
| 27 | 25 |
| 28 closure1() { | 26 closure1() { |
| 29 // f captures variable $0 which once could yield to troubles with HForeign if | 27 // f captures variable $0 which once could yield to troubles with HForeign if |
| 30 // we did not mangle correctly. | 28 // we did not mangle correctly. |
| 31 var $1 = 499; | 29 var $1 = 499; |
| 32 // TODO(floitsch): remove name from functions. | 30 var f = () { return $1; }; |
| 33 var f = fun() { return $1; }; | |
| 34 $1++; | 31 $1++; |
| 35 Expect.equals(500, f()); | 32 Expect.equals(500, f()); |
| 36 } | 33 } |
| 37 | 34 |
| 38 main() { | 35 main() { |
| 39 closure0(); | 36 closure0(); |
| 40 closure1(); | 37 closure1(); |
| 41 } | 38 } |
| OLD | NEW |