| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:async_helper/async_helper.dart'; | 5 import 'package:async_helper/async_helper.dart'; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'catch_errors.dart'; | 8 import 'catch_errors.dart'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 asyncStart(); | 11 asyncStart(); |
| 12 Completer done = new Completer(); | 12 Completer done = new Completer(); |
| 13 | 13 |
| 14 var events = []; | 14 var events = []; |
| 15 // Work around bug that makes runAsync use Timers. By invoking `runAsync` here | 15 // Work around bug that makes scheduleMicrotask use Timers. By invoking |
| 16 // we make sure that asynchronous non-timer events are executed before any | 16 // `scheduleMicrotask` here we make sure that asynchronous non-timer events |
| 17 // Timer events. | 17 // are executed before any Timer events. |
| 18 runAsync(() { }); | 18 scheduleMicrotask(() { }); |
| 19 | 19 |
| 20 // Test that errors are caught by nested `catchErrors`. Also uses `runAsync` | 20 // Test that errors are caught by nested `catchErrors`. Also uses |
| 21 // in the body of a Timer. | 21 // `scheduleMicrotask` in the body of a Timer. |
| 22 catchErrors(() { | 22 catchErrors(() { |
| 23 events.add("catch error entry"); | 23 events.add("catch error entry"); |
| 24 catchErrors(() { | 24 catchErrors(() { |
| 25 events.add("catch error entry2"); | 25 events.add("catch error entry2"); |
| 26 Timer.run(() { throw "timer error"; }); | 26 Timer.run(() { throw "timer error"; }); |
| 27 new Timer(const Duration(milliseconds: 50), | 27 new Timer(const Duration(milliseconds: 50), |
| 28 () { | 28 () { |
| 29 runAsync(() { throw "runAsync"; }); | 29 scheduleMicrotask(() { throw "scheduleMicrotask"; }); |
| 30 throw "delayed error"; | 30 throw "delayed error"; |
| 31 }); | 31 }); |
| 32 }).listen((x) { | 32 }).listen((x) { |
| 33 events.add(x); | 33 events.add(x); |
| 34 if (x == "runAsync") { | 34 if (x == "scheduleMicrotask") { |
| 35 throw "inner done throw"; | 35 throw "inner done throw"; |
| 36 } | 36 } |
| 37 }); | 37 }); |
| 38 events.add("after inner"); | 38 events.add("after inner"); |
| 39 Timer.run(() { throw "timer outer"; }); | 39 Timer.run(() { throw "timer outer"; }); |
| 40 throw "inner throw"; | 40 throw "inner throw"; |
| 41 }).listen((x) { | 41 }).listen((x) { |
| 42 events.add(x); | 42 events.add(x); |
| 43 if (x == "inner done throw") done.complete(true); | 43 if (x == "inner done throw") done.complete(true); |
| 44 }, | 44 }, |
| 45 onDone: () { Expect.fail("Unexpected callback"); }); | 45 onDone: () { Expect.fail("Unexpected callback"); }); |
| 46 | 46 |
| 47 done.future.whenComplete(() { | 47 done.future.whenComplete(() { |
| 48 // Give callbacks time to run. | 48 // Give callbacks time to run. |
| 49 Timer.run(() { | 49 Timer.run(() { |
| 50 Expect.listEquals([ | 50 Expect.listEquals([ |
| 51 "catch error entry", | 51 "catch error entry", |
| 52 "catch error entry2", | 52 "catch error entry2", |
| 53 "after inner", | 53 "after inner", |
| 54 "main exit", | 54 "main exit", |
| 55 "inner throw", | 55 "inner throw", |
| 56 "timer error", | 56 "timer error", |
| 57 "timer outer", | 57 "timer outer", |
| 58 "delayed error", | 58 "delayed error", |
| 59 "runAsync", | 59 "scheduleMicrotask", |
| 60 "inner done throw" | 60 "inner done throw" |
| 61 ], | 61 ], |
| 62 events); | 62 events); |
| 63 asyncEnd(); | 63 asyncEnd(); |
| 64 }); | 64 }); |
| 65 }); | 65 }); |
| 66 events.add("main exit"); | 66 events.add("main exit"); |
| 67 } | 67 } |
| OLD | NEW |