Chromium Code Reviews| Index: pkg/stack_trace/lib/src/chain.dart |
| diff --git a/pkg/stack_trace/lib/src/chain.dart b/pkg/stack_trace/lib/src/chain.dart |
| index 4055bc847c7e1bb70f229627f4a55b371d7273c4..c1e0b8d1c708eb8f3ef38707306318a6ef29ece2 100644 |
| --- a/pkg/stack_trace/lib/src/chain.dart |
| +++ b/pkg/stack_trace/lib/src/chain.dart |
| @@ -7,6 +7,7 @@ library stack_trace.chain; |
| import 'dart:async'; |
| import 'dart:collection'; |
| +import 'frame.dart'; |
| import 'stack_zone_specification.dart'; |
| import 'trace.dart'; |
| import 'utils.dart'; |
| @@ -172,6 +173,31 @@ class Chain implements StackTrace { |
| return new Chain(nonEmptyTraces); |
| } |
| + /// Returns a new [Chain] based on [this] where multiple stack frames matching |
| + /// [predicate] are folded together. |
| + /// |
| + /// This means that whenever there are multiple frames in a row that match |
| + /// [predicate], only the last one is kept. In addition, traces that are |
| + /// composed entirely of frames matching [predicate] are omitted. |
| + /// |
| + /// This is useful for limiting the amount of library code that appears in a |
| + /// stack trace by only showing user code and code that's called by user code. |
| + Chain foldFrames(bool predicate(Frame frame)) { |
| + var foldedTraces = traces.map((trace) => trace.foldFrames(predicate)); |
| + var nonEmptyTraces = foldedTraces.where((trace) { |
| + // Ignore traces that contain only internal processing. |
| + 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.
|
| + }); |
| + |
| + // If all the traces contain only internal processing, preserve the last |
| + // (top-most) one so that the chain isn't empty. |
| + if (nonEmptyTraces.isEmpty && foldedTraces.isNotEmpty) { |
| + return new Chain([foldedTraces.last]); |
| + } |
| + |
| + return new Chain(nonEmptyTraces); |
| + } |
| + |
| /// Converts [this] to a [Trace]. |
| /// |
| /// The trace version of a chain is just the concatenation of all the traces |