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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 trace; 5 library trace;
6 6
7 import 'dart:uri'; 7 import 'dart:uri';
8 8
9 import 'frame.dart'; 9 import 'frame.dart';
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 /// native stack traces. 72 /// native stack traces.
73 String get stackTrace => toString(); 73 String get stackTrace => toString();
74 74
75 /// Returns a string representation of this stack trace. 75 /// Returns a string representation of this stack trace.
76 /// 76 ///
77 /// This is identical to [toString]. It will not be formatted in the manner of 77 /// This is identical to [toString]. It will not be formatted in the manner of
78 /// native stack traces. 78 /// native stack traces.
79 String get fullStackTrace => toString(); 79 String get fullStackTrace => toString();
80 80
81 /// Returns a terser version of [this]. This is accomplished by folding 81 /// Returns a terser version of [this]. This is accomplished by folding
82 /// together multiple stack frames from the core library. If multiple such 82 /// together multiple stack frames from the core library, as in [foldFrames].
83 /// frames appear in a row, only the last (the one directly called by user 83 /// Core library patches are also renamed to remove their `-patch` suffix.
84 /// code) is kept. Core library patches are also renamed to remove their
85 /// `-patch` suffix.
86 Trace get terse { 84 Trace get terse {
85 return new Trace(foldFrames((frame) => frame.isCore).frames.map((frame) {
86 if (!frame.isCore) return frame;
87 var library = frame.library.replaceAll(_patchRegExp, '');
88 return new Frame(
89 Uri.parse(library), frame.line, frame.column, frame.member);
90 }));
91 }
92
93 /// 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.
94 /// [predicate] are folded together. This means that whenever there are
95 /// multiple frames in a row that match [predicate], only the last one is
96 /// kept.
97 ///
98 /// This is useful for limiting the amount of library code that appears in a
99 /// stack trace by only showing user code and code that's called by user code.
100 Trace foldFrames(bool predicate(frame)) {
87 var newFrames = <Frame>[]; 101 var newFrames = <Frame>[];
88 for (var frame in frames.reversed) { 102 for (var frame in frames.reversed) {
89 if (!frame.isCore) { 103 if (!predicate(frame)) {
90 newFrames.add(frame); 104 newFrames.add(frame);
91 } else if (newFrames.isEmpty || !newFrames.last.isCore) { 105 } else if (newFrames.isEmpty || !predicate(newFrames.last)) {
92 var library = frame.library.replaceAll(_patchRegExp, '');
93 newFrames.add(new Frame( 106 newFrames.add(new Frame(
94 Uri.parse(library), frame.line, frame.column, frame.member)); 107 frame.uri, frame.line, frame.column, frame.member));
95 } 108 }
96 } 109 }
97 110
98 return new Trace(newFrames.reversed); 111 return new Trace(newFrames.reversed);
99 } 112 }
100 113
101 /// Returns a human-readable string representation of [this]. 114 /// Returns a human-readable string representation of [this].
102 String toString() { 115 String toString() {
103 if (frames.length == '') return ''; 116 if (frames.length == '') return '';
104 117
(...skipping 13 matching lines...) Expand all
118 if (string.length >= length) return string; 131 if (string.length >= length) return string;
119 132
120 var result = new StringBuffer(); 133 var result = new StringBuffer();
121 result.write(string); 134 result.write(string);
122 for (var i = 0; i < length - string.length; i++) { 135 for (var i = 0; i < length - string.length; i++) {
123 result.write(' '); 136 result.write(' ');
124 } 137 }
125 138
126 return result.toString(); 139 return result.toString();
127 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698