| 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 = new V.main_a(_box_0); | 23 var _box_0 = {}; |
| 24 _box_0._captured_x_0 = x; | 24 _box_0._captured_x_0 = x; |
| 25 _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"); |
| 26 P.print(a.call$0()); | 26 P.print(new V.main_a(_box_0).call$0()); |
| 27 }"""), | 27 }"""), |
| 28 | 28 |
| 29 const TestEntry(""" | 29 const TestEntry(""" |
| 30 main(x) { | 30 main(x) { |
| 31 a() { | 31 a() { |
| 32 return x; | 32 return x; |
| 33 } | 33 } |
| 34 print(a()); | 34 print(a()); |
| 35 } | 35 } |
| 36 """, | 36 """, |
| 37 r""" | 37 r""" |
| 38 function(x) { | 38 function(x) { |
| 39 P.print(new V.main_a(x).call$0()); | 39 P.print(new V.main_a(x).call$0()); |
| 40 }"""), | 40 }"""), |
| 41 | 41 |
| 42 const TestEntry(""" | 42 const TestEntry(""" |
| 43 main() { | 43 main() { |
| 44 var x = 122; | 44 var x = 122; |
| 45 var a = () => x; | 45 var a = () => x; |
| 46 x = x + 1; | 46 x = x + 1; |
| 47 print(a()); | 47 print(a()); |
| 48 } | 48 } |
| 49 """, | 49 """, |
| 50 r""" | 50 r""" |
| 51 function() { | 51 function() { |
| 52 var _box_0 = {}, a = new V.main_closure(_box_0); | 52 var _box_0 = {}; |
| 53 _box_0._captured_x_0 = 122; | 53 _box_0._captured_x_0 = 122; |
| 54 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; | 54 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; |
| 55 P.print(a.call$0()); | 55 P.print(new V.main_closure(_box_0).call$0()); |
| 56 }"""), | 56 }"""), |
| 57 | 57 |
| 58 const TestEntry(""" | 58 const TestEntry(""" |
| 59 main() { | 59 main() { |
| 60 var x = 122; | 60 var x = 122; |
| 61 var a = () { | 61 var a = () { |
| 62 var y = x; | 62 var y = x; |
| 63 return () => y; | 63 return () => y; |
| 64 }; | 64 }; |
| 65 x = x + 1; | 65 x = x + 1; |
| 66 print(a()()); | 66 print(a()()); |
| 67 } | 67 } |
| 68 """, | 68 """, |
| 69 r""" | 69 r""" |
| 70 function() { | 70 function() { |
| 71 var _box_0 = {}, a = new V.main_closure(_box_0); | 71 var _box_0 = {}; |
| 72 _box_0._captured_x_0 = 122; | 72 _box_0._captured_x_0 = 122; |
| 73 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; | 73 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; |
| 74 P.print(a.call$0().call$0()); | 74 P.print(new V.main_closure(_box_0).call$0().call$0()); |
| 75 }"""), | 75 }"""), |
| 76 | 76 |
| 77 const TestEntry(""" | 77 const TestEntry(""" |
| 78 main() { | 78 main() { |
| 79 var a; | 79 var a; |
| 80 for (var i=0; i<10; i++) { | 80 for (var i=0; i<10; i++) { |
| 81 a = () => i; | 81 a = () => i; |
| 82 } | 82 } |
| 83 print(a()); | 83 print(a()); |
| 84 } | 84 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 """, | 184 """, |
| 185 r""" | 185 r""" |
| 186 function(x) { | 186 function(x) { |
| 187 P.print(V.Foo$().getter$1(123)); | 187 P.print(V.Foo$().getter$1(123)); |
| 188 }"""), | 188 }"""), |
| 189 ]; | 189 ]; |
| 190 | 190 |
| 191 void main() { | 191 void main() { |
| 192 runTests(tests); | 192 runTests(tests); |
| 193 } | 193 } |
| OLD | NEW |