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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 108 } |
109 | 109 |
110 /// Parses a string representation of a stack trace. | 110 /// Parses a string representation of a stack trace. |
111 /// | 111 /// |
112 /// [trace] should be formatted in the same way as a Dart VM or browser stack | 112 /// [trace] should be formatted in the same way as a Dart VM or browser stack |
113 /// trace. | 113 /// trace. |
114 factory Trace.parse(String trace) { | 114 factory Trace.parse(String trace) { |
115 try { | 115 try { |
116 if (trace.isEmpty) return new Trace(<Frame>[]); | 116 if (trace.isEmpty) return new Trace(<Frame>[]); |
117 if (trace.contains(_v8Trace)) return new Trace.parseV8(trace); | 117 if (trace.contains(_v8Trace)) return new Trace.parseV8(trace); |
| 118 if (trace.startsWith("\tat ")) return new Trace.parseJSCore(trace); |
118 if (trace.contains(_firefoxSafariTrace)) { | 119 if (trace.contains(_firefoxSafariTrace)) { |
119 return new Trace.parseFirefox(trace); | 120 return new Trace.parseFirefox(trace); |
120 } | 121 } |
121 if (trace.contains(_friendlyTrace)) { | 122 if (trace.contains(_friendlyTrace)) { |
122 return new Trace.parseFriendly(trace); | 123 return new Trace.parseFriendly(trace); |
123 } | 124 } |
124 | 125 |
125 // Default to parsing the stack trace as a VM trace. This is also hit on | 126 // Default to parsing the stack trace as a VM trace. This is also hit on |
126 // IE and Safari, where the stack trace is just an empty string (issue | 127 // IE and Safari, where the stack trace is just an empty string (issue |
127 // 11257). | 128 // 11257). |
(...skipping 12 matching lines...) Expand all Loading... |
140 | 141 |
141 /// Parses a string representation of a Chrome/V8 stack trace. | 142 /// Parses a string representation of a Chrome/V8 stack trace. |
142 Trace.parseV8(String trace) | 143 Trace.parseV8(String trace) |
143 : this(trace.split("\n").skip(1) | 144 : this(trace.split("\n").skip(1) |
144 // It's possible that an Exception's description contains a line that | 145 // It's possible that an Exception's description contains a line that |
145 // looks like a V8 trace line, which will screw this up. | 146 // looks like a V8 trace line, which will screw this up. |
146 // Unfortunately, that's impossible to detect. | 147 // Unfortunately, that's impossible to detect. |
147 .skipWhile((line) => !line.startsWith(_v8TraceLine)) | 148 .skipWhile((line) => !line.startsWith(_v8TraceLine)) |
148 .map((line) => new Frame.parseV8(line))); | 149 .map((line) => new Frame.parseV8(line))); |
149 | 150 |
| 151 /// Parses a string representation of a JavaScriptCore stack trace. |
| 152 Trace.parseJSCore(String trace) |
| 153 : this(trace.split("\n").map((line) => new Frame.parseV8(line))); |
| 154 |
150 /// Parses a string representation of an Internet Explorer stack trace. | 155 /// Parses a string representation of an Internet Explorer stack trace. |
151 /// | 156 /// |
152 /// IE10+ traces look just like V8 traces. Prior to IE10, stack traces can't | 157 /// IE10+ traces look just like V8 traces. Prior to IE10, stack traces can't |
153 /// be retrieved. | 158 /// be retrieved. |
154 Trace.parseIE(String trace) | 159 Trace.parseIE(String trace) |
155 : this.parseV8(trace); | 160 : this.parseV8(trace); |
156 | 161 |
157 /// Parses a string representation of a Firefox stack trace. | 162 /// Parses a string representation of a Firefox stack trace. |
158 Trace.parseFirefox(String trace) | 163 Trace.parseFirefox(String trace) |
159 : this(trace.trim().split("\n") | 164 : this(trace.trim().split("\n") |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // Figure out the longest path so we know how much to pad. | 272 // Figure out the longest path so we know how much to pad. |
268 var longest = frames.map((frame) => frame.location.length) | 273 var longest = frames.map((frame) => frame.location.length) |
269 .fold(0, math.max); | 274 .fold(0, math.max); |
270 | 275 |
271 // Print out the stack trace nicely formatted. | 276 // Print out the stack trace nicely formatted. |
272 return frames.map((frame) { | 277 return frames.map((frame) { |
273 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 278 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
274 }).join(); | 279 }).join(); |
275 } | 280 } |
276 } | 281 } |
OLD | NEW |