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

Side by Side Diff: lib/src/chain.dart

Issue 962913002: Remove the outermost folded frame for terse stack traces. (Closed) Base URL: git@github.com:dart-lang/stack_trace@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/trace.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 stack_trace.chain; 5 library stack_trace.chain;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'frame.dart'; 10 import 'frame.dart';
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 /// This is useful for limiting the amount of library code that appears in a 148 /// This is useful for limiting the amount of library code that appears in a
149 /// stack trace by only showing user code and code that's called by user code. 149 /// stack trace by only showing user code and code that's called by user code.
150 /// 150 ///
151 /// If [terse] is true, this will also fold together frames from the core 151 /// If [terse] is true, this will also fold together frames from the core
152 /// library or from this package, and simplify core library frames as in 152 /// library or from this package, and simplify core library frames as in
153 /// [Trace.terse]. 153 /// [Trace.terse].
154 Chain foldFrames(bool predicate(Frame frame), {bool terse: false}) { 154 Chain foldFrames(bool predicate(Frame frame), {bool terse: false}) {
155 var foldedTraces = traces.map( 155 var foldedTraces = traces.map(
156 (trace) => trace.foldFrames(predicate, terse: terse)); 156 (trace) => trace.foldFrames(predicate, terse: terse));
157 var nonEmptyTraces = foldedTraces.where((trace) { 157 var nonEmptyTraces = foldedTraces.where((trace) {
158 // Ignore traces that contain only folded frames. These traces will be 158 // Ignore traces that contain only folded frames.
159 // folded into a single frame each. 159 if (trace.frames.length > 1) return true;
160 return trace.frames.length > 1; 160
161 // In terse mode, the trace may have removed an outer folded frame,
162 // leaving a single non-folded frame. We can detect a folded frame because
163 // it has no line information.
164 if (!terse) return false;
165 return trace.frames.single.line != null;
161 }); 166 });
162 167
163 // If all the traces contain only internal processing, preserve the last 168 // If all the traces contain only internal processing, preserve the last
164 // (top-most) one so that the chain isn't empty. 169 // (top-most) one so that the chain isn't empty.
165 if (nonEmptyTraces.isEmpty && foldedTraces.isNotEmpty) { 170 if (nonEmptyTraces.isEmpty && foldedTraces.isNotEmpty) {
166 return new Chain([foldedTraces.last]); 171 return new Chain([foldedTraces.last]);
167 } 172 }
168 173
169 return new Chain(nonEmptyTraces); 174 return new Chain(nonEmptyTraces);
170 } 175 }
171 176
172 /// Converts [this] to a [Trace]. 177 /// Converts [this] to a [Trace].
173 /// 178 ///
174 /// The trace version of a chain is just the concatenation of all the traces 179 /// The trace version of a chain is just the concatenation of all the traces
175 /// in the chain. 180 /// in the chain.
176 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames))); 181 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames)));
177 182
178 String toString() => traces.join(_GAP); 183 String toString() => traces.join(_GAP);
179 } 184 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/trace.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698