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

Side by Side Diff: pkg/stack_trace/lib/src/trace.dart

Issue 16097012: Make the StackTrace library better handle core library frames. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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:collection'; 7 import 'dart:collection';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'frame.dart'; 10 import 'frame.dart';
11 import 'lazy_trace.dart'; 11 import 'lazy_trace.dart';
12 12
13 final _patchRegExp = new RegExp(r"-patch$"); 13 final _terseRegExp = new RegExp(r"(-patch)?(/.*)?$");
14 14
15 /// A stack trace, comprised of a list of stack frames. 15 /// A stack trace, comprised of a list of stack frames.
16 class Trace implements StackTrace { 16 class Trace implements StackTrace {
17 /// The stack frames that comprise this stack trace. 17 /// The stack frames that comprise this stack trace.
18 final List<Frame> frames; 18 final List<Frame> frames;
19 19
20 /// Returns a human-readable representation of [stackTrace]. If [terse] is 20 /// Returns a human-readable representation of [stackTrace]. If [terse] is
21 /// set, this folds together multiple stack frames from the Dart core 21 /// set, this folds together multiple stack frames from the Dart core
22 /// libraries, so that only the core library method directly called from user 22 /// libraries, so that only the core library method directly called from user
23 /// code is visible (see [Trace.terse]). 23 /// code is visible (see [Trace.terse]).
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 /// This is identical to [toString]. It will not be formatted in the manner of 72 /// This is identical to [toString]. It will not be formatted in the manner of
73 /// native stack traces. 73 /// native stack traces.
74 String get stackTrace => toString(); 74 String get stackTrace => toString();
75 75
76 /// Returns a string representation of this stack trace. 76 /// Returns a string representation of this stack trace.
77 /// 77 ///
78 /// This is identical to [toString]. It will not be formatted in the manner of 78 /// This is identical to [toString]. It will not be formatted in the manner of
79 /// native stack traces. 79 /// native stack traces.
80 String get fullStackTrace => toString(); 80 String get fullStackTrace => toString();
81 81
82 /// Returns a terser version of [this]. This is accomplished by folding 82 /// Returns a terser version of [this].
83 /// together multiple stack frames from the core library, as in [foldFrames]. 83 ///
84 /// Core library patches are also renamed to remove their `-patch` suffix. 84 /// This is accomplished by folding together multiple stack frames from the
85 /// core library, as in [foldFrames]. Remaining core library frames have their
86 /// libraries, "-patch" suffixes, and line numbers removed.
85 Trace get terse { 87 Trace get terse {
86 return new Trace(foldFrames((frame) => frame.isCore).frames.map((frame) { 88 return new Trace(foldFrames((frame) => frame.isCore).frames.map((frame) {
87 if (!frame.isCore) return frame; 89 if (!frame.isCore) return frame;
88 var library = frame.library.replaceAll(_patchRegExp, ''); 90 var library = frame.library.replaceAll(_terseRegExp, '');
89 return new Frame( 91 return new Frame(Uri.parse(library), null, null, frame.member);
90 Uri.parse(library), frame.line, frame.column, frame.member);
91 })); 92 }));
92 } 93 }
93 94
94 /// Returns a new [Trace] based on [this] where multiple stack frames matching 95 /// Returns a new [Trace] based on [this] where multiple stack frames matching
95 /// [predicate] are folded together. This means that whenever there are 96 /// [predicate] are folded together. This means that whenever there are
96 /// multiple frames in a row that match [predicate], only the last one is 97 /// multiple frames in a row that match [predicate], only the last one is
97 /// kept. 98 /// kept.
98 /// 99 ///
99 /// This is useful for limiting the amount of library code that appears in a 100 /// This is useful for limiting the amount of library code that appears in a
100 /// stack trace by only showing user code and code that's called by user code. 101 /// stack trace by only showing user code and code that's called by user code.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (string.length >= length) return string; 133 if (string.length >= length) return string;
133 134
134 var result = new StringBuffer(); 135 var result = new StringBuffer();
135 result.write(string); 136 result.write(string);
136 for (var i = 0; i < length - string.length; i++) { 137 for (var i = 0; i < length - string.length; i++) {
137 result.write(' '); 138 result.write(' ');
138 } 139 }
139 140
140 return result.toString(); 141 return result.toString();
141 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698