| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Tests of closures. | 5 // Tests of closures. |
| 6 | 6 |
| 7 library closures_test; | 7 library closures_test; |
| 8 | 8 |
| 9 import 'js_backend_cps_ir.dart'; | 9 import 'js_backend_cps_ir.dart'; |
| 10 | 10 |
| 11 const List<TestEntry> tests = const [ | 11 const List<TestEntry> tests = const [ |
| 12 const TestEntry(""" | 12 const TestEntry(""" |
| 13 main(x) { | 13 main(x) { |
| 14 a() { | 14 a() { |
| 15 return x; | 15 return x; |
| 16 } | 16 } |
| 17 x = x + '1'; | 17 x = x + '1'; |
| 18 print(a()); | 18 print(a()); |
| 19 } | 19 } |
| 20 """, | 20 """, |
| 21 r""" | 21 r""" |
| 22 function(x) { | 22 function(x) { |
| 23 var _box_0 = {}, a; | 23 var _box_0 = {}, a = new V.main_a(_box_0); |
| 24 _box_0._captured_x_0 = x; | 24 _box_0._captured_x_0 = x; |
| 25 a = new V.main_a(_box_0); | |
| 26 _box_0._captured_x_0 = J.getInterceptor$ns(x = _box_0._captured_x_0).$add(x, "
1"); | 25 _box_0._captured_x_0 = J.getInterceptor$ns(x = _box_0._captured_x_0).$add(x, "
1"); |
| 27 P.print(a.call$0()); | 26 P.print(a.call$0()); |
| 28 return null; | 27 return null; |
| 29 }"""), | 28 }"""), |
| 30 | 29 |
| 31 const TestEntry(""" | 30 const TestEntry(""" |
| 32 main(x) { | 31 main(x) { |
| 33 a() { | 32 a() { |
| 34 return x; | 33 return x; |
| 35 } | 34 } |
| 36 print(a()); | 35 print(a()); |
| 37 } | 36 } |
| 38 """, | 37 """, |
| 39 r""" | 38 r""" |
| 40 function(x) { | 39 function(x) { |
| 41 P.print(new V.main_a(x).call$0()); | 40 P.print(new V.main_a(x).call$0()); |
| 42 return null; | 41 return null; |
| 43 }"""), | 42 }"""), |
| 44 | 43 |
| 45 const TestEntry(""" | 44 const TestEntry(""" |
| 46 main() { | 45 main() { |
| 47 var x = 122; | 46 var x = 122; |
| 48 var a = () => x; | 47 var a = () => x; |
| 49 x = x + 1; | 48 x = x + 1; |
| 50 print(a()); | 49 print(a()); |
| 51 } | 50 } |
| 52 """, | 51 """, |
| 53 r""" | 52 r""" |
| 54 function() { | 53 function() { |
| 55 var _box_0 = {}, a; | 54 var _box_0 = {}, a = new V.main_closure(_box_0); |
| 56 _box_0._captured_x_0 = 122; | 55 _box_0._captured_x_0 = 122; |
| 57 a = new V.main_closure(_box_0); | |
| 58 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; | 56 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; |
| 59 P.print(a.call$0()); | 57 P.print(a.call$0()); |
| 60 return null; | 58 return null; |
| 61 }"""), | 59 }"""), |
| 62 | 60 |
| 63 const TestEntry(""" | 61 const TestEntry(""" |
| 64 main() { | 62 main() { |
| 65 var x = 122; | 63 var x = 122; |
| 66 var a = () { | 64 var a = () { |
| 67 var y = x; | 65 var y = x; |
| 68 return () => y; | 66 return () => y; |
| 69 }; | 67 }; |
| 70 x = x + 1; | 68 x = x + 1; |
| 71 print(a()()); | 69 print(a()()); |
| 72 } | 70 } |
| 73 """, | 71 """, |
| 74 r""" | 72 r""" |
| 75 function() { | 73 function() { |
| 76 var _box_0 = {}, a; | 74 var _box_0 = {}, a = new V.main_closure(_box_0); |
| 77 _box_0._captured_x_0 = 122; | 75 _box_0._captured_x_0 = 122; |
| 78 a = new V.main_closure(_box_0); | |
| 79 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; | 76 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; |
| 80 P.print(a.call$0().call$0()); | 77 P.print(a.call$0().call$0()); |
| 81 return null; | 78 return null; |
| 82 }"""), | 79 }"""), |
| 83 | 80 |
| 84 const TestEntry(""" | 81 const TestEntry(""" |
| 85 main() { | 82 main() { |
| 86 var a; | 83 var a; |
| 87 for (var i=0; i<10; i++) { | 84 for (var i=0; i<10; i++) { |
| 88 a = () => i; | 85 a = () => i; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 112 """, | 109 """, |
| 113 r""" | 110 r""" |
| 114 function() { | 111 function() { |
| 115 return new V.A_b_closure(this); | 112 return new V.A_b_closure(this); |
| 116 }"""), | 113 }"""), |
| 117 ]; | 114 ]; |
| 118 | 115 |
| 119 void main() { | 116 void main() { |
| 120 runTests(tests); | 117 runTests(tests); |
| 121 } | 118 } |
| OLD | NEW |