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 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:stack_trace/stack_trace.dart'; | 7 import 'package:stack_trace/stack_trace.dart'; |
8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
9 | 9 |
10 /// Runs [callback] in a microtask callback. | 10 /// Runs [callback] in a microtask callback. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 Future<Chain> chainForTrace(asyncFn(callback()), callback()) { | 66 Future<Chain> chainForTrace(asyncFn(callback()), callback()) { |
67 var completer = new Completer(); | 67 var completer = new Completer(); |
68 asyncFn(() { | 68 asyncFn(() { |
69 // We use `new Future.value().then(...)` here as opposed to [new Future] or | 69 // We use `new Future.value().then(...)` here as opposed to [new Future] or |
70 // [new Future.sync] because those methods don't pass the exception through | 70 // [new Future.sync] because those methods don't pass the exception through |
71 // the zone specification before propagating it, so there's no chance to | 71 // the zone specification before propagating it, so there's no chance to |
72 // attach a chain to its stack trace. See issue 15105. | 72 // attach a chain to its stack trace. See issue 15105. |
73 new Future.value().then((_) => callback()) | 73 new Future.value().then((_) => callback()) |
74 .catchError(completer.completeError); | 74 .catchError(completer.completeError); |
75 }); | 75 }); |
| 76 |
| 77 // TODO(rnystrom): Remove this cast if catchError() gets a better type. |
76 return completer.future | 78 return completer.future |
77 .catchError((_, stackTrace) => new Chain.forTrace(stackTrace)); | 79 .catchError((_, stackTrace) => new Chain.forTrace(stackTrace)) |
| 80 as Future<Chain>; |
78 } | 81 } |
79 | 82 |
80 /// Runs [callback] in a [Chain.capture] zone and returns a Future that | 83 /// Runs [callback] in a [Chain.capture] zone and returns a Future that |
81 /// completes to the stack chain for an error thrown by [callback]. | 84 /// completes to the stack chain for an error thrown by [callback]. |
82 /// | 85 /// |
83 /// [callback] is expected to throw the string `"error"`. | 86 /// [callback] is expected to throw the string `"error"`. |
84 Future<Chain> captureFuture(callback()) { | 87 Future<Chain> captureFuture(callback()) { |
85 var completer = new Completer<Chain>(); | 88 var completer = new Completer<Chain>(); |
86 Chain.capture(callback, onError: (error, chain) { | 89 Chain.capture(callback, onError: (error, chain) { |
87 expect(error, equals('error')); | 90 expect(error, equals('error')); |
88 completer.complete(chain); | 91 completer.complete(chain); |
89 }); | 92 }); |
90 return completer.future; | 93 return completer.future; |
91 } | 94 } |
OLD | NEW |