| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 closure0() { | |
| 6 var x = 499; | |
| 7 // TODO(floitsch): remove name from functions. | |
| 8 var f = fun() { return x; }; | |
| 9 Expect.equals(499, f()); | |
| 10 } | |
| 11 | |
| 12 class A { | |
| 13 closure1() { | |
| 14 var x = 499; | |
| 15 var f = fun() { return x; }; | |
| 16 Expect.equals(499, f()); | |
| 17 } | |
| 18 } | |
| 19 | |
| 20 applyFun(f) { | |
| 21 return f(); | |
| 22 } | |
| 23 | |
| 24 closure2() { | |
| 25 var x = 499; | |
| 26 Expect.equals(499, applyFun(fun() { return x; })); | |
| 27 } | |
| 28 | |
| 29 closure3() { | |
| 30 var y = 400; | |
| 31 var f = fun(x) { return y + x; }; | |
| 32 Expect.equals(499, f(99)); | |
| 33 } | |
| 34 | |
| 35 applyFun2(f) { | |
| 36 return f(400, 90); | |
| 37 } | |
| 38 | |
| 39 closure4() { | |
| 40 var z = 9; | |
| 41 Expect.equals(499, applyFun2(fun(x, y) { return x + y + z; })); | |
| 42 } | |
| 43 | |
| 44 closure5() { | |
| 45 var x = 498; | |
| 46 // TODO(floitsch): remove name from functions. | |
| 47 var f = fun() { return x; }; | |
| 48 x++; | |
| 49 Expect.equals(499, f()); | |
| 50 } | |
| 51 | |
| 52 class A2 { | |
| 53 closure6() { | |
| 54 var x = 498; | |
| 55 var f = fun() { return x; }; | |
| 56 x++; | |
| 57 Expect.equals(499, f()); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 closure7() { | |
| 62 var x = 498; | |
| 63 var f = fun() { return x; }; | |
| 64 x++; | |
| 65 Expect.equals(499, applyFun(f)); | |
| 66 } | |
| 67 | |
| 68 closure8() { | |
| 69 var y = 399; | |
| 70 var f = fun(x) { return y + x; }; | |
| 71 y++; | |
| 72 Expect.equals(499, f(99)); | |
| 73 } | |
| 74 | |
| 75 closure9() { | |
| 76 var z = 9; | |
| 77 Expect.equals(499, applyFun2(fun(x, y) { return x + y + z; })); | |
| 78 } | |
| 79 | |
| 80 main() { | |
| 81 closure0(); | |
| 82 new A().closure1(); | |
| 83 closure2(); | |
| 84 closure3(); | |
| 85 closure4(); | |
| 86 closure5(); | |
| 87 new A2().closure6(); | |
| 88 closure7(); | |
| 89 closure8(); | |
| 90 closure9(); | |
| 91 } | |
| OLD | NEW |