| 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 = {}; | 23 P.print(J.getInterceptor$ns(x).$add(x, "1")); |
| 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"); | |
| 26 P.print(new V.main_a(_box_0)._box_0._captured_x_0); | |
| 27 }"""), | 24 }"""), |
| 28 | 25 |
| 29 const TestEntry(""" | 26 const TestEntry(""" |
| 30 main(x) { | 27 main(x) { |
| 31 a() { | 28 a() { |
| 32 return x; | 29 return x; |
| 33 } | 30 } |
| 34 x = x + '1'; | 31 x = x + '1'; |
| 35 print(a()); | 32 print(a()); |
| 36 return a; | 33 return a; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 const TestEntry(""" | 45 const TestEntry(""" |
| 49 main(x) { | 46 main(x) { |
| 50 a() { | 47 a() { |
| 51 return x; | 48 return x; |
| 52 } | 49 } |
| 53 print(a()); | 50 print(a()); |
| 54 } | 51 } |
| 55 """, | 52 """, |
| 56 r""" | 53 r""" |
| 57 function(x) { | 54 function(x) { |
| 58 P.print(new V.main_a(x)._captured_x_0); | 55 P.print(x); |
| 59 }"""), | 56 }"""), |
| 60 | 57 |
| 61 const TestEntry(""" | 58 const TestEntry(""" |
| 62 main(x) { | 59 main(x) { |
| 63 a() { | 60 a() { |
| 64 return x; | 61 return x; |
| 65 } | 62 } |
| 66 print(a()); | 63 print(a()); |
| 67 return a; | 64 return a; |
| 68 } | 65 } |
| 69 """, | 66 """, |
| 70 r""" | 67 r""" |
| 71 function(x) { | 68 function(x) { |
| 72 var a = new V.main_a(x); | 69 var a = new V.main_a(x); |
| 73 P.print(a.call$0()); | 70 P.print(a.call$0()); |
| 74 return a; | 71 return a; |
| 75 }"""), | 72 }"""), |
| 76 | 73 |
| 77 const TestEntry(""" | 74 const TestEntry(""" |
| 78 main() { | 75 main() { |
| 79 var x = 122; | 76 var x = 122; |
| 80 var a = () => x; | 77 var a = () => x; |
| 81 x = x + 1; | 78 x = x + 1; |
| 82 print(a()); | 79 print(a()); |
| 83 } | 80 } |
| 84 """, | 81 """, |
| 85 r""" | 82 r""" |
| 86 function() { | 83 function() { |
| 87 var _box_0 = {}; | 84 P.print(122 + 1); |
| 88 _box_0._captured_x_0 = 122; | |
| 89 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; | |
| 90 P.print(new V.main_closure(_box_0)._box_0._captured_x_0); | |
| 91 }"""), | 85 }"""), |
| 92 | 86 |
| 93 const TestEntry(""" | 87 const TestEntry(""" |
| 94 main() { | 88 main() { |
| 95 var x = 122; | 89 var x = 122; |
| 96 var a = () => x; | 90 var a = () => x; |
| 97 x = x + 1; | 91 x = x + 1; |
| 98 print(a()); | 92 print(a()); |
| 99 return a; | 93 return a; |
| 100 } | 94 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 114 var a = () { | 108 var a = () { |
| 115 var y = x; | 109 var y = x; |
| 116 return () => y; | 110 return () => y; |
| 117 }; | 111 }; |
| 118 x = x + 1; | 112 x = x + 1; |
| 119 print(a()()); | 113 print(a()()); |
| 120 } | 114 } |
| 121 """, | 115 """, |
| 122 r""" | 116 r""" |
| 123 function() { | 117 function() { |
| 124 var _box_0 = {}; | 118 P.print(122 + 1); |
| 125 _box_0._captured_x_0 = 122; | |
| 126 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; | |
| 127 P.print(new V.main__closure(new V.main_closure(_box_0)._box_0._captured_x_0)._
captured_y_1); | |
| 128 }"""), | 119 }"""), |
| 129 | 120 |
| 130 const TestEntry(""" | 121 const TestEntry(""" |
| 131 main() { | 122 main() { |
| 132 var x = 122; | 123 var x = 122; |
| 133 var a = () { | 124 var a = () { |
| 134 var y = x; | 125 var y = x; |
| 135 return () => y; | 126 return () => y; |
| 136 }; | 127 }; |
| 137 x = x + 1; | 128 x = x + 1; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 """, | 247 """, |
| 257 r""" | 248 r""" |
| 258 function(x) { | 249 function(x) { |
| 259 P.print(V.Foo$().getter$1(123)); | 250 P.print(V.Foo$().getter$1(123)); |
| 260 }"""), | 251 }"""), |
| 261 ]; | 252 ]; |
| 262 | 253 |
| 263 void main() { | 254 void main() { |
| 264 runTests(tests); | 255 runTests(tests); |
| 265 } | 256 } |
| OLD | NEW |