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

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

Issue 116913003: Chain.terse shouldn't return an empty chain. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
« no previous file with comments | « no previous file | pkg/stack_trace/test/chain_test.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 'stack_zone_specification.dart'; 10 import 'stack_zone_specification.dart';
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 /// Returns a new [Chain] comprised of [traces]. 151 /// Returns a new [Chain] comprised of [traces].
152 Chain(Iterable<Trace> traces) 152 Chain(Iterable<Trace> traces)
153 : traces = new UnmodifiableListView<Trace>(traces.toList()); 153 : traces = new UnmodifiableListView<Trace>(traces.toList());
154 154
155 /// Returns a terser version of [this]. 155 /// Returns a terser version of [this].
156 /// 156 ///
157 /// This calls [Trace.terse] on every trace in [traces], and discards any 157 /// This calls [Trace.terse] on every trace in [traces], and discards any
158 /// trace that contain only internal frames. 158 /// trace that contain only internal frames.
159 Chain get terse { 159 Chain get terse {
160 return new Chain(traces.map((trace) => trace.terse).where((trace) { 160 var terseTraces = traces.map((trace) => trace.terse);
161 var nonEmptyTraces = terseTraces.where((trace) {
161 // Ignore traces that contain only internal processing. 162 // Ignore traces that contain only internal processing.
162 return trace.frames.length > 1; 163 return trace.frames.length > 1;
163 })); 164 });
165
166 // If all the traces contain only internal processing, preserve the last
167 // (top-most) one so that the chain isn't empty.
168 if (nonEmptyTraces.isEmpty && terseTraces.isNotEmpty) {
169 return new Chain([terseTraces.last]);
170 }
171
172 return new Chain(nonEmptyTraces);
164 } 173 }
165 174
166 /// Converts [this] to a [Trace]. 175 /// Converts [this] to a [Trace].
167 /// 176 ///
168 /// The trace version of a chain is just the concatenation of all the traces 177 /// The trace version of a chain is just the concatenation of all the traces
169 /// in the chain. 178 /// in the chain.
170 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames))); 179 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames)));
171 180
172 String toString() => traces.join(_GAP); 181 String toString() => traces.join(_GAP);
173 } 182 }
OLDNEW
« no previous file with comments | « no previous file | pkg/stack_trace/test/chain_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698