| 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 'frame.dart'; | 10 import 'frame.dart'; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 /// | 165 /// |
| 166 /// Safari 6.0 stack traces look just like Firefox traces, except that they | 166 /// Safari 6.0 stack traces look just like Firefox traces, except that they |
| 167 /// sometimes (e.g. in isolates) have a "[native code]" frame. We just ignore | 167 /// sometimes (e.g. in isolates) have a "[native code]" frame. We just ignore |
| 168 /// this frame to make the stack format more consistent between browsers. | 168 /// this frame to make the stack format more consistent between browsers. |
| 169 /// Prior to Safari 6.0, stack traces can't be retrieved. | 169 /// Prior to Safari 6.0, stack traces can't be retrieved. |
| 170 Trace.parseSafari6_0(String trace) | 170 Trace.parseSafari6_0(String trace) |
| 171 : this(trace.trim().split("\n") | 171 : this(trace.trim().split("\n") |
| 172 .where((line) => line != '[native code]') | 172 .where((line) => line != '[native code]') |
| 173 .map((line) => new Frame.parseFirefox(line))); | 173 .map((line) => new Frame.parseFirefox(line))); |
| 174 | 174 |
| 175 /// Parses this package's a string representation of a stack trace. | 175 /// Parses this package's string representation of a stack trace. |
| 176 /// |
| 177 /// This also parses string representations of [Chain]s. They parse to the |
| 178 /// same trace that [Chain.toTrace] would return. |
| 176 Trace.parseFriendly(String trace) | 179 Trace.parseFriendly(String trace) |
| 177 : this(trace.trim().split("\n") | 180 : this(trace.trim().split("\n") |
| 181 // Filter out asynchronous gaps from [Chain]s. |
| 182 .where((line) => !line.startsWith('=====')) |
| 178 .map((line) => new Frame.parseFriendly(line))); | 183 .map((line) => new Frame.parseFriendly(line))); |
| 179 | 184 |
| 180 /// Returns a new [Trace] comprised of [frames]. | 185 /// Returns a new [Trace] comprised of [frames]. |
| 181 Trace(Iterable<Frame> frames) | 186 Trace(Iterable<Frame> frames) |
| 182 : frames = new UnmodifiableListView<Frame>(frames.toList()); | 187 : frames = new UnmodifiableListView<Frame>(frames.toList()); |
| 183 | 188 |
| 184 /// Returns a VM-style [StackTrace] object. | 189 /// Returns a VM-style [StackTrace] object. |
| 185 /// | 190 /// |
| 186 /// The return value's [toString] method will always return a string | 191 /// The return value's [toString] method will always return a string |
| 187 /// representation in the Dart VM's stack trace format, regardless of what | 192 /// representation in the Dart VM's stack trace format, regardless of what |
| 188 /// platform is being used. | 193 /// platform is being used. |
| 189 StackTrace get vmTrace => new VMTrace(frames); | 194 StackTrace get vmTrace => new VMTrace(frames); |
| 190 | 195 |
| 191 /// Returns a terser version of [this]. | 196 /// Returns a terser version of [this]. |
| 192 /// | 197 /// |
| 193 /// This is accomplished by folding together multiple stack frames from the | 198 /// This is accomplished by folding together multiple stack frames from the |
| 194 /// core library, as in [foldFrames]. Remaining core library frames have their | 199 /// core library or from this package, as in [foldFrames]. Remaining core |
| 195 /// libraries, "-patch" suffixes, and line numbers removed. | 200 /// library frames have their libraries, "-patch" suffixes, and line numbers |
| 201 /// removed. |
| 196 Trace get terse { | 202 Trace get terse { |
| 197 return new Trace(foldFrames((frame) => frame.isCore).frames.map((frame) { | 203 return new Trace(foldFrames((frame) { |
| 204 return frame.isCore || frame.package == 'stack_trace'; |
| 205 }).frames.map((frame) { |
| 198 if (!frame.isCore) return frame; | 206 if (!frame.isCore) return frame; |
| 199 var library = frame.library.replaceAll(_terseRegExp, ''); | 207 var library = frame.library.replaceAll(_terseRegExp, ''); |
| 200 return new Frame(Uri.parse(library), null, null, frame.member); | 208 return new Frame(Uri.parse(library), null, null, frame.member); |
| 201 })); | 209 })); |
| 202 } | 210 } |
| 203 | 211 |
| 204 /// Returns a new [Trace] based on [this] where multiple stack frames matching | 212 /// Returns a new [Trace] based on [this] where multiple stack frames matching |
| 205 /// [predicate] are folded together. This means that whenever there are | 213 /// [predicate] are folded together. This means that whenever there are |
| 206 /// multiple frames in a row that match [predicate], only the last one is | 214 /// multiple frames in a row that match [predicate], only the last one is |
| 207 /// kept. | 215 /// kept. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 227 // Figure out the longest path so we know how much to pad. | 235 // Figure out the longest path so we know how much to pad. |
| 228 var longest = frames.map((frame) => frame.location.length) | 236 var longest = frames.map((frame) => frame.location.length) |
| 229 .fold(0, math.max); | 237 .fold(0, math.max); |
| 230 | 238 |
| 231 // Print out the stack trace nicely formatted. | 239 // Print out the stack trace nicely formatted. |
| 232 return frames.map((frame) { | 240 return frames.map((frame) { |
| 233 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 241 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
| 234 }).join(); | 242 }).join(); |
| 235 } | 243 } |
| 236 } | 244 } |
| OLD | NEW |