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

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

Issue 63603005: Properly parse jsshell and d8 stack frames. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
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 frame; 5 library frame;
6 6
7 7
8 import 'package:path/path.dart' as path; 8 import 'package:path/path.dart' as path;
9 9
10 import 'trace.dart'; 10 import 'trace.dart';
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 /// Parses a string representation of a Chrome/V8 stack frame. 130 /// Parses a string representation of a Chrome/V8 stack frame.
131 factory Frame.parseV8(String frame) { 131 factory Frame.parseV8(String frame) {
132 var match = _v8Frame.firstMatch(frame); 132 var match = _v8Frame.firstMatch(frame);
133 if (match == null) { 133 if (match == null) {
134 throw new FormatException("Couldn't parse V8 stack trace line '$frame'."); 134 throw new FormatException("Couldn't parse V8 stack trace line '$frame'.");
135 } 135 }
136 136
137 // V8 stack frames can be in two forms. 137 // V8 stack frames can be in two forms.
138 if (match[2] != null) { 138 if (match[2] != null) {
139 // The first form looks like " at FUNCTION (URI:LINE:COL)" 139 // The first form looks like " at FUNCTION (PATH:LINE:COL)". PATH is
140 var uri = Uri.parse(match[2]); 140 // usually an absolute URL, but it can be a path if the stack frame came
141 // from d8.
142 var uri = _uriOrPathToUri(match[2]);
141 var member = match[1].replaceAll("<anonymous>", "<fn>"); 143 var member = match[1].replaceAll("<anonymous>", "<fn>");
142 return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member); 144 return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member);
143 } else { 145 } else {
144 // The second form looks like " at URI:LINE:COL", and is used for 146 // The second form looks like " at PATH:LINE:COL", and is used for
145 // anonymous functions. 147 // anonymous functions. PATH is usually an absolute URL, but it can be a
146 var uri = Uri.parse(match[5]); 148 // path if the stack frame came from d8.
149 var uri = _uriOrPathToUri(match[5]);
147 return new Frame(uri, int.parse(match[6]), int.parse(match[7]), "<fn>"); 150 return new Frame(uri, int.parse(match[6]), int.parse(match[7]), "<fn>");
148 } 151 }
149 } 152 }
150 153
151 /// Parses a string representation of an IE stack frame. 154 /// Parses a string representation of an IE stack frame.
152 /// 155 ///
153 /// IE10+ frames look just like V8 frames. Prior to IE10, stack traces can't 156 /// IE10+ frames look just like V8 frames. Prior to IE10, stack traces can't
154 /// be retrieved. 157 /// be retrieved.
155 factory Frame.parseIE(String frame) => new Frame.parseV8(frame); 158 factory Frame.parseIE(String frame) => new Frame.parseV8(frame);
156 159
157 /// Parses a string representation of a Firefox stack frame. 160 /// Parses a string representation of a Firefox stack frame.
158 factory Frame.parseFirefox(String frame) { 161 factory Frame.parseFirefox(String frame) {
159 var match = _firefoxFrame.firstMatch(frame); 162 var match = _firefoxFrame.firstMatch(frame);
160 if (match == null) { 163 if (match == null) {
161 throw new FormatException( 164 throw new FormatException(
162 "Couldn't parse Firefox stack trace line '$frame'."); 165 "Couldn't parse Firefox stack trace line '$frame'.");
163 } 166 }
164 167
165 var uri = Uri.parse(match[3]); 168 // Normally this is a URI, but in a jsshell trace it can be a path.
169 var uri = _uriOrPathToUri(match[3]);
166 var member = match[1]; 170 var member = match[1];
167 member += new List.filled('/'.allMatches(match[2]).length, ".<fn>").join(); 171 member += new List.filled('/'.allMatches(match[2]).length, ".<fn>").join();
168 if (member == '') member = '<fn>'; 172 if (member == '') member = '<fn>';
169 173
170 // Some Firefox members have initial dots. We remove them for consistency 174 // Some Firefox members have initial dots. We remove them for consistency
171 // with other platforms. 175 // with other platforms.
172 member = member.replaceFirst(_initialDot, ''); 176 member = member.replaceFirst(_initialDot, '');
173 return new Frame(uri, int.parse(match[4]), null, member); 177 return new Frame(uri, int.parse(match[4]), null, member);
174 } 178 }
175 179
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // relative to the current working directory. 212 // relative to the current working directory.
209 if (uri.scheme == '') { 213 if (uri.scheme == '') {
210 uri = path.toUri(path.absolute(path.fromUri(uri))); 214 uri = path.toUri(path.absolute(path.fromUri(uri)));
211 } 215 }
212 216
213 var line = match[2] == null ? null : int.parse(match[2]); 217 var line = match[2] == null ? null : int.parse(match[2]);
214 var column = match[3] == null ? null : int.parse(match[3]); 218 var column = match[3] == null ? null : int.parse(match[3]);
215 return new Frame(uri, line, column, match[4]); 219 return new Frame(uri, line, column, match[4]);
216 } 220 }
217 221
222 /// A regular expression matching an absolute URI.
223 static final _uriRegExp = new RegExp(r'^[a-zA-Z][-+.a-zA-Z\d]*://');
224
225 /// A regular expression matching a Windows path.
226 static final _windowsRegExp = new RegExp(r'^[a-zA-Z]:[\/]');
Bob Nystrom 2013/11/07 22:25:10 What about UNC paths?
nweiz 2013/11/07 22:40:12 They were implicitly supported by the uriOrPath.co
227
228 /// Converts [uriOrPath], which can be a URI, a Windows path, or a Posix path,
229 /// to a URI (absolute if possible).
230 static Uri _uriOrPathToUri(String uriOrPath) {
231 if (uriOrPath.contains(_uriRegExp)) {
232 return Uri.parse(uriOrPath);
233 } else if (uriOrPath.contains(_windowsRegExp)) {
234 return new Uri.file(uriOrPath, windows: true);
235 } else if (uriOrPath.startsWith('/')) {
236 return new Uri.file(uriOrPath, windows: false);
237 }
238
239 // As far as I've seen, Firefox and V8 both always report absolute paths in
240 // their stack frames. However, if we do get a relative path, we should
241 // handle it gracefully.
242 if (uriOrPath.contains('\\')) return path.windows.toUri(uriOrPath);
243 return Uri.parse(uriOrPath);
244 }
245
218 Frame(this.uri, this.line, this.column, this.member); 246 Frame(this.uri, this.line, this.column, this.member);
219 247
220 String toString() => '$location in $member'; 248 String toString() => '$location in $member';
221 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698