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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 /// If [trace] is already a [Chain], it will be returned as-is. | 120 /// If [trace] is already a [Chain], it will be returned as-is. |
121 factory Chain.forTrace(StackTrace trace) { | 121 factory Chain.forTrace(StackTrace trace) { |
122 if (trace is Chain) return trace; | 122 if (trace is Chain) return trace; |
123 if (_currentSpec == null) return new Chain([new Trace.from(trace)]); | 123 if (_currentSpec == null) return new Chain([new Trace.from(trace)]); |
124 return _currentSpec.chainFor(trace); | 124 return _currentSpec.chainFor(trace); |
125 } | 125 } |
126 | 126 |
127 /// Parses a string representation of a stack chain. | 127 /// Parses a string representation of a stack chain. |
128 /// | 128 /// |
129 /// Specifically, this parses the output of [Chain.toString]. | 129 /// Specifically, this parses the output of [Chain.toString]. |
130 factory Chain.parse(String chain) => | 130 factory Chain.parse(String chain) { |
131 new Chain(chain.split(_gap).map((trace) => new Trace.parseFriendly(trace))); | 131 if (chain.isEmpty) return new Chain([]); |
| 132 return new Chain( |
| 133 chain.split(_gap).map((trace) => new Trace.parseFriendly(trace))); |
| 134 } |
132 | 135 |
133 /// Returns a new [Chain] comprised of [traces]. | 136 /// Returns a new [Chain] comprised of [traces]. |
134 Chain(Iterable<Trace> traces) | 137 Chain(Iterable<Trace> traces) |
135 : traces = new UnmodifiableListView<Trace>(traces.toList()); | 138 : traces = new UnmodifiableListView<Trace>(traces.toList()); |
136 | 139 |
137 /// Returns a terser version of [this]. | 140 /// Returns a terser version of [this]. |
138 /// | 141 /// |
139 /// This calls [Trace.terse] on every trace in [traces], and discards any | 142 /// This calls [Trace.terse] on every trace in [traces], and discards any |
140 /// trace that contain only internal frames. | 143 /// trace that contain only internal frames. |
141 Chain get terse => foldFrames((_) => false, terse: true); | 144 Chain get terse => foldFrames((_) => false, terse: true); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 194 |
192 // Don't call out to [Trace.toString] here because that doesn't ensure that | 195 // Don't call out to [Trace.toString] here because that doesn't ensure that |
193 // padding is consistent across all traces. | 196 // padding is consistent across all traces. |
194 return traces.map((trace) { | 197 return traces.map((trace) { |
195 return trace.frames.map((frame) { | 198 return trace.frames.map((frame) { |
196 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 199 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
197 }).join(); | 200 }).join(); |
198 }).join(_gap); | 201 }).join(_gap); |
199 } | 202 } |
200 } | 203 } |
OLD | NEW |