Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2162)

Unified Diff: lib/src/trace.dart

Issue 917423002: Add a "terse" argument to foldFrames(). (Closed) Base URL: git@github.com:dart-lang/stack_trace@master
Patch Set: Code review changes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/chain.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/trace.dart
diff --git a/lib/src/trace.dart b/lib/src/trace.dart
index 5cd09e9bb7fe0774e06ac6297667597dfb19e57e..53dbe33e4c2e9c1724e806e364bf9f5ac95fc209 100644
--- a/lib/src/trace.dart
+++ b/lib/src/trace.dart
@@ -203,36 +203,43 @@ class Trace implements StackTrace {
/// core library or from this package, as in [foldFrames]. Remaining core
/// library frames have their libraries, "-patch" suffixes, and line numbers
/// removed.
- Trace get terse {
- return new Trace(foldFrames((frame) {
- if (frame.isCore) return true;
- if (frame.package == 'stack_trace') return true;
-
- // Ignore async stack frames without any line or column information. These
- // come from the VM's async/await implementation and represent internal
- // frames. They only ever show up in stack chains and are always
- // surrounded by other traces that are actually useful, so we can just get
- // rid of them.
- // TODO(nweiz): Get rid of this logic some time after issue 22009 is
- // fixed.
- if (!frame.member.contains('<async>')) return false;
- return frame.line == null;
- }).frames.map((frame) {
- if (!frame.isCore) return frame;
- var library = frame.library.replaceAll(_terseRegExp, '');
- return new Frame(Uri.parse(library), null, null, frame.member);
- }));
- }
+ ///
+ /// For custom folding, see [foldFrames].
+ Trace get terse => foldFrames((_) => false, terse: true);
/// Returns a new [Trace] 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.
+ /// [predicate] are folded together.
///
- /// 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.
- Trace foldFrames(bool predicate(Frame frame)) {
- var newFrames = <Frame>[];
+ /// This means that whenever there are multiple frames in a row that match
+ /// [predicate], only the last one is kept. 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.
+ ///
+ /// If [terse] is true, this will also fold together frames from the core
+ /// library or from this package, and simplify core library frames as in
+ /// [Trace.terse].
+ Trace foldFrames(bool predicate(Frame frame), {bool terse: false}) {
+ if (terse) {
+ var oldPredicate = predicate;
+ predicate = (frame) {
+ if (oldPredicate(frame)) return true;
+
+ if (frame.isCore) return true;
+ if (frame.package == 'stack_trace') return true;
+
+ // Ignore async stack frames without any line or column information.
+ // These come from the VM's async/await implementation and represent
+ // internal frames. They only ever show up in stack chains and are
+ // always surrounded by other traces that are actually useful, so we can
+ // just get rid of them.
+ // TODO(nweiz): Get rid of this logic some time after issue 22009 is
+ // fixed.
+ if (!frame.member.contains('<async>')) return false;
+ return frame.line == null;
+ };
+ }
+
+ var newFrames = [];
for (var frame in frames.reversed) {
if (!predicate(frame)) {
newFrames.add(frame);
@@ -242,6 +249,14 @@ class Trace implements StackTrace {
}
}
+ if (terse) {
+ newFrames = newFrames.map((frame) {
+ if (!frame.isCore) return frame;
+ var library = frame.library.replaceAll(_terseRegExp, '');
+ return new Frame(Uri.parse(library), null, null, frame.member);
+ }).toList();
+ }
+
return new Trace(newFrames.reversed);
}
« no previous file with comments | « lib/src/chain.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698