| 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 library stack_trace.chain; | 5 library stack_trace.chain; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:math' as math; | 9 import 'dart:math' as math; |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 /// error. Note that if [callback] produces multiple unhandled errors, | 61 /// error. Note that if [callback] produces multiple unhandled errors, |
| 62 /// [onError] may be called more than once. If [onError] isn't passed, the | 62 /// [onError] may be called more than once. If [onError] isn't passed, the |
| 63 /// parent Zone's `unhandledErrorHandler` will be called with the error and | 63 /// parent Zone's `unhandledErrorHandler` will be called with the error and |
| 64 /// its chain. | 64 /// its chain. |
| 65 /// | 65 /// |
| 66 /// Note that even if [onError] isn't passed, this zone will still be an error | 66 /// Note that even if [onError] isn't passed, this zone will still be an error |
| 67 /// zone. This means that any errors that would cross the zone boundary are | 67 /// zone. This means that any errors that would cross the zone boundary are |
| 68 /// considered unhandled. | 68 /// considered unhandled. |
| 69 /// | 69 /// |
| 70 /// If [callback] returns a value, it will be returned by [capture] as well. | 70 /// If [callback] returns a value, it will be returned by [capture] as well. |
| 71 /// | |
| 72 /// Currently, capturing stack chains doesn't work when using dart2js due to | |
| 73 /// issues [15171] and [15105]. Stack chains reported on dart2js will contain | |
| 74 /// only one trace. | |
| 75 /// | |
| 76 /// [15171]: https://code.google.com/p/dart/issues/detail?id=15171 | |
| 77 /// [15105]: https://code.google.com/p/dart/issues/detail?id=15105 | |
| 78 static capture(callback(), {ChainHandler onError}) { | 71 static capture(callback(), {ChainHandler onError}) { |
| 79 var spec = new StackZoneSpecification(onError); | 72 var spec = new StackZoneSpecification(onError); |
| 80 return runZoned(() { | 73 return runZoned(() { |
| 81 try { | 74 try { |
| 82 return callback(); | 75 return callback(); |
| 83 } catch (error, stackTrace) { | 76 } catch (error, stackTrace) { |
| 84 // TODO(nweiz): Don't special-case this when issue 19566 is fixed. | 77 // TODO(nweiz): Don't special-case this when issue 19566 is fixed. |
| 85 return Zone.current.handleUncaughtError(error, stackTrace); | 78 return Zone.current.handleUncaughtError(error, stackTrace); |
| 86 } | 79 } |
| 87 }, zoneSpecification: spec.toSpec(), zoneValues: { | 80 }, zoneSpecification: spec.toSpec(), zoneValues: { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 187 |
| 195 // Don't call out to [Trace.toString] here because that doesn't ensure that | 188 // Don't call out to [Trace.toString] here because that doesn't ensure that |
| 196 // padding is consistent across all traces. | 189 // padding is consistent across all traces. |
| 197 return traces.map((trace) { | 190 return traces.map((trace) { |
| 198 return trace.frames.map((frame) { | 191 return trace.frames.map((frame) { |
| 199 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 192 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
| 200 }).join(); | 193 }).join(); |
| 201 }).join(_gap); | 194 }).join(_gap); |
| 202 } | 195 } |
| 203 } | 196 } |
| OLD | NEW |