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

Unified Diff: pkg/stack_trace/lib/src/trace.dart

Issue 13157004: Use the stack_trace library in scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
Index: pkg/stack_trace/lib/src/trace.dart
diff --git a/pkg/stack_trace/lib/src/trace.dart b/pkg/stack_trace/lib/src/trace.dart
index 1ab7695b996d279b8115e243e89007ae68fa7c53..3445b5c55157399dcbdc30caed01d75212e76916 100644
--- a/pkg/stack_trace/lib/src/trace.dart
+++ b/pkg/stack_trace/lib/src/trace.dart
@@ -79,19 +79,32 @@ class Trace implements StackTrace {
String get fullStackTrace => toString();
/// Returns a terser version of [this]. This is accomplished by folding
- /// together multiple stack frames from the core library. If multiple such
- /// frames appear in a row, only the last (the one directly called by user
- /// code) is kept. Core library patches are also renamed to remove their
- /// `-patch` suffix.
+ /// together multiple stack frames from the core library, as in [foldFrames].
+ /// Core library patches are also renamed to remove their `-patch` suffix.
Trace get terse {
+ return new Trace(foldFrames((frame) => frame.isCore).frames.map((frame) {
+ if (!frame.isCore) return frame;
+ var library = frame.library.replaceAll(_patchRegExp, '');
+ return new Frame(
+ Uri.parse(library), frame.line, frame.column, frame.member);
+ }));
+ }
+
+ /// Returns a version of [this] where multiple stack frames matching
Bob Nystrom 2013/04/01 17:30:49 "a version of [this]" -> "a new Trace based on [th
nweiz 2013/04/01 20:46:03 Done.
+ /// [predicate] are folded together. 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.
+ Trace foldFrames(bool predicate(frame)) {
var newFrames = <Frame>[];
for (var frame in frames.reversed) {
- if (!frame.isCore) {
+ if (!predicate(frame)) {
newFrames.add(frame);
- } else if (newFrames.isEmpty || !newFrames.last.isCore) {
- var library = frame.library.replaceAll(_patchRegExp, '');
+ } else if (newFrames.isEmpty || !predicate(newFrames.last)) {
newFrames.add(new Frame(
- Uri.parse(library), frame.line, frame.column, frame.member));
+ frame.uri, frame.line, frame.column, frame.member));
}
}

Powered by Google App Engine
This is Rietveld 408576698