| 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 f = () { return x; }; | 14 f = () { |
| 15 return x; |
| 16 }; |
| 15 x++; | 17 x++; |
| 16 } | 18 } |
| 17 { | 19 { |
| 18 var x = 42; | 20 var x = 42; |
| 19 g = () { return x; }; | 21 g = () { |
| 22 return x; |
| 23 }; |
| 20 x++; | 24 x++; |
| 21 } | 25 } |
| 22 Expect.equals(500, f()); | 26 Expect.equals(500, f()); |
| 23 Expect.equals(43, g()); | 27 Expect.equals(43, g()); |
| 24 } | 28 } |
| 25 | 29 |
| 26 closure1() { | 30 closure1() { |
| 27 // f captures variable $0 which once could yield to troubles with HForeign if | 31 // f captures variable $0 which once could yield to troubles with HForeign if |
| 28 // we did not mangle correctly. | 32 // we did not mangle correctly. |
| 29 var $1 = 499; | 33 var $1 = 499; |
| 30 var f = () { return $1; }; | 34 var f = () { |
| 35 return $1; |
| 36 }; |
| 31 $1++; | 37 $1++; |
| 32 Expect.equals(500, f()); | 38 Expect.equals(500, f()); |
| 33 } | 39 } |
| 34 | 40 |
| 35 main() { | 41 main() { |
| 36 closure0(); | 42 closure0(); |
| 37 closure1(); | 43 closure1(); |
| 38 } | 44 } |
| OLD | NEW |