| 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 | 9 |
| 10 import 'stack_zone_specification.dart'; | 10 import 'stack_zone_specification.dart'; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 /// Returns a new [Chain] comprised of [traces]. | 151 /// Returns a new [Chain] comprised of [traces]. |
| 152 Chain(Iterable<Trace> traces) | 152 Chain(Iterable<Trace> traces) |
| 153 : traces = new UnmodifiableListView<Trace>(traces.toList()); | 153 : traces = new UnmodifiableListView<Trace>(traces.toList()); |
| 154 | 154 |
| 155 /// Returns a terser version of [this]. | 155 /// Returns a terser version of [this]. |
| 156 /// | 156 /// |
| 157 /// This calls [Trace.terse] on every trace in [traces], and discards any | 157 /// This calls [Trace.terse] on every trace in [traces], and discards any |
| 158 /// trace that contain only internal frames. | 158 /// trace that contain only internal frames. |
| 159 Chain get terse { | 159 Chain get terse { |
| 160 return new Chain(traces.map((trace) => trace.terse).where((trace) { | 160 var terseTraces = traces.map((trace) => trace.terse); |
| 161 var nonEmptyTraces = terseTraces.where((trace) { |
| 161 // Ignore traces that contain only internal processing. | 162 // Ignore traces that contain only internal processing. |
| 162 return trace.frames.length > 1; | 163 return trace.frames.length > 1; |
| 163 })); | 164 }); |
| 165 |
| 166 // If all the traces contain only internal processing, preserve the last |
| 167 // (top-most) one so that the chain isn't empty. |
| 168 if (nonEmptyTraces.isEmpty && terseTraces.isNotEmpty) { |
| 169 return new Chain([terseTraces.last]); |
| 170 } |
| 171 |
| 172 return new Chain(nonEmptyTraces); |
| 164 } | 173 } |
| 165 | 174 |
| 166 /// Converts [this] to a [Trace]. | 175 /// Converts [this] to a [Trace]. |
| 167 /// | 176 /// |
| 168 /// The trace version of a chain is just the concatenation of all the traces | 177 /// The trace version of a chain is just the concatenation of all the traces |
| 169 /// in the chain. | 178 /// in the chain. |
| 170 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames))); | 179 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames))); |
| 171 | 180 |
| 172 String toString() => traces.join(_GAP); | 181 String toString() => traces.join(_GAP); |
| 173 } | 182 } |
| OLD | NEW |