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 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 | 8 |
9 import 'frame.dart'; | 9 import 'frame.dart'; |
10 import 'stack_zone_specification.dart'; | 10 import 'stack_zone_specification.dart'; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 static /*=T*/ capture/*<T>*/(/*=T*/ callback(), | 71 static /*=T*/ capture/*<T>*/(/*=T*/ callback(), |
72 {void onError(error, Chain chain), bool when: true}) { | 72 {void onError(error, Chain chain), bool when: true}) { |
73 if (!when) { | 73 if (!when) { |
74 var newOnError; | 74 var newOnError; |
75 if (onError != null) { | 75 if (onError != null) { |
76 newOnError = (error, stackTrace) { | 76 newOnError = (error, stackTrace) { |
77 onError(error, new Chain.forTrace(stackTrace)); | 77 onError(error, new Chain.forTrace(stackTrace)); |
78 }; | 78 }; |
79 } | 79 } |
80 | 80 |
81 return runZoned(callback, onError: newOnError); | 81 // TODO(rnystrom): Remove this cast if runZoned() gets a generic type. |
| 82 return runZoned(callback, onError: newOnError) as dynamic/*=T*/; |
82 } | 83 } |
83 | 84 |
84 var spec = new StackZoneSpecification(onError); | 85 var spec = new StackZoneSpecification(onError); |
85 return runZoned(() { | 86 return runZoned(() { |
86 try { | 87 try { |
87 return callback(); | 88 return callback(); |
88 } catch (error, stackTrace) { | 89 } catch (error, stackTrace) { |
89 // TODO(nweiz): Don't special-case this when issue 19566 is fixed. | 90 // TODO(nweiz): Don't special-case this when issue 19566 is fixed. |
90 return Zone.current.handleUncaughtError(error, stackTrace); | 91 return Zone.current.handleUncaughtError(error, stackTrace); |
91 } | 92 } |
92 }, zoneSpecification: spec.toSpec(), zoneValues: { | 93 }, zoneSpecification: spec.toSpec(), zoneValues: { |
93 #stack_trace.stack_zone.spec: spec | 94 #stack_trace.stack_zone.spec: spec |
94 }); | 95 }) as dynamic/*=T*/; |
| 96 // TODO(rnystrom): Remove this cast if runZoned() gets a generic type. |
95 } | 97 } |
96 | 98 |
97 /// Returns [futureOrStream] unmodified. | 99 /// Returns [futureOrStream] unmodified. |
98 /// | 100 /// |
99 /// Prior to Dart 1.7, this was necessary to ensure that stack traces for | 101 /// Prior to Dart 1.7, this was necessary to ensure that stack traces for |
100 /// exceptions reported with [Completer.completeError] and | 102 /// exceptions reported with [Completer.completeError] and |
101 /// [StreamController.addError] were tracked correctly. | 103 /// [StreamController.addError] were tracked correctly. |
102 @Deprecated("Chain.track is not necessary in Dart 1.7+.") | 104 @Deprecated("Chain.track is not necessary in Dart 1.7+.") |
103 static track(futureOrStream) => futureOrStream; | 105 static track(futureOrStream) => futureOrStream; |
104 | 106 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 206 |
205 // Don't call out to [Trace.toString] here because that doesn't ensure that | 207 // Don't call out to [Trace.toString] here because that doesn't ensure that |
206 // padding is consistent across all traces. | 208 // padding is consistent across all traces. |
207 return traces.map((trace) { | 209 return traces.map((trace) { |
208 return trace.frames.map((frame) { | 210 return trace.frames.map((frame) { |
209 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 211 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
210 }).join(); | 212 }).join(); |
211 }).join(chainGap); | 213 }).join(chainGap); |
212 } | 214 } |
213 } | 215 } |
OLD | NEW |