Chromium Code Reviews| 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 'frame.dart'; | |
| 10 import 'stack_zone_specification.dart'; | 11 import 'stack_zone_specification.dart'; |
| 11 import 'trace.dart'; | 12 import 'trace.dart'; |
| 12 import 'utils.dart'; | 13 import 'utils.dart'; |
| 13 | 14 |
| 14 /// A function that handles errors in the zone wrapped by [Chain.capture]. | 15 /// A function that handles errors in the zone wrapped by [Chain.capture]. |
| 15 typedef void ChainHandler(error, Chain chain); | 16 typedef void ChainHandler(error, Chain chain); |
| 16 | 17 |
| 17 /// A chain of stack traces. | 18 /// A chain of stack traces. |
| 18 /// | 19 /// |
| 19 /// A stack chain is a collection of one or more stack traces that collectively | 20 /// A stack chain is a collection of one or more stack traces that collectively |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 166 |
| 166 // If all the traces contain only internal processing, preserve the last | 167 // If all the traces contain only internal processing, preserve the last |
| 167 // (top-most) one so that the chain isn't empty. | 168 // (top-most) one so that the chain isn't empty. |
| 168 if (nonEmptyTraces.isEmpty && terseTraces.isNotEmpty) { | 169 if (nonEmptyTraces.isEmpty && terseTraces.isNotEmpty) { |
| 169 return new Chain([terseTraces.last]); | 170 return new Chain([terseTraces.last]); |
| 170 } | 171 } |
| 171 | 172 |
| 172 return new Chain(nonEmptyTraces); | 173 return new Chain(nonEmptyTraces); |
| 173 } | 174 } |
| 174 | 175 |
| 176 /// Returns a new [Chain] based on [this] where multiple stack frames matching | |
| 177 /// [predicate] are folded together. | |
| 178 /// | |
| 179 /// This means that whenever there are multiple frames in a row that match | |
| 180 /// [predicate], only the last one is kept. In addition, traces that are | |
| 181 /// composed entirely of frames matching [predicate] are omitted. | |
| 182 /// | |
| 183 /// This is useful for limiting the amount of library code that appears in a | |
| 184 /// stack trace by only showing user code and code that's called by user code. | |
| 185 Chain foldFrames(bool predicate(Frame frame)) { | |
| 186 var foldedTraces = traces.map((trace) => trace.foldFrames(predicate)); | |
| 187 var nonEmptyTraces = foldedTraces.where((trace) { | |
| 188 // Ignore traces that contain only internal processing. | |
| 189 return trace.frames.length > 1; | |
|
Bob Nystrom
2014/02/25 22:10:59
Why isn't this .isNotEmpty?
nweiz
2014/02/25 22:38:08
We want to omit chains that contain only a single
Bob Nystrom
2014/02/25 22:58:31
Ah, got it. Clarify the comment then.
nweiz
2014/02/25 23:19:46
Done.
| |
| 190 }); | |
| 191 | |
| 192 // If all the traces contain only internal processing, preserve the last | |
| 193 // (top-most) one so that the chain isn't empty. | |
| 194 if (nonEmptyTraces.isEmpty && foldedTraces.isNotEmpty) { | |
| 195 return new Chain([foldedTraces.last]); | |
| 196 } | |
| 197 | |
| 198 return new Chain(nonEmptyTraces); | |
| 199 } | |
| 200 | |
| 175 /// Converts [this] to a [Trace]. | 201 /// Converts [this] to a [Trace]. |
| 176 /// | 202 /// |
| 177 /// The trace version of a chain is just the concatenation of all the traces | 203 /// The trace version of a chain is just the concatenation of all the traces |
| 178 /// in the chain. | 204 /// in the chain. |
| 179 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames))); | 205 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames))); |
| 180 | 206 |
| 181 String toString() => traces.join(_GAP); | 207 String toString() => traces.join(_GAP); |
| 182 } | 208 } |
| OLD | NEW |