| 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 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 12 matching lines...) Expand all Loading... |
| 23 // http://pub.dartlang.org/stuff.dart.js:560:28 | 23 // http://pub.dartlang.org/stuff.dart.js:560:28 |
| 24 final _v8UrlLocation = new RegExp(r'^(.*):(\d+):(\d+)$'); | 24 final _v8UrlLocation = new RegExp(r'^(.*):(\d+):(\d+)$'); |
| 25 | 25 |
| 26 // eval as function (http://pub.dartlang.org/stuff.dart.js:560:28), efn:3:28 | 26 // eval as function (http://pub.dartlang.org/stuff.dart.js:560:28), efn:3:28 |
| 27 // eval as function (http://pub.dartlang.org/stuff.dart.js:560:28) | 27 // eval as function (http://pub.dartlang.org/stuff.dart.js:560:28) |
| 28 // eval as function (eval as otherFunction | 28 // eval as function (eval as otherFunction |
| 29 // (http://pub.dartlang.org/stuff.dart.js:560:28)) | 29 // (http://pub.dartlang.org/stuff.dart.js:560:28)) |
| 30 final _v8EvalLocation = new RegExp( | 30 final _v8EvalLocation = new RegExp( |
| 31 r'^eval at (?:\S.*?) \((.*)\)(?:, .*?:\d+:\d+)?$'); | 31 r'^eval at (?:\S.*?) \((.*)\)(?:, .*?:\d+:\d+)?$'); |
| 32 | 32 |
| 33 // foo$bar$0@http://pub.dartlang.org/stuff.dart.js:560:28 | |
| 34 // http://pub.dartlang.org/stuff.dart.js:560:28 | |
| 35 final _safariFrame = new RegExp(r"^(?:([0-9A-Za-z_$]*)@)?(.*):(\d*):(\d*)$"); | |
| 36 | |
| 37 // .VW.call$0@http://pub.dartlang.org/stuff.dart.js:560 | 33 // .VW.call$0@http://pub.dartlang.org/stuff.dart.js:560 |
| 38 // .VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560 | 34 // .VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560 |
| 39 // .VW.call$0/name<@http://pub.dartlang.org/stuff.dart.js:560 | 35 // .VW.call$0/name<@http://pub.dartlang.org/stuff.dart.js:560 |
| 40 final _firefoxFrame = new RegExp( | 36 // .VW.call$0@http://pub.dartlang.org/stuff.dart.js:560:36 |
| 41 r'^([^@(/]*)(?:\(.*\))?((?:/[^/]*)*)(?:\(.*\))?@(.*):(\d+)$'); | 37 // http://pub.dartlang.org/stuff.dart.js:560 |
| 38 final _firefoxSafariFrame = new RegExp( |
| 39 r'^' |
| 40 r'(?:' // Member description. Not present in some Safari frames. |
| 41 r'([^@(/]*)' // The actual name of the member. |
| 42 r'(?:\(.*\))?' // Arguments to the member, sometimes captured by Firefox. |
| 43 r'((?:/[^/]*)*)' // Extra characters indicating a nested closure. |
| 44 r'(?:\(.*\))?' // Arguments to the closure. |
| 45 r'@' |
| 46 r')?' |
| 47 r'(.*?)' // The frame's URL. |
| 48 r':' |
| 49 r'(\d*)' // The line number. Empty in Safari if it's unknown. |
| 50 r'(?::(\d*))?' // The column number. Not present in older browsers and |
| 51 // empty in Safari if it's unknown. |
| 52 r'$'); |
| 42 | 53 |
| 43 // foo/bar.dart 10:11 in Foo._bar | 54 // foo/bar.dart 10:11 in Foo._bar |
| 44 // http://dartlang.org/foo/bar.dart in Foo._bar | 55 // http://dartlang.org/foo/bar.dart in Foo._bar |
| 45 final _friendlyFrame = new RegExp( | 56 final _friendlyFrame = new RegExp( |
| 46 r'^(\S+)(?: (\d+)(?::(\d+))?)?\s+([^\d]\S*)$'); | 57 r'^(\S+)(?: (\d+)(?::(\d+))?)?\s+([^\d]\S*)$'); |
| 47 | 58 |
| 48 final _initialDot = new RegExp(r"^\."); | 59 final _initialDot = new RegExp(r"^\."); |
| 49 | 60 |
| 50 /// A single stack frame. Each frame points to a precise location in Dart code. | 61 /// A single stack frame. Each frame points to a precise location in Dart code. |
| 51 class Frame { | 62 class Frame { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 191 } |
| 181 | 192 |
| 182 /// Parses a string representation of an IE stack frame. | 193 /// Parses a string representation of an IE stack frame. |
| 183 /// | 194 /// |
| 184 /// IE10+ frames look just like V8 frames. Prior to IE10, stack traces can't | 195 /// IE10+ frames look just like V8 frames. Prior to IE10, stack traces can't |
| 185 /// be retrieved. | 196 /// be retrieved. |
| 186 factory Frame.parseIE(String frame) => new Frame.parseV8(frame); | 197 factory Frame.parseIE(String frame) => new Frame.parseV8(frame); |
| 187 | 198 |
| 188 /// Parses a string representation of a Firefox stack frame. | 199 /// Parses a string representation of a Firefox stack frame. |
| 189 factory Frame.parseFirefox(String frame) { | 200 factory Frame.parseFirefox(String frame) { |
| 190 var match = _firefoxFrame.firstMatch(frame); | 201 var match = _firefoxSafariFrame.firstMatch(frame); |
| 191 if (match == null) { | 202 if (match == null) { |
| 192 throw new FormatException( | 203 throw new FormatException( |
| 193 "Couldn't parse Firefox stack trace line '$frame'."); | 204 "Couldn't parse Firefox/Safari stack trace line '$frame'."); |
| 194 } | 205 } |
| 195 | 206 |
| 196 // Normally this is a URI, but in a jsshell trace it can be a path. | 207 // Normally this is a URI, but in a jsshell trace it can be a path. |
| 197 var uri = _uriOrPathToUri(match[3]); | 208 var uri = _uriOrPathToUri(match[3]); |
| 198 var member = match[1]; | |
| 199 member += new List.filled('/'.allMatches(match[2]).length, ".<fn>").join(); | |
| 200 if (member == '') member = '<fn>'; | |
| 201 | 209 |
| 202 // Some Firefox members have initial dots. We remove them for consistency | 210 var member; |
| 203 // with other platforms. | 211 if (match[1] != null) { |
| 204 member = member.replaceFirst(_initialDot, ''); | 212 member = match[1]; |
| 205 return new Frame(uri, int.parse(match[4]), null, member); | 213 member += |
| 214 new List.filled('/'.allMatches(match[2]).length, ".<fn>").join(); |
| 215 if (member == '') member = '<fn>'; |
| 216 |
| 217 // Some Firefox members have initial dots. We remove them for consistency |
| 218 // with other platforms. |
| 219 member = member.replaceFirst(_initialDot, ''); |
| 220 } else { |
| 221 member = '<fn>'; |
| 222 } |
| 223 |
| 224 var line = match[4] == '' ? null : int.parse(match[4]); |
| 225 var column = match[5] == null || match[5] == '' ? |
| 226 null : int.parse(match[5]); |
| 227 return new Frame(uri, line, column, member); |
| 206 } | 228 } |
| 207 | 229 |
| 208 /// Parses a string representation of a Safari 6.0 stack frame. | 230 /// Parses a string representation of a Safari 6.0 stack frame. |
| 209 /// | 231 @Deprecated("Use Frame.parseSafari instead.") |
| 210 /// Safari 6.0 frames look just like Firefox frames. Prior to Safari 6.0, | |
| 211 /// stack traces can't be retrieved. | |
| 212 factory Frame.parseSafari6_0(String frame) => new Frame.parseFirefox(frame); | 232 factory Frame.parseSafari6_0(String frame) => new Frame.parseFirefox(frame); |
| 213 | 233 |
| 214 /// Parses a string representation of a Safari 6.1+ stack frame. | 234 /// Parses a string representation of a Safari 6.1+ stack frame. |
| 215 factory Frame.parseSafari6_1(String frame) { | 235 @Deprecated("Use Frame.parseSafari instead.") |
| 216 var match = _safariFrame.firstMatch(frame); | 236 factory Frame.parseSafari6_1(String frame) => new Frame.parseFirefox(frame); |
| 217 if (match == null) { | |
| 218 throw new FormatException( | |
| 219 "Couldn't parse Safari stack trace line '$frame'."); | |
| 220 } | |
| 221 | 237 |
| 222 var uri = Uri.parse(match[2]); | 238 /// Parses a string representation of a Safari stack frame. |
| 223 var member = match[1]; | 239 factory Frame.parseSafari(String frame) => new Frame.parseFirefox(frame); |
| 224 if (member == null) member = '<fn>'; | |
| 225 var line = match[3] == '' ? null : int.parse(match[3]); | |
| 226 var column = match[4] == '' ? null : int.parse(match[4]); | |
| 227 return new Frame(uri, line, column, member); | |
| 228 } | |
| 229 | 240 |
| 230 /// Parses this package's string representation of a stack frame. | 241 /// Parses this package's string representation of a stack frame. |
| 231 factory Frame.parseFriendly(String frame) { | 242 factory Frame.parseFriendly(String frame) { |
| 232 var match = _friendlyFrame.firstMatch(frame); | 243 var match = _friendlyFrame.firstMatch(frame); |
| 233 if (match == null) { | 244 if (match == null) { |
| 234 throw new FormatException( | 245 throw new FormatException( |
| 235 "Couldn't parse package:stack_trace stack trace line '$frame'."); | 246 "Couldn't parse package:stack_trace stack trace line '$frame'."); |
| 236 } | 247 } |
| 237 | 248 |
| 238 var uri = Uri.parse(match[1]); | 249 var uri = Uri.parse(match[1]); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 268 // their stack frames. However, if we do get a relative path, we should | 279 // their stack frames. However, if we do get a relative path, we should |
| 269 // handle it gracefully. | 280 // handle it gracefully. |
| 270 if (uriOrPath.contains('\\')) return path.windows.toUri(uriOrPath); | 281 if (uriOrPath.contains('\\')) return path.windows.toUri(uriOrPath); |
| 271 return Uri.parse(uriOrPath); | 282 return Uri.parse(uriOrPath); |
| 272 } | 283 } |
| 273 | 284 |
| 274 Frame(this.uri, this.line, this.column, this.member); | 285 Frame(this.uri, this.line, this.column, this.member); |
| 275 | 286 |
| 276 String toString() => '$location in $member'; | 287 String toString() => '$location in $member'; |
| 277 } | 288 } |
| OLD | NEW |