| 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:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 Completer done = new Completer(); | 10 Completer done = new Completer(); |
| 11 List events = []; | 11 List events = []; |
| 12 | 12 |
| 13 // runGuarded calls run, captures the synchronous error (if any) and | 13 // runGuarded calls run, captures the synchronous error (if any) and |
| 14 // gives that one to handleUncaughtError. | 14 // gives that one to handleUncaughtError. |
| 15 | 15 |
| 16 Expect.identical(Zone.ROOT, Zone.current); | 16 Expect.identical(Zone.ROOT, Zone.current); |
| 17 Zone forked; | 17 Zone forked; |
| 18 forked = Zone.current.fork(specification: new ZoneSpecification( | 18 forked = Zone.current.fork(specification: new ZoneSpecification( |
| 19 run: (Zone self, ZoneDelegate parent, Zone origin, f()) { | 19 run: (Zone self, ZoneDelegate parent, Zone origin, f()) { |
| 20 // The zone is still the same as when origin.run was invoked, which | 20 // The zone is still the same as when origin.run was invoked, which |
| 21 // is the root zone. (The origin zone hasn't been set yet). | 21 // is the root zone. (The origin zone hasn't been set yet). |
| 22 Expect.identical(Zone.ROOT, Zone.current); | 22 Expect.identical(Zone.ROOT, Zone.current); |
| 23 events.add("forked.run"); | 23 events.add("forked.run"); |
| 24 return parent.run(origin, f); | 24 return parent.run(origin, f); |
| 25 }, | 25 }, |
| 26 handleUncaughtError: (Zone self, ZoneDelegate parent, Zone origin, e) { | 26 handleUncaughtError: |
| 27 (Zone self, ZoneDelegate parent, Zone origin, error, stackTrace) { |
| 27 Expect.identical(Zone.ROOT, Zone.current); | 28 Expect.identical(Zone.ROOT, Zone.current); |
| 28 Expect.identical(forked, origin); | 29 Expect.identical(forked, origin); |
| 29 events.add("forked.handleUncaught $e"); | 30 events.add("forked.handleUncaught $error"); |
| 30 return 499; | 31 return 499; |
| 31 })); | 32 })); |
| 32 | 33 |
| 33 var result = forked.runGuarded(() { | 34 var result = forked.runGuarded(() { |
| 34 events.add("runGuarded 1"); | 35 events.add("runGuarded 1"); |
| 35 Expect.identical(forked, Zone.current); | 36 Expect.identical(forked, Zone.current); |
| 36 return 42; | 37 return 42; |
| 37 }); | 38 }); |
| 38 Expect.identical(Zone.ROOT, Zone.current); | 39 Expect.identical(Zone.ROOT, Zone.current); |
| 39 Expect.equals(42, result); | 40 Expect.equals(42, result); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 69 | 70 |
| 70 done.future.whenComplete(() { | 71 done.future.whenComplete(() { |
| 71 Expect.listEquals( | 72 Expect.listEquals( |
| 72 ["forked.run", "run closure", "forked.handleUncaught 1234", | 73 ["forked.run", "run closure", "forked.handleUncaught 1234", |
| 73 "after nested runAsync", "forked.run", "run closure 2", | 74 "after nested runAsync", "forked.run", "run closure 2", |
| 74 "forked.handleUncaught 88" ], | 75 "forked.handleUncaught 88" ], |
| 75 events); | 76 events); |
| 76 asyncEnd(); | 77 asyncEnd(); |
| 77 }); | 78 }); |
| 78 } | 79 } |
| OLD | NEW |