OLD | NEW |
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 'chain.dart'; | 10 import 'chain.dart'; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 Trace.parseSafari6_0(String trace) | 181 Trace.parseSafari6_0(String trace) |
182 : this(trace.trim().split("\n") | 182 : this(trace.trim().split("\n") |
183 .where((line) => line != '[native code]') | 183 .where((line) => line != '[native code]') |
184 .map((line) => new Frame.parseFirefox(line))); | 184 .map((line) => new Frame.parseFirefox(line))); |
185 | 185 |
186 /// Parses this package's string representation of a stack trace. | 186 /// Parses this package's string representation of a stack trace. |
187 /// | 187 /// |
188 /// This also parses string representations of [Chain]s. They parse to the | 188 /// This also parses string representations of [Chain]s. They parse to the |
189 /// same trace that [Chain.toTrace] would return. | 189 /// same trace that [Chain.toTrace] would return. |
190 Trace.parseFriendly(String trace) | 190 Trace.parseFriendly(String trace) |
191 : this(trace.trim().split("\n") | 191 : this(trace.isEmpty |
192 // Filter out asynchronous gaps from [Chain]s. | 192 ? [] |
193 .where((line) => !line.startsWith('=====')) | 193 : trace.trim().split("\n") |
194 .map((line) => new Frame.parseFriendly(line))); | 194 // Filter out asynchronous gaps from [Chain]s. |
| 195 .where((line) => !line.startsWith('=====')) |
| 196 .map((line) => new Frame.parseFriendly(line))); |
195 | 197 |
196 /// Returns a new [Trace] comprised of [frames]. | 198 /// Returns a new [Trace] comprised of [frames]. |
197 Trace(Iterable<Frame> frames) | 199 Trace(Iterable<Frame> frames) |
198 : frames = new UnmodifiableListView<Frame>(frames.toList()); | 200 : frames = new UnmodifiableListView<Frame>(frames.toList()); |
199 | 201 |
200 /// Returns a VM-style [StackTrace] object. | 202 /// Returns a VM-style [StackTrace] object. |
201 /// | 203 /// |
202 /// The return value's [toString] method will always return a string | 204 /// The return value's [toString] method will always return a string |
203 /// representation in the Dart VM's stack trace format, regardless of what | 205 /// representation in the Dart VM's stack trace format, regardless of what |
204 /// platform is being used. | 206 /// platform is being used. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // Figure out the longest path so we know how much to pad. | 276 // Figure out the longest path so we know how much to pad. |
275 var longest = frames.map((frame) => frame.location.length) | 277 var longest = frames.map((frame) => frame.location.length) |
276 .fold(0, math.max); | 278 .fold(0, math.max); |
277 | 279 |
278 // Print out the stack trace nicely formatted. | 280 // Print out the stack trace nicely formatted. |
279 return frames.map((frame) { | 281 return frames.map((frame) { |
280 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 282 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
281 }).join(); | 283 }).join(); |
282 } | 284 } |
283 } | 285 } |
OLD | NEW |