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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 104 } |
105 | 105 |
106 if (trace is Trace) return trace; | 106 if (trace is Trace) return trace; |
107 if (trace is Chain) return trace.toTrace(); | 107 if (trace is Chain) return trace.toTrace(); |
108 return new LazyTrace(() => new Trace.parse(trace.toString())); | 108 return new LazyTrace(() => new Trace.parse(trace.toString())); |
109 } | 109 } |
110 | 110 |
111 /// Parses a string representation of a stack trace. | 111 /// Parses a string representation of a stack trace. |
112 /// | 112 /// |
113 /// [trace] should be formatted in the same way as a Dart VM or browser stack | 113 /// [trace] should be formatted in the same way as a Dart VM or browser stack |
114 /// trace. | 114 /// trace. If it's formatted as a stack chain, this will return the equivalent |
| 115 /// of [Chain.toTrace]. |
115 factory Trace.parse(String trace) { | 116 factory Trace.parse(String trace) { |
116 try { | 117 try { |
117 if (trace.isEmpty) return new Trace(<Frame>[]); | 118 if (trace.isEmpty) return new Trace(<Frame>[]); |
118 if (trace.contains(_v8Trace)) return new Trace.parseV8(trace); | 119 if (trace.contains(_v8Trace)) return new Trace.parseV8(trace); |
119 if (trace.contains("\tat ")) return new Trace.parseJSCore(trace); | 120 if (trace.contains("\tat ")) return new Trace.parseJSCore(trace); |
120 if (trace.contains(_firefoxSafariTrace)) { | 121 if (trace.contains(_firefoxSafariTrace)) { |
121 return new Trace.parseFirefox(trace); | 122 return new Trace.parseFirefox(trace); |
122 } | 123 } |
| 124 if (trace.contains(chainGap)) return new Chain.parse(trace).toTrace(); |
123 if (trace.contains(_friendlyTrace)) { | 125 if (trace.contains(_friendlyTrace)) { |
124 return new Trace.parseFriendly(trace); | 126 return new Trace.parseFriendly(trace); |
125 } | 127 } |
126 | 128 |
127 // Default to parsing the stack trace as a VM trace. This is also hit on | 129 // Default to parsing the stack trace as a VM trace. This is also hit on |
128 // IE and Safari, where the stack trace is just an empty string (issue | 130 // IE and Safari, where the stack trace is just an empty string (issue |
129 // 11257). | 131 // 11257). |
130 return new Trace.parseVM(trace); | 132 return new Trace.parseVM(trace); |
131 } on FormatException catch (error) { | 133 } on FormatException catch (error) { |
132 throw new FormatException('${error.message}\nStack trace:\n$trace'); | 134 throw new FormatException('${error.message}\nStack trace:\n$trace'); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 var longest = frames.map((frame) => frame.location.length) | 291 var longest = frames.map((frame) => frame.location.length) |
290 .fold(0, math.max); | 292 .fold(0, math.max); |
291 | 293 |
292 // Print out the stack trace nicely formatted. | 294 // Print out the stack trace nicely formatted. |
293 return frames.map((frame) { | 295 return frames.map((frame) { |
294 if (frame is UnparsedFrame) return "$frame\n"; | 296 if (frame is UnparsedFrame) return "$frame\n"; |
295 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 297 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
296 }).join(); | 298 }).join(); |
297 } | 299 } |
298 } | 300 } |
OLD | NEW |