OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "package:compiler/src/js/js.dart"; | 6 import "package:compiler/src/js/js.dart"; |
7 import "package:compiler/src/js/rewrite_async.dart"; | 7 import "package:compiler/src/js/rewrite_async.dart"; |
8 | 8 |
9 import "backend_dart/dart_printer_test.dart" show PrintDiagnosticListener; | 9 import "backend_dart/dart_printer_test.dart" show PrintDiagnosticListener; |
10 | 10 |
11 void testTransform(String source, String expected) { | 11 void testTransform(String source, String expected) { |
12 Fun fun = js(source); | 12 Fun fun = js(source); |
13 Fun rewritten = new AsyncRewriter( | 13 Fun rewritten = new AsyncRewriter( |
14 null, // The diagnostic helper should not be used in these tests. | 14 null, // The diagnostic helper should not be used in these tests. |
15 null, | 15 null, |
16 thenHelper: new VariableUse("thenHelper"), | 16 asyncHelper: new VariableUse("thenHelper"), |
17 newCompleter: new VariableUse("Completer"), | 17 newCompleter: new VariableUse("Completer"), |
18 endOfIteration: new VariableUse("endOfIteration"), | 18 endOfIteration: new VariableUse("endOfIteration"), |
19 newIterable: new VariableUse("Iterator"), | 19 newIterable: new VariableUse("Iterator"), |
20 safeVariableName: (String name) => "__$name").rewrite(fun); | 20 safeVariableName: (String name) => "__$name").rewrite(fun); |
21 | 21 |
22 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); | 22 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); |
23 JavaScriptPrintingContext context = new SimpleJavaScriptPrintingContext(); | 23 SimpleJavaScriptPrintingContext context = |
| 24 new SimpleJavaScriptPrintingContext(); |
24 Printer printer = new Printer(options, context); | 25 Printer printer = new Printer(options, context); |
25 printer.visit(rewritten); | 26 printer.visit(rewritten); |
26 Expect.stringEquals(expected, context.getText()); | 27 Expect.stringEquals(expected, context.getText()); |
27 } | 28 } |
28 | 29 |
29 main() { | 30 main() { |
30 testTransform(""" | 31 testTransform(""" |
31 function() async { | 32 function(a) async { |
32 print(this.x); // Ensure `this` is translated in the helper function. | 33 print(this.x); // Ensure `this` is translated in the helper function. |
33 await foo(); | 34 await foo(); |
34 }""", """ | 35 }""", """ |
35 function() { | 36 function(a) { |
36 var __goto = 0, __completer = new Completer(), __self = this; | 37 var __goto = 0, __completer = new Completer(), __handler = 1, __storedError, _
_self = this; |
37 function __helper(__result) { | 38 function __body(__errorCode, __result) { |
| 39 if (__errorCode == 1) { |
| 40 __storedError = __result; |
| 41 __goto = __handler; |
| 42 } |
38 while (true) | 43 while (true) |
39 switch (__goto) { | 44 try { |
40 case 0: | 45 switch (__goto) { |
41 // Function start | 46 case 0: |
42 print(__self.x); | 47 // Function start |
43 __goto = 1; | 48 print(__self.x); |
44 return thenHelper(foo(), __helper, __completer, null); | 49 __goto = 2; |
45 case 1: | 50 return thenHelper(foo(), __body, __completer); |
46 // returning from await. | 51 case 2: |
47 // implicit return | 52 // returning from await. |
48 return thenHelper(null, null, __completer, null); | 53 // implicit return |
| 54 return thenHelper(null, 0, __completer, null); |
| 55 case 1: |
| 56 // rethrow |
| 57 return thenHelper(__storedError, 1, __completer); |
| 58 } |
| 59 } catch (__error) { |
| 60 __storedError = __error; |
| 61 __goto = __handler; |
49 } | 62 } |
| 63 |
50 } | 64 } |
51 return thenHelper(null, __helper, __completer, null); | 65 return thenHelper(null, __body, __completer, null); |
52 }"""); | 66 }"""); |
53 | 67 |
54 testTransform(""" | 68 testTransform(""" |
55 function() async { | 69 function(b) async { |
56 try { | 70 try { |
57 __outer: while (true) { // Overlapping label name. | 71 __outer: while (true) { // Overlapping label name. |
58 try { | 72 try { |
59 inner: while (true) { | 73 inner: while (true) { |
60 break __outer; // Break from untranslated loop to translated target. | 74 break __outer; // Break from untranslated loop to translated target. |
61 break; // break to untranslated target. | 75 break; // break to untranslated target. |
62 } | 76 } |
63 while (true) { | 77 while (true) { |
64 return; // Return via finallies. | 78 return; // Return via finallies. |
65 } | 79 } |
66 var __helper = await foo(); // Overlapping variable name. | 80 var __helper = await foo(); // Overlapping variable name. |
67 } finally { | 81 } finally { |
68 foo(); | 82 foo(); |
69 continue; // Continue from finally with pending finally. | 83 continue; // Continue from finally with pending finally. |
70 return 2; // Return from finally with pending finally. | 84 return 2; // Return from finally with pending finally. |
71 } | 85 } |
72 } | 86 } |
73 } finally { | 87 } finally { |
74 return 3; // Return from finally with no pending finally. | 88 return 3; // Return from finally with no pending finally. |
75 } | 89 } |
76 return 4; | 90 return 4; |
77 }""", """ | 91 }""", """ |
78 function() { | 92 function(b) { |
79 var __goto = 0, __completer = new Completer(), __handler = null, __next, __ret
urnValue, __helper; | 93 var __goto = 0, __completer = new Completer(), __handler = 2, __storedError, _
_next, __returnValue, __helper; |
80 function __helper1(__result) { | 94 function __body(__errorCode, __result) { |
| 95 if (__errorCode == 1) { |
| 96 __storedError = __result; |
| 97 __goto = __handler; |
| 98 } |
81 while (true) | 99 while (true) |
82 try { | 100 try { |
83 __outer1: | 101 __outer1: |
84 switch (__goto) { | 102 switch (__goto) { |
85 case 0: | 103 case 0: |
86 // Function start | 104 // Function start |
87 __handler = 2; | 105 __handler = 3; |
88 case 6: | 106 case 7: |
89 // continue __outer | 107 // continue __outer |
90 case 7: | 108 case 8: |
91 // while condition | 109 // while condition |
92 __handler = 9; | 110 __handler = 10; |
93 inner: { | 111 inner: { |
94 while (true) { | 112 while (true) { |
95 __next = [5]; | 113 __next = [6]; |
96 // goto finally | 114 // goto finally |
97 __goto = 10; | 115 __goto = 11; |
98 break __outer1; | 116 break __outer1; |
99 break; | 117 break; |
100 } | 118 } |
101 } | 119 } |
102 while (true) { | 120 while (true) { |
103 __next = [1, 3]; | 121 __next = [1, 4]; |
104 // goto finally | 122 // goto finally |
105 __goto = 10; | 123 __goto = 11; |
106 break __outer1; | 124 break __outer1; |
107 } | 125 } |
108 __goto = 12; | 126 __goto = 13; |
109 return thenHelper(foo(), __helper1, __completer, function(__error)
{ | 127 return thenHelper(foo(), __body, __completer); |
110 __goto = 9; | 128 case 13: |
111 __helper1(__error); | |
112 }); | |
113 case 12: | |
114 // returning from await. | 129 // returning from await. |
115 __helper = __result; | 130 __helper = __result; |
116 __next = [11]; | 131 __next = [12]; |
117 // goto finally | 132 // goto finally |
118 __goto = 10; | 133 __goto = 11; |
119 break; | 134 break; |
120 case 9: | 135 case 10: |
121 // catch | 136 // catch |
122 __handler = 2; | 137 __handler = 3; |
123 __next = [11]; | 138 __next = [12]; |
124 case 10: | 139 case 11: |
125 // finally | 140 // finally |
126 __handler = 2; | 141 __handler = 3; |
127 foo(); | 142 foo(); |
128 // goto while condition | 143 // goto while condition |
129 __goto = 7; | 144 __goto = 8; |
130 break; | 145 break; |
131 __returnValue = 2; | 146 __returnValue = 2; |
132 __next = [1]; | 147 __next = [1]; |
133 // goto finally | 148 // goto finally |
134 __goto = 3; | 149 __goto = 4; |
135 break; | 150 break; |
136 // goto the next finally handler | 151 // goto the next finally handler |
137 __goto = __next.pop(); | 152 __goto = __next.pop(); |
138 break; | 153 break; |
139 case 11: | 154 case 12: |
140 // after finally | 155 // after finally |
141 // goto while condition | 156 // goto while condition |
142 __goto = 7; | 157 __goto = 8; |
143 break; | 158 break; |
144 case 8: | 159 case 9: |
145 // after while | 160 // after while |
146 case 5: | 161 case 6: |
147 // break __outer | 162 // break __outer |
148 __next = [4]; | 163 __next = [5]; |
149 // goto finally | 164 // goto finally |
150 __goto = 3; | 165 __goto = 4; |
151 break; | 166 break; |
152 case 2: | 167 case 3: |
153 // catch | 168 // catch |
154 __handler = null; | 169 __handler = 2; |
155 __next = [4]; | 170 __next = [5]; |
156 case 3: | 171 case 4: |
157 // finally | 172 // finally |
158 __handler = null; | 173 __handler = 2; |
159 __returnValue = 3; | 174 __returnValue = 3; |
160 // goto return | 175 // goto return |
161 __goto = 1; | 176 __goto = 1; |
162 break; | 177 break; |
163 // goto the next finally handler | 178 // goto the next finally handler |
164 __goto = __next.pop(); | 179 __goto = __next.pop(); |
165 break; | 180 break; |
166 case 4: | 181 case 5: |
167 // after finally | 182 // after finally |
168 __returnValue = 4; | 183 __returnValue = 4; |
169 // goto return | 184 // goto return |
170 __goto = 1; | 185 __goto = 1; |
171 break; | 186 break; |
172 case 1: | 187 case 1: |
173 // return | 188 // return |
174 return thenHelper(__returnValue, null, __completer, null); | 189 return thenHelper(__returnValue, 0, __completer, null); |
| 190 case 2: |
| 191 // rethrow |
| 192 return thenHelper(__storedError, 1, __completer); |
175 } | 193 } |
176 } catch (__error) { | 194 } catch (__error) { |
177 if (__handler === null) | 195 __storedError = __error; |
178 throw __error; | |
179 __result = __error; | |
180 __goto = __handler; | 196 __goto = __handler; |
181 } | 197 } |
182 | 198 |
183 } | 199 } |
184 return thenHelper(null, __helper1, __completer, null); | 200 return thenHelper(null, __body, __completer, null); |
185 }"""); | 201 }"""); |
186 testTransform(""" | 202 testTransform(""" |
187 function() async { | 203 function(c) async { |
188 var a, b, c, d, e, f; | 204 var a, b, c, d, e, f; |
189 a = b++; // post- and preincrements. | 205 a = b++; // post- and preincrements. |
190 b = --b; | 206 b = --b; |
191 c = (await foo()).a++; | 207 c = (await foo()).a++; |
192 d = ++(await foo()).a; | 208 d = ++(await foo()).a; |
193 e = foo1()[await foo2()]--; | 209 e = foo1()[await foo2()]--; |
194 f = --foo1()[await foo2()]; | 210 f = --foo1()[await foo2()]; |
195 }""", """ | 211 }""", """ |
196 function() { | 212 function(c) { |
197 var __goto = 0, __completer = new Completer(), a, b, c, d, e, f, __temp1; | 213 var __goto = 0, __completer = new Completer(), __handler = 1, __storedError, a
, b, c, d, e, f, __temp1; |
198 function __helper(__result) { | 214 function __body(__errorCode, __result) { |
| 215 if (__errorCode == 1) { |
| 216 __storedError = __result; |
| 217 __goto = __handler; |
| 218 } |
199 while (true) | 219 while (true) |
200 switch (__goto) { | 220 try { |
201 case 0: | 221 switch (__goto) { |
202 // Function start | 222 case 0: |
203 a = b++; | 223 // Function start |
204 b = --b; | 224 a = b++; |
205 __goto = 1; | 225 b = --b; |
206 return thenHelper(foo(), __helper, __completer, null); | 226 __goto = 2; |
207 case 1: | 227 return thenHelper(foo(), __body, __completer); |
208 // returning from await. | 228 case 2: |
209 c = __result.a++; | 229 // returning from await. |
210 __goto = 2; | 230 c = __result.a++; |
211 return thenHelper(foo(), __helper, __completer, null); | 231 __goto = 3; |
212 case 2: | 232 return thenHelper(foo(), __body, __completer); |
213 // returning from await. | 233 case 3: |
214 d = ++__result.a; | 234 // returning from await. |
215 __temp1 = foo1(); | 235 d = ++__result.a; |
216 __goto = 3; | 236 __temp1 = foo1(); |
217 return thenHelper(foo2(), __helper, __completer, null); | 237 __goto = 4; |
218 case 3: | 238 return thenHelper(foo2(), __body, __completer); |
219 // returning from await. | 239 case 4: |
220 e = __temp1[__result]--; | 240 // returning from await. |
221 __temp1 = foo1(); | 241 e = __temp1[__result]--; |
222 __goto = 4; | 242 __temp1 = foo1(); |
223 return thenHelper(foo2(), __helper, __completer, null); | 243 __goto = 5; |
224 case 4: | 244 return thenHelper(foo2(), __body, __completer); |
225 // returning from await. | 245 case 5: |
226 f = --__temp1[__result]; | 246 // returning from await. |
227 // implicit return | 247 f = --__temp1[__result]; |
228 return thenHelper(null, null, __completer, null); | 248 // implicit return |
| 249 return thenHelper(null, 0, __completer, null); |
| 250 case 1: |
| 251 // rethrow |
| 252 return thenHelper(__storedError, 1, __completer); |
| 253 } |
| 254 } catch (__error) { |
| 255 __storedError = __error; |
| 256 __goto = __handler; |
229 } | 257 } |
| 258 |
230 } | 259 } |
231 return thenHelper(null, __helper, __completer, null); | 260 return thenHelper(null, __body, __completer, null); |
232 }"""); | 261 }"""); |
233 testTransform(""" | 262 testTransform(""" |
234 function() async { | 263 function(d2) async { |
235 var a, b, c, d, e, f, g, h; // empty initializer | 264 var a, b, c, d, e, f, g, h; // empty initializer |
236 a = foo1() || await foo2(); // short circuiting operators | 265 a = foo1() || await foo2(); // short circuiting operators |
237 b = await foo1() || foo2(); | 266 b = await foo1() || foo2(); |
238 c = await foo1() || foo3(await foo2()); | 267 c = await foo1() || foo3(await foo2()); |
239 d = foo1() || foo2(); | 268 d = foo1() || foo2(); |
240 e = foo1() && await foo2(); | 269 e = foo1() && await foo2(); |
241 f = await foo1() && foo2(); | 270 f = await foo1() && foo2(); |
242 g = await foo1() && await foo2(); | 271 g = await foo1() && await foo2(); |
243 h = foo1() && foo2(); | 272 h = foo1() && foo2(); |
244 }""", """ | 273 }""", """ |
245 function() { | 274 function(d2) { |
246 var __goto = 0, __completer = new Completer(), a, b, c, d, e, f, g, h, __temp1
; | 275 var __goto = 0, __completer = new Completer(), __handler = 1, __storedError, a
, b, c, d, e, f, g, h, __temp1; |
247 function __helper(__result) { | 276 function __body(__errorCode, __result) { |
| 277 if (__errorCode == 1) { |
| 278 __storedError = __result; |
| 279 __goto = __handler; |
| 280 } |
248 while (true) | 281 while (true) |
249 switch (__goto) { | 282 try { |
250 case 0: | 283 switch (__goto) { |
251 // Function start | 284 case 0: |
252 __temp1 = foo1(); | 285 // Function start |
253 if (__temp1) { | 286 __temp1 = foo1(); |
254 // goto then | 287 if (__temp1) { |
255 __goto = 1; | 288 // goto then |
| 289 __goto = 2; |
| 290 break; |
| 291 } else |
| 292 __result = __temp1; |
| 293 // goto join |
| 294 __goto = 3; |
256 break; | 295 break; |
257 } else | 296 case 2: |
258 __result = __temp1; | 297 // then |
259 // goto join | 298 __goto = 4; |
260 __goto = 2; | 299 return thenHelper(foo2(), __body, __completer); |
261 break; | 300 case 4: |
262 case 1: | 301 // returning from await. |
263 // then | 302 case 3: |
264 __goto = 3; | 303 // join |
265 return thenHelper(foo2(), __helper, __completer, null); | 304 a = __result; |
266 case 3: | |
267 // returning from await. | |
268 case 2: | |
269 // join | |
270 a = __result; | |
271 __goto = 4; | |
272 return thenHelper(foo1(), __helper, __completer, null); | |
273 case 4: | |
274 // returning from await. | |
275 b = __result || foo2(); | |
276 __goto = 7; | |
277 return thenHelper(foo1(), __helper, __completer, null); | |
278 case 7: | |
279 // returning from await. | |
280 __temp1 = __result; | |
281 if (__temp1) { | |
282 // goto then | |
283 __goto = 5; | 305 __goto = 5; |
| 306 return thenHelper(foo1(), __body, __completer); |
| 307 case 5: |
| 308 // returning from await. |
| 309 b = __result || foo2(); |
| 310 __goto = 8; |
| 311 return thenHelper(foo1(), __body, __completer); |
| 312 case 8: |
| 313 // returning from await. |
| 314 __temp1 = __result; |
| 315 if (__temp1) { |
| 316 // goto then |
| 317 __goto = 6; |
| 318 break; |
| 319 } else |
| 320 __result = __temp1; |
| 321 // goto join |
| 322 __goto = 7; |
284 break; | 323 break; |
285 } else | 324 case 6: |
286 __result = __temp1; | 325 // then |
287 // goto join | 326 __temp1 = foo3; |
288 __goto = 6; | |
289 break; | |
290 case 5: | |
291 // then | |
292 __temp1 = foo3; | |
293 __goto = 8; | |
294 return thenHelper(foo2(), __helper, __completer, null); | |
295 case 8: | |
296 // returning from await. | |
297 __result = __temp1(__result); | |
298 case 6: | |
299 // join | |
300 c = __result; | |
301 d = foo1() || foo2(); | |
302 __temp1 = foo1(); | |
303 if (__temp1) | |
304 __result = __temp1; | |
305 else { | |
306 // goto then | |
307 __goto = 9; | 327 __goto = 9; |
| 328 return thenHelper(foo2(), __body, __completer); |
| 329 case 9: |
| 330 // returning from await. |
| 331 __result = __temp1(__result); |
| 332 case 7: |
| 333 // join |
| 334 c = __result; |
| 335 d = foo1() || foo2(); |
| 336 __temp1 = foo1(); |
| 337 if (__temp1) |
| 338 __result = __temp1; |
| 339 else { |
| 340 // goto then |
| 341 __goto = 10; |
| 342 break; |
| 343 } |
| 344 // goto join |
| 345 __goto = 11; |
308 break; | 346 break; |
309 } | 347 case 10: |
310 // goto join | 348 // then |
311 __goto = 10; | 349 __goto = 12; |
312 break; | 350 return thenHelper(foo2(), __body, __completer); |
313 case 9: | 351 case 12: |
314 // then | 352 // returning from await. |
315 __goto = 11; | 353 case 11: |
316 return thenHelper(foo2(), __helper, __completer, null); | 354 // join |
317 case 11: | 355 e = __result; |
318 // returning from await. | |
319 case 10: | |
320 // join | |
321 e = __result; | |
322 __goto = 12; | |
323 return thenHelper(foo1(), __helper, __completer, null); | |
324 case 12: | |
325 // returning from await. | |
326 f = __result && foo2(); | |
327 __goto = 15; | |
328 return thenHelper(foo1(), __helper, __completer, null); | |
329 case 15: | |
330 // returning from await. | |
331 __temp1 = __result; | |
332 if (__temp1) | |
333 __result = __temp1; | |
334 else { | |
335 // goto then | |
336 __goto = 13; | 356 __goto = 13; |
| 357 return thenHelper(foo1(), __body, __completer); |
| 358 case 13: |
| 359 // returning from await. |
| 360 f = __result && foo2(); |
| 361 __goto = 16; |
| 362 return thenHelper(foo1(), __body, __completer); |
| 363 case 16: |
| 364 // returning from await. |
| 365 __temp1 = __result; |
| 366 if (__temp1) |
| 367 __result = __temp1; |
| 368 else { |
| 369 // goto then |
| 370 __goto = 14; |
| 371 break; |
| 372 } |
| 373 // goto join |
| 374 __goto = 15; |
337 break; | 375 break; |
338 } | 376 case 14: |
339 // goto join | 377 // then |
340 __goto = 14; | 378 __goto = 17; |
341 break; | 379 return thenHelper(foo2(), __body, __completer); |
342 case 13: | 380 case 17: |
343 // then | 381 // returning from await. |
344 __goto = 16; | 382 case 15: |
345 return thenHelper(foo2(), __helper, __completer, null); | 383 // join |
346 case 16: | 384 g = __result; |
347 // returning from await. | 385 h = foo1() && foo2(); |
348 case 14: | 386 // implicit return |
349 // join | 387 return thenHelper(null, 0, __completer, null); |
350 g = __result; | 388 case 1: |
351 h = foo1() && foo2(); | 389 // rethrow |
352 // implicit return | 390 return thenHelper(__storedError, 1, __completer); |
353 return thenHelper(null, null, __completer, null); | 391 } |
| 392 } catch (__error) { |
| 393 __storedError = __error; |
| 394 __goto = __handler; |
354 } | 395 } |
| 396 |
355 } | 397 } |
356 return thenHelper(null, __helper, __completer, null); | 398 return thenHelper(null, __body, __completer, null); |
357 }"""); | 399 }"""); |
358 testTransform(""" | 400 testTransform(""" |
359 function(x, y) async { | 401 function(x, y) async { |
360 while (true) { | 402 while (true) { |
361 switch(y) { // Switch with no awaits in case key expressions | 403 switch(y) { // Switch with no awaits in case key expressions |
362 case 0: | 404 case 0: |
363 case 1: | 405 case 1: |
364 await foo(); | 406 await foo(); |
365 continue; // Continue the loop, not the switch | 407 continue; // Continue the loop, not the switch |
366 case 1: // Duplicate case | 408 case 1: // Duplicate case |
367 await foo(); | 409 await foo(); |
368 break; // Break the switch | 410 break; // Break the switch |
369 case 2: | 411 case 2: |
370 foo(); // No default | 412 foo(); // No default |
371 } | 413 } |
372 } | 414 } |
373 }""", """ | 415 }""", """ |
374 function(x, y) { | 416 function(x, y) { |
375 var __goto = 0, __completer = new Completer(); | 417 var __goto = 0, __completer = new Completer(), __handler = 1, __storedError; |
376 function __helper(__result) { | 418 function __body(__errorCode, __result) { |
| 419 if (__errorCode == 1) { |
| 420 __storedError = __result; |
| 421 __goto = __handler; |
| 422 } |
377 while (true) | 423 while (true) |
378 switch (__goto) { | 424 try { |
379 case 0: | 425 switch (__goto) { |
380 // Function start | 426 case 0: |
381 case 1: | 427 // Function start |
382 // while condition | 428 case 2: |
383 case 3: | 429 // while condition |
384 // switch | 430 case 4: |
385 switch (y) { | 431 // switch |
386 case 0: | 432 switch (y) { |
387 // goto case | 433 case 0: |
388 __goto = 5; | 434 // goto case |
389 break; | 435 __goto = 6; |
390 case 1: | 436 break; |
391 // goto case | 437 case 1: |
392 __goto = 6; | 438 // goto case |
393 break; | 439 __goto = 7; |
394 case 1: | 440 break; |
395 // goto case | 441 case 1: |
396 __goto = 7; | 442 // goto case |
397 break; | 443 __goto = 8; |
398 case 2: | 444 break; |
399 // goto case | 445 case 2: |
400 __goto = 8; | 446 // goto case |
401 break; | 447 __goto = 9; |
402 } | 448 break; |
403 // goto after switch | 449 } |
404 __goto = 4; | 450 // goto after switch |
405 break; | 451 __goto = 5; |
406 case 5: | 452 break; |
407 // case | 453 case 6: |
408 case 6: | 454 // case |
409 // case | 455 case 7: |
410 __goto = 9; | 456 // case |
411 return thenHelper(foo(), __helper, __completer, null); | 457 __goto = 10; |
412 case 9: | 458 return thenHelper(foo(), __body, __completer); |
413 // returning from await. | 459 case 10: |
414 // goto while condition | 460 // returning from await. |
415 __goto = 1; | 461 // goto while condition |
416 break; | 462 __goto = 2; |
417 case 7: | 463 break; |
418 // case | 464 case 8: |
419 __goto = 10; | 465 // case |
420 return thenHelper(foo(), __helper, __completer, null); | 466 __goto = 11; |
421 case 10: | 467 return thenHelper(foo(), __body, __completer); |
422 // returning from await. | 468 case 11: |
423 // goto after switch | 469 // returning from await. |
424 __goto = 4; | 470 // goto after switch |
425 break; | 471 __goto = 5; |
426 case 8: | 472 break; |
427 // case | 473 case 9: |
428 foo(); | 474 // case |
429 case 4: | 475 foo(); |
430 // after switch | 476 case 5: |
431 // goto while condition | 477 // after switch |
432 __goto = 1; | 478 // goto while condition |
433 break; | 479 __goto = 2; |
434 case 2: | 480 break; |
435 // after while | 481 case 3: |
436 // implicit return | 482 // after while |
437 return thenHelper(null, null, __completer, null); | 483 // implicit return |
| 484 return thenHelper(null, 0, __completer, null); |
| 485 case 1: |
| 486 // rethrow |
| 487 return thenHelper(__storedError, 1, __completer); |
| 488 } |
| 489 } catch (__error) { |
| 490 __storedError = __error; |
| 491 __goto = __handler; |
438 } | 492 } |
| 493 |
439 } | 494 } |
440 return thenHelper(null, __helper, __completer, null); | 495 return thenHelper(null, __body, __completer, null); |
441 }"""); | 496 }"""); |
442 testTransform(""" | 497 testTransform(""" |
443 function() async { | 498 function(f) async { |
444 do { | 499 do { |
445 var a = await foo(); | 500 var a = await foo(); |
446 if (a) // If with no awaits in body | 501 if (a) // If with no awaits in body |
447 break; | 502 break; |
448 else | 503 else |
449 continue; | 504 continue; |
450 } while (await foo()); | 505 } while (await foo()); |
451 } | 506 } |
452 """, """ | 507 """, """ |
453 function() { | 508 function(f) { |
454 var __goto = 0, __completer = new Completer(), a; | 509 var __goto = 0, __completer = new Completer(), __handler = 1, __storedError, a
; |
455 function __helper(__result) { | 510 function __body(__errorCode, __result) { |
| 511 if (__errorCode == 1) { |
| 512 __storedError = __result; |
| 513 __goto = __handler; |
| 514 } |
456 while (true) | 515 while (true) |
457 switch (__goto) { | 516 try { |
458 case 0: | 517 switch (__goto) { |
459 // Function start | 518 case 0: |
460 case 1: | 519 // Function start |
461 // do body | 520 case 2: |
462 __goto = 4; | 521 // do body |
463 return thenHelper(foo(), __helper, __completer, null); | 522 __goto = 5; |
464 case 4: | 523 return thenHelper(foo(), __body, __completer); |
465 // returning from await. | 524 case 5: |
466 a = __result; | 525 // returning from await. |
467 if (a) { | 526 a = __result; |
468 // goto after do | 527 if (a) { |
469 __goto = 3; | 528 // goto after do |
470 break; | 529 __goto = 4; |
471 } else { | 530 break; |
472 // goto do condition | 531 } else { |
473 __goto = 2; | 532 // goto do condition |
474 break; | 533 __goto = 3; |
475 } | 534 break; |
476 case 2: | 535 } |
477 // do condition | 536 case 3: |
478 __goto = 5; | 537 // do condition |
479 return thenHelper(foo(), __helper, __completer, null); | 538 __goto = 6; |
480 case 5: | 539 return thenHelper(foo(), __body, __completer); |
481 // returning from await. | 540 case 6: |
482 if (__result) { | 541 // returning from await. |
483 // goto do body | 542 if (__result) { |
484 __goto = 1; | 543 // goto do body |
485 break; | 544 __goto = 2; |
486 } | 545 break; |
487 case 3: | 546 } |
488 // after do | 547 case 4: |
489 // implicit return | 548 // after do |
490 return thenHelper(null, null, __completer, null); | 549 // implicit return |
| 550 return thenHelper(null, 0, __completer, null); |
| 551 case 1: |
| 552 // rethrow |
| 553 return thenHelper(__storedError, 1, __completer); |
| 554 } |
| 555 } catch (__error) { |
| 556 __storedError = __error; |
| 557 __goto = __handler; |
491 } | 558 } |
| 559 |
492 } | 560 } |
493 return thenHelper(null, __helper, __completer, null); | 561 return thenHelper(null, __body, __completer, null); |
494 }"""); | 562 }"""); |
495 | 563 |
496 testTransform(""" | 564 testTransform(""" |
497 function() async { | 565 function(g) async { |
498 for (var i = 0; i < await foo1(); i += await foo2()) { | 566 for (var i = 0; i < await foo1(); i += await foo2()) { |
499 if (foo(i)) | 567 if (foo(i)) |
500 continue; | 568 continue; |
501 else | 569 else |
502 break; | 570 break; |
503 if (!foo(i)) { // If with no else and await in body. | 571 if (!foo(i)) { // If with no else and await in body. |
504 await foo(); | 572 await foo(); |
505 return; | 573 return; |
506 } | 574 } |
507 print(await(foo(i))); | 575 print(await(foo(i))); |
508 } | 576 } |
509 } | 577 } |
510 """, """ | 578 """, """ |
511 function() { | 579 function(g) { |
512 var __goto = 0, __completer = new Completer(), __returnValue, i, __temp1; | 580 var __goto = 0, __completer = new Completer(), __handler = 2, __storedError, _
_returnValue, i, __temp1; |
513 function __helper(__result) { | 581 function __body(__errorCode, __result) { |
| 582 if (__errorCode == 1) { |
| 583 __storedError = __result; |
| 584 __goto = __handler; |
| 585 } |
514 while (true) | 586 while (true) |
515 switch (__goto) { | 587 try { |
516 case 0: | 588 switch (__goto) { |
517 // Function start | 589 case 0: |
518 i = 0; | 590 // Function start |
519 case 2: | 591 i = 0; |
520 // for condition | 592 case 3: |
521 __temp1 = i; | 593 // for condition |
522 __goto = 5; | 594 __temp1 = i; |
523 return thenHelper(foo1(), __helper, __completer, null); | 595 __goto = 6; |
524 case 5: | 596 return thenHelper(foo1(), __body, __completer); |
525 // returning from await. | 597 case 6: |
526 if (!(__temp1 < __result)) { | 598 // returning from await. |
527 // goto after for | 599 if (!(__temp1 < __result)) { |
528 __goto = 4; | 600 // goto after for |
| 601 __goto = 5; |
| 602 break; |
| 603 } |
| 604 if (foo(i)) { |
| 605 // goto for update |
| 606 __goto = 4; |
| 607 break; |
| 608 } else { |
| 609 // goto after for |
| 610 __goto = 5; |
| 611 break; |
| 612 } |
| 613 __goto = !foo(i) ? 7 : 8; |
529 break; | 614 break; |
530 } | 615 case 7: |
531 if (foo(i)) { | 616 // then |
532 // goto for update | 617 __goto = 9; |
| 618 return thenHelper(foo(), __body, __completer); |
| 619 case 9: |
| 620 // returning from await. |
| 621 // goto return |
| 622 __goto = 1; |
| 623 break; |
| 624 case 8: |
| 625 // join |
| 626 __temp1 = print; |
| 627 __goto = 10; |
| 628 return thenHelper(foo(i), __body, __completer); |
| 629 case 10: |
| 630 // returning from await. |
| 631 __temp1(__result); |
| 632 case 4: |
| 633 // for update |
| 634 __goto = 11; |
| 635 return thenHelper(foo2(), __body, __completer); |
| 636 case 11: |
| 637 // returning from await. |
| 638 i = __result; |
| 639 // goto for condition |
533 __goto = 3; | 640 __goto = 3; |
534 break; | 641 break; |
535 } else { | 642 case 5: |
536 // goto after for | 643 // after for |
537 __goto = 4; | 644 case 1: |
538 break; | 645 // return |
539 } | 646 return thenHelper(__returnValue, 0, __completer, null); |
540 __goto = !foo(i) ? 6 : 7; | 647 case 2: |
541 break; | 648 // rethrow |
542 case 6: | 649 return thenHelper(__storedError, 1, __completer); |
543 // then | 650 } |
544 __goto = 8; | 651 } catch (__error) { |
545 return thenHelper(foo(), __helper, __completer, null); | 652 __storedError = __error; |
546 case 8: | 653 __goto = __handler; |
547 // returning from await. | |
548 // goto return | |
549 __goto = 1; | |
550 break; | |
551 case 7: | |
552 // join | |
553 __temp1 = print; | |
554 __goto = 9; | |
555 return thenHelper(foo(i), __helper, __completer, null); | |
556 case 9: | |
557 // returning from await. | |
558 __temp1(__result); | |
559 case 3: | |
560 // for update | |
561 __goto = 10; | |
562 return thenHelper(foo2(), __helper, __completer, null); | |
563 case 10: | |
564 // returning from await. | |
565 i = __result; | |
566 // goto for condition | |
567 __goto = 2; | |
568 break; | |
569 case 4: | |
570 // after for | |
571 case 1: | |
572 // return | |
573 return thenHelper(__returnValue, null, __completer, null); | |
574 } | 654 } |
| 655 |
575 } | 656 } |
576 return thenHelper(null, __helper, __completer, null); | 657 return thenHelper(null, __body, __completer, null); |
577 }"""); | 658 }"""); |
578 | 659 |
579 testTransform(""" | 660 testTransform(""" |
580 function(a) async { | 661 function(a, h) async { |
581 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; | 662 var x = {"a": foo1(), "b": await foo2(), "c": foo3()}; |
582 x["a"] = 2; // Different assignments | 663 x["a"] = 2; // Different assignments |
583 (await foo()).a = 3; | 664 (await foo()).a = 3; |
584 x[await foo()] = 4; | 665 x[await foo()] = 4; |
585 x[(await foo1()).a = await foo2()] = 5; | 666 x[(await foo1()).a = await foo2()] = 5; |
586 (await foo1())[await foo2()] = await foo3(6); | 667 (await foo1())[await foo2()] = await foo3(6); |
587 } | 668 } |
588 """, """ | 669 """, """ |
589 function(a) { | 670 function(a, h) { |
590 var __goto = 0, __completer = new Completer(), x, __temp1, __temp2; | 671 var __goto = 0, __completer = new Completer(), __handler = 1, __storedError, x
, __temp1, __temp2; |
591 function __helper(__result) { | 672 function __body(__errorCode, __result) { |
| 673 if (__errorCode == 1) { |
| 674 __storedError = __result; |
| 675 __goto = __handler; |
| 676 } |
592 while (true) | 677 while (true) |
593 switch (__goto) { | 678 try { |
594 case 0: | 679 switch (__goto) { |
595 // Function start | 680 case 0: |
596 __temp1 = foo1(); | 681 // Function start |
597 __goto = 1; | 682 __temp1 = foo1(); |
598 return thenHelper(foo2(), __helper, __completer, null); | 683 __goto = 2; |
599 case 1: | 684 return thenHelper(foo2(), __body, __completer); |
600 // returning from await. | 685 case 2: |
601 x = {a: __temp1, b: __result, c: foo3()}; | 686 // returning from await. |
602 x.a = 2; | 687 x = {a: __temp1, b: __result, c: foo3()}; |
603 __goto = 2; | 688 x.a = 2; |
604 return thenHelper(foo(), __helper, __completer, null); | 689 __goto = 3; |
605 case 2: | 690 return thenHelper(foo(), __body, __completer); |
606 // returning from await. | 691 case 3: |
607 __result.a = 3; | 692 // returning from await. |
608 __temp1 = x; | 693 __result.a = 3; |
609 __goto = 3; | 694 __temp1 = x; |
610 return thenHelper(foo(), __helper, __completer, null); | 695 __goto = 4; |
611 case 3: | 696 return thenHelper(foo(), __body, __completer); |
612 // returning from await. | 697 case 4: |
613 __temp1[__result] = 4; | 698 // returning from await. |
614 __temp1 = x; | 699 __temp1[__result] = 4; |
615 __goto = 4; | 700 __temp1 = x; |
616 return thenHelper(foo1(), __helper, __completer, null); | 701 __goto = 5; |
617 case 4: | 702 return thenHelper(foo1(), __body, __completer); |
618 // returning from await. | 703 case 5: |
619 __temp2 = __result; | 704 // returning from await. |
620 __goto = 5; | 705 __temp2 = __result; |
621 return thenHelper(foo2(), __helper, __completer, null); | 706 __goto = 6; |
622 case 5: | 707 return thenHelper(foo2(), __body, __completer); |
623 // returning from await. | 708 case 6: |
624 __temp1[__temp2.a = __result] = 5; | 709 // returning from await. |
625 __goto = 6; | 710 __temp1[__temp2.a = __result] = 5; |
626 return thenHelper(foo1(), __helper, __completer, null); | 711 __goto = 7; |
627 case 6: | 712 return thenHelper(foo1(), __body, __completer); |
628 // returning from await. | 713 case 7: |
629 __temp1 = __result; | 714 // returning from await. |
630 __goto = 7; | 715 __temp1 = __result; |
631 return thenHelper(foo2(), __helper, __completer, null); | 716 __goto = 8; |
632 case 7: | 717 return thenHelper(foo2(), __body, __completer); |
633 // returning from await. | 718 case 8: |
634 __temp2 = __result; | 719 // returning from await. |
635 __goto = 8; | 720 __temp2 = __result; |
636 return thenHelper(foo3(6), __helper, __completer, null); | 721 __goto = 9; |
637 case 8: | 722 return thenHelper(foo3(6), __body, __completer); |
638 // returning from await. | 723 case 9: |
639 __temp1[__temp2] = __result; | 724 // returning from await. |
640 // implicit return | 725 __temp1[__temp2] = __result; |
641 return thenHelper(null, null, __completer, null); | 726 // implicit return |
| 727 return thenHelper(null, 0, __completer, null); |
| 728 case 1: |
| 729 // rethrow |
| 730 return thenHelper(__storedError, 1, __completer); |
| 731 } |
| 732 } catch (__error) { |
| 733 __storedError = __error; |
| 734 __goto = __handler; |
642 } | 735 } |
| 736 |
643 } | 737 } |
644 return thenHelper(null, __helper, __completer, null); | 738 return thenHelper(null, __body, __completer, null); |
645 }"""); | 739 }"""); |
646 testTransform(""" | 740 testTransform(""" |
647 function(c) async { | 741 function(c, i) async { |
648 try { | 742 try { |
649 var x = c ? await foo() : foo(); // conditional | 743 var x = c ? await foo() : foo(); // conditional |
650 var y = {}; | 744 var y = {}; |
651 } catch (error) { | 745 } catch (error) { |
652 try { | 746 try { |
653 x = c ? await fooError(error) : fooError(error); | 747 x = c ? await fooError(error) : fooError(error); |
654 } catch (error) { // nested error handler with overlapping name | 748 } catch (error) { // nested error handler with overlapping name |
655 y.x = foo(error); | 749 y.x = foo(error); |
656 } finally { | 750 } finally { |
657 foo(x); | 751 foo(x); |
658 } | 752 } |
659 } | 753 } |
660 } | 754 } |
661 """, """ | 755 """, """ |
662 function(c) { | 756 function(c, i) { |
663 var __goto = 0, __completer = new Completer(), __handler = null, x, y, __error
1, __error2; | 757 var __goto = 0, __completer = new Completer(), __handler = 1, __storedError, x
, y, __error1, __error2; |
664 function __helper(__result) { | 758 function __body(__errorCode, __result) { |
| 759 if (__errorCode == 1) { |
| 760 __storedError = __result; |
| 761 __goto = __handler; |
| 762 } |
665 while (true) | 763 while (true) |
666 try { | 764 try { |
667 switch (__goto) { | 765 switch (__goto) { |
668 case 0: | 766 case 0: |
669 // Function start | 767 // Function start |
670 __handler = 1; | 768 __handler = 2; |
671 __goto = c ? 4 : 6; | 769 __goto = c ? 5 : 7; |
672 break; | 770 break; |
673 case 4: | 771 case 5: |
674 // then | 772 // then |
675 __goto = 7; | 773 __goto = 8; |
676 return thenHelper(foo(), __helper, __completer, function(__error) { | 774 return thenHelper(foo(), __body, __completer); |
677 __goto = 1; | 775 case 8: |
678 __helper(__error); | |
679 }); | |
680 case 7: | |
681 // returning from await. | 776 // returning from await. |
682 // goto join | 777 // goto join |
683 __goto = 5; | 778 __goto = 6; |
684 break; | 779 break; |
685 case 6: | 780 case 7: |
686 // else | 781 // else |
687 __result = foo(); | 782 __result = foo(); |
688 case 5: | 783 case 6: |
689 // join | 784 // join |
690 x = __result; | 785 x = __result; |
691 y = {}; | 786 y = {}; |
692 __next = [3]; | 787 __next = [4]; |
693 __handler = null; | 788 __handler = 1; |
694 // goto after finally | 789 // goto after finally |
695 __goto = 3; | 790 __goto = 4; |
696 break; | 791 break; |
697 case 1: | 792 case 2: |
698 // catch | 793 // catch |
699 __handler = null; | 794 __handler = 1; |
700 __error1 = __result; | 795 __error1 = __storedError; |
701 __handler = 8; | 796 __handler = 9; |
702 __goto = c ? 11 : 13; | 797 __goto = c ? 12 : 14; |
703 break; | 798 break; |
704 case 11: | 799 case 12: |
705 // then | 800 // then |
706 __goto = 14; | 801 __goto = 15; |
707 return thenHelper(fooError(__error1), __helper, __completer, functio
n(__error) { | 802 return thenHelper(fooError(__error1), __body, __completer); |
708 __goto = 8; | 803 case 15: |
709 __helper(__error); | |
710 }); | |
711 case 14: | |
712 // returning from await. | 804 // returning from await. |
713 // goto join | 805 // goto join |
714 __goto = 12; | 806 __goto = 13; |
715 break; | 807 break; |
716 case 13: | 808 case 14: |
717 // else | 809 // else |
718 __result = fooError(__error1); | 810 __result = fooError(__error1); |
719 case 12: | 811 case 13: |
720 // join | 812 // join |
721 x = __result; | 813 x = __result; |
722 __next = [10]; | 814 __next = [11]; |
723 // goto finally | 815 // goto finally |
724 __goto = 9; | 816 __goto = 10; |
725 break; | 817 break; |
726 case 8: | 818 case 9: |
727 // catch | 819 // catch |
728 __handler = null; | 820 __handler = 10; |
729 __error2 = __result; | 821 __next = [1]; |
| 822 __error2 = __storedError; |
730 y.x = foo(__error2); | 823 y.x = foo(__error2); |
731 __handler = null; | 824 __handler = 1; |
732 __next = [10]; | 825 __next = [11]; |
733 case 9: | 826 case 10: |
734 // finally | 827 // finally |
735 __handler = null; | 828 __handler = 1; |
736 foo(x); | 829 foo(x); |
737 // goto the next finally handler | 830 // goto the next finally handler |
738 __goto = __next.pop(); | 831 __goto = __next.pop(); |
739 break; | 832 break; |
740 case 10: | 833 case 11: |
741 // after finally | 834 // after finally |
742 case 3: | 835 case 4: |
743 // after finally | 836 // after finally |
744 // implicit return | 837 // implicit return |
745 return thenHelper(null, null, __completer, null); | 838 return thenHelper(null, 0, __completer, null); |
| 839 case 1: |
| 840 // rethrow |
| 841 return thenHelper(__storedError, 1, __completer); |
746 } | 842 } |
747 } catch (__error) { | 843 } catch (__error) { |
748 if (__handler === null) | 844 __storedError = __error; |
749 throw __error; | |
750 __result = __error; | |
751 __goto = __handler; | 845 __goto = __handler; |
752 } | 846 } |
753 | 847 |
754 } | 848 } |
755 return thenHelper(null, __helper, __completer, null); | 849 return thenHelper(null, __body, __completer, null); |
756 }"""); | 850 }"""); |
757 testTransform(""" | 851 testTransform(""" |
758 function(x, y) async { | 852 function(x, y, j) async { |
759 print(await(foo(x))); // calls | 853 print(await(foo(x))); // calls |
760 (await print)(foo(x)); | 854 (await print)(foo(x)); |
761 print(foo(await x)); | 855 print(foo(await x)); |
762 await (print(foo(await x))); | 856 await (print(foo(await x))); |
763 print(foo(x, await y, z)); | 857 print(foo(x, await y, z)); |
764 } | 858 } |
765 """, """ | 859 """, """ |
766 function(x, y) { | 860 function(x, y, j) { |
767 var __goto = 0, __completer = new Completer(), __temp1, __temp2, __temp3; | 861 var __goto = 0, __completer = new Completer(), __handler = 1, __storedError, _
_temp1, __temp2, __temp3; |
768 function __helper(__result) { | 862 function __body(__errorCode, __result) { |
| 863 if (__errorCode == 1) { |
| 864 __storedError = __result; |
| 865 __goto = __handler; |
| 866 } |
769 while (true) | 867 while (true) |
770 switch (__goto) { | 868 try { |
771 case 0: | 869 switch (__goto) { |
772 // Function start | 870 case 0: |
773 __temp1 = print; | 871 // Function start |
774 __goto = 1; | 872 __temp1 = print; |
775 return thenHelper(foo(x), __helper, __completer, null); | 873 __goto = 2; |
776 case 1: | 874 return thenHelper(foo(x), __body, __completer); |
777 // returning from await. | 875 case 2: |
778 __temp1(__result); | 876 // returning from await. |
779 __goto = 2; | 877 __temp1(__result); |
780 return thenHelper(print, __helper, __completer, null); | 878 __goto = 3; |
781 case 2: | 879 return thenHelper(print, __body, __completer); |
782 // returning from await. | 880 case 3: |
783 __result(foo(x)); | 881 // returning from await. |
784 __temp1 = print; | 882 __result(foo(x)); |
785 __temp2 = foo; | 883 __temp1 = print; |
786 __goto = 3; | 884 __temp2 = foo; |
787 return thenHelper(x, __helper, __completer, null); | 885 __goto = 4; |
788 case 3: | 886 return thenHelper(x, __body, __completer); |
789 // returning from await. | 887 case 4: |
790 __temp1(__temp2(__result)); | 888 // returning from await. |
791 __temp1 = print; | 889 __temp1(__temp2(__result)); |
792 __temp2 = foo; | 890 __temp1 = print; |
793 __goto = 5; | 891 __temp2 = foo; |
794 return thenHelper(x, __helper, __completer, null); | 892 __goto = 6; |
795 case 5: | 893 return thenHelper(x, __body, __completer); |
796 // returning from await. | 894 case 6: |
797 __goto = 4; | 895 // returning from await. |
798 return thenHelper(__temp1(__temp2(__result)), __helper, __completer, n
ull); | 896 __goto = 5; |
799 case 4: | 897 return thenHelper(__temp1(__temp2(__result)), __body, __completer); |
800 // returning from await. | 898 case 5: |
801 __temp1 = print; | 899 // returning from await. |
802 __temp2 = foo; | 900 __temp1 = print; |
803 __temp3 = x; | 901 __temp2 = foo; |
804 __goto = 6; | 902 __temp3 = x; |
805 return thenHelper(y, __helper, __completer, null); | 903 __goto = 7; |
806 case 6: | 904 return thenHelper(y, __body, __completer); |
807 // returning from await. | 905 case 7: |
808 __temp1(__temp2(__temp3, __result, z)); | 906 // returning from await. |
809 // implicit return | 907 __temp1(__temp2(__temp3, __result, z)); |
810 return thenHelper(null, null, __completer, null); | 908 // implicit return |
| 909 return thenHelper(null, 0, __completer, null); |
| 910 case 1: |
| 911 // rethrow |
| 912 return thenHelper(__storedError, 1, __completer); |
| 913 } |
| 914 } catch (__error) { |
| 915 __storedError = __error; |
| 916 __goto = __handler; |
811 } | 917 } |
| 918 |
812 } | 919 } |
813 return thenHelper(null, __helper, __completer, null); | 920 return thenHelper(null, __body, __completer, null); |
814 }"""); | 921 }"""); |
815 testTransform(""" | 922 testTransform(""" |
816 function(x, y) async { | 923 function(x, y, k) async { |
817 while (await(foo())) { | 924 while (await(foo())) { |
818 lab: { // labelled statement | 925 lab: { // labelled statement |
819 switch(y) { | 926 switch(y) { |
820 case 0: | 927 case 0: |
821 foo(); | 928 foo(); |
822 case 0: // Duplicate case | 929 case 0: // Duplicate case |
823 print(await foo1(x)); | 930 print(await foo1(x)); |
824 return y; | 931 return y; |
825 case await bar(): // await in case | 932 case await bar(): // await in case |
826 print(await foobar(x)); | 933 print(await foobar(x)); |
827 return y; | 934 return y; |
828 case x: | 935 case x: |
829 if (a) { | 936 if (a) { |
830 throw new Error(); | 937 throw new Error(); |
831 } else { | 938 } else { |
832 continue; | 939 continue; |
833 } | 940 } |
834 default: // defaul case | 941 default: // defaul case |
835 break lab; // break to label | 942 break lab; // break to label |
836 } | 943 } |
837 foo(); | 944 foo(); |
838 } | 945 } |
839 } | 946 } |
840 }""", """ | 947 }""", """ |
841 function(x, y) { | 948 function(x, y, k) { |
842 var __goto = 0, __completer = new Completer(), __returnValue, __temp1; | 949 var __goto = 0, __completer = new Completer(), __handler = 2, __storedError, _
_returnValue, __temp1; |
843 function __helper(__result) { | 950 function __body(__errorCode, __result) { |
| 951 if (__errorCode == 1) { |
| 952 __storedError = __result; |
| 953 __goto = __handler; |
| 954 } |
844 while (true) | 955 while (true) |
845 switch (__goto) { | 956 try { |
846 case 0: | 957 switch (__goto) { |
847 // Function start | 958 case 0: |
848 case 2: | 959 // Function start |
849 // while condition | 960 case 3: |
850 __goto = 4; | 961 // while condition |
851 return thenHelper(foo(), __helper, __completer, null); | 962 __goto = 5; |
852 case 4: | 963 return thenHelper(foo(), __body, __completer); |
853 // returning from await. | 964 case 5: |
854 if (!__result) { | 965 // returning from await. |
855 // goto after while | 966 if (!__result) { |
| 967 // goto after while |
| 968 __goto = 4; |
| 969 break; |
| 970 } |
| 971 case 7: |
| 972 // continue lab |
| 973 case 8: |
| 974 // switch |
| 975 __temp1 = y; |
| 976 if (__temp1 === 0) { |
| 977 // goto case |
| 978 __goto = 10; |
| 979 break; |
| 980 } |
| 981 if (__temp1 === 0) { |
| 982 // goto case |
| 983 __goto = 11; |
| 984 break; |
| 985 } |
| 986 __goto = 13; |
| 987 return thenHelper(bar(), __body, __completer); |
| 988 case 13: |
| 989 // returning from await. |
| 990 if (__temp1 === __result) { |
| 991 // goto case |
| 992 __goto = 12; |
| 993 break; |
| 994 } |
| 995 if (__temp1 === x) { |
| 996 // goto case |
| 997 __goto = 14; |
| 998 break; |
| 999 } |
| 1000 // goto default |
| 1001 __goto = 15; |
| 1002 break; |
| 1003 case 10: |
| 1004 // case |
| 1005 foo(); |
| 1006 case 11: |
| 1007 // case |
| 1008 __temp1 = print; |
| 1009 __goto = 16; |
| 1010 return thenHelper(foo1(x), __body, __completer); |
| 1011 case 16: |
| 1012 // returning from await. |
| 1013 __temp1(__result); |
| 1014 __returnValue = y; |
| 1015 // goto return |
| 1016 __goto = 1; |
| 1017 break; |
| 1018 case 12: |
| 1019 // case |
| 1020 __temp1 = print; |
| 1021 __goto = 17; |
| 1022 return thenHelper(foobar(x), __body, __completer); |
| 1023 case 17: |
| 1024 // returning from await. |
| 1025 __temp1(__result); |
| 1026 __returnValue = y; |
| 1027 // goto return |
| 1028 __goto = 1; |
| 1029 break; |
| 1030 case 14: |
| 1031 // case |
| 1032 if (a) { |
| 1033 throw new Error(); |
| 1034 } else { |
| 1035 // goto while condition |
| 1036 __goto = 3; |
| 1037 break; |
| 1038 } |
| 1039 case 15: |
| 1040 // default |
| 1041 // goto break lab |
| 1042 __goto = 6; |
| 1043 break; |
| 1044 case 9: |
| 1045 // after switch |
| 1046 foo(); |
| 1047 case 6: |
| 1048 // break lab |
| 1049 // goto while condition |
856 __goto = 3; | 1050 __goto = 3; |
857 break; | 1051 break; |
858 } | 1052 case 4: |
859 case 6: | 1053 // after while |
860 // continue lab | 1054 case 1: |
861 case 7: | 1055 // return |
862 // switch | 1056 return thenHelper(__returnValue, 0, __completer, null); |
863 __temp1 = y; | 1057 case 2: |
864 if (__temp1 === 0) { | 1058 // rethrow |
865 // goto case | 1059 return thenHelper(__storedError, 1, __completer); |
866 __goto = 9; | 1060 } |
867 break; | 1061 } catch (__error) { |
868 } | 1062 __storedError = __error; |
869 if (__temp1 === 0) { | 1063 __goto = __handler; |
870 // goto case | |
871 __goto = 10; | |
872 break; | |
873 } | |
874 __goto = 12; | |
875 return thenHelper(bar(), __helper, __completer, null); | |
876 case 12: | |
877 // returning from await. | |
878 if (__temp1 === __result) { | |
879 // goto case | |
880 __goto = 11; | |
881 break; | |
882 } | |
883 if (__temp1 === x) { | |
884 // goto case | |
885 __goto = 13; | |
886 break; | |
887 } | |
888 // goto default | |
889 __goto = 14; | |
890 break; | |
891 case 9: | |
892 // case | |
893 foo(); | |
894 case 10: | |
895 // case | |
896 __temp1 = print; | |
897 __goto = 15; | |
898 return thenHelper(foo1(x), __helper, __completer, null); | |
899 case 15: | |
900 // returning from await. | |
901 __temp1(__result); | |
902 __returnValue = y; | |
903 // goto return | |
904 __goto = 1; | |
905 break; | |
906 case 11: | |
907 // case | |
908 __temp1 = print; | |
909 __goto = 16; | |
910 return thenHelper(foobar(x), __helper, __completer, null); | |
911 case 16: | |
912 // returning from await. | |
913 __temp1(__result); | |
914 __returnValue = y; | |
915 // goto return | |
916 __goto = 1; | |
917 break; | |
918 case 13: | |
919 // case | |
920 if (a) { | |
921 throw new Error(); | |
922 } else { | |
923 // goto while condition | |
924 __goto = 2; | |
925 break; | |
926 } | |
927 case 14: | |
928 // default | |
929 // goto break lab | |
930 __goto = 5; | |
931 break; | |
932 case 8: | |
933 // after switch | |
934 foo(); | |
935 case 5: | |
936 // break lab | |
937 // goto while condition | |
938 __goto = 2; | |
939 break; | |
940 case 3: | |
941 // after while | |
942 case 1: | |
943 // return | |
944 return thenHelper(__returnValue, null, __completer, null); | |
945 } | 1064 } |
| 1065 |
946 } | 1066 } |
947 return thenHelper(null, __helper, __completer, null); | 1067 return thenHelper(null, __body, __completer, null); |
948 }"""); | 1068 }"""); |
949 } | 1069 } |
OLD | NEW |