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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 return x; | 29 return x; |
30 } | 30 } |
31 x = x + '1'; | 31 x = x + '1'; |
32 print(a()); | 32 print(a()); |
33 return a; | 33 return a; |
34 } | 34 } |
35 """, | 35 """, |
36 r""" | 36 r""" |
37 function(x) { | 37 function(x) { |
38 var _box_0 = {}, a = new V.main_a(_box_0); | 38 var _box_0 = {}, a = new V.main_a(_box_0); |
39 _box_0._captured_x_0 = x; | 39 _box_0.x = x; |
40 _box_0._captured_x_0 = J.getInterceptor$ns(x = _box_0._captured_x_0).$add(x, "
1"); | 40 _box_0.x = J.getInterceptor$ns(x = _box_0.x).$add(x, "1"); |
41 P.print(a.call$0()); | 41 P.print(a.call$0()); |
42 return a; | 42 return a; |
43 }"""), | 43 }"""), |
44 | 44 |
45 const TestEntry(""" | 45 const TestEntry(""" |
46 main(x) { | 46 main(x) { |
47 a() { | 47 a() { |
48 return x; | 48 return x; |
49 } | 49 } |
50 print(a()); | 50 print(a()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 var x = 122; | 89 var x = 122; |
90 var a = () => x; | 90 var a = () => x; |
91 x = x + 1; | 91 x = x + 1; |
92 print(a()); | 92 print(a()); |
93 return a; | 93 return a; |
94 } | 94 } |
95 """, | 95 """, |
96 r""" | 96 r""" |
97 function() { | 97 function() { |
98 var _box_0 = {}, a = new V.main_closure(_box_0); | 98 var _box_0 = {}, a = new V.main_closure(_box_0); |
99 _box_0._captured_x_0 = 122; | 99 _box_0.x = 122; |
100 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; | 100 _box_0.x = _box_0.x + 1; |
101 P.print(a.call$0()); | 101 P.print(a.call$0()); |
102 return a; | 102 return a; |
103 }"""), | 103 }"""), |
104 | 104 |
105 const TestEntry(""" | 105 const TestEntry(""" |
106 main() { | 106 main() { |
107 var x = 122; | 107 var x = 122; |
108 var a = () { | 108 var a = () { |
109 var y = x; | 109 var y = x; |
110 return () => y; | 110 return () => y; |
(...skipping 15 matching lines...) Expand all Loading... |
126 return () => y; | 126 return () => y; |
127 }; | 127 }; |
128 x = x + 1; | 128 x = x + 1; |
129 print(a()()); | 129 print(a()()); |
130 return a; | 130 return a; |
131 } | 131 } |
132 """, | 132 """, |
133 r""" | 133 r""" |
134 function() { | 134 function() { |
135 var _box_0 = {}, a = new V.main_closure(_box_0); | 135 var _box_0 = {}, a = new V.main_closure(_box_0); |
136 _box_0._captured_x_0 = 122; | 136 _box_0.x = 122; |
137 _box_0._captured_x_0 = _box_0._captured_x_0 + 1; | 137 _box_0.x = _box_0.x + 1; |
138 P.print(a.call$0().call$0()); | 138 P.print(a.call$0().call$0()); |
139 return a; | 139 return a; |
140 }"""), | 140 }"""), |
141 | 141 |
142 const TestEntry(""" | 142 const TestEntry(""" |
143 main() { | 143 main() { |
144 var a; | 144 var a; |
145 for (var i=0; i<10; i++) { | 145 for (var i=0; i<10; i++) { |
146 a = () => i; | 146 a = () => i; |
147 } | 147 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 """, | 247 """, |
248 r""" | 248 r""" |
249 function(x) { | 249 function(x) { |
250 P.print(V.Foo$().getter$1(123)); | 250 P.print(V.Foo$().getter$1(123)); |
251 }"""), | 251 }"""), |
252 ]; | 252 ]; |
253 | 253 |
254 void main() { | 254 void main() { |
255 runTests(tests); | 255 runTests(tests); |
256 } | 256 } |
OLD | NEW |