Chromium Code Reviews| 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:pathos/path.dart' as path; | 8 import 'package:pathos/path.dart' as path; |
| 9 | 9 |
| 10 import 'trace.dart'; | 10 import 'trace.dart'; |
| 11 | 11 |
| 12 final _nativeFrameRegExp = new RegExp( | 12 final _vmFrame = new RegExp( |
| 13 r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$'); | 13 r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$'); |
| 14 | 14 |
| 15 final _v8Frame = new RegExp( | |
| 16 r'^\s*at (?:([^\s].*) \((.+):(\d+):(\d+)\)|(.+):(\d+):(\d+))$'); | |
| 17 | |
| 18 final _firefoxFrame = new RegExp( | |
| 19 r'^([^@(/]*)(?:\(.*\))?(/[^<]*<)?(?:\(.*\))?@(.*):(\d+)$'); | |
|
Bob Nystrom
2013/06/26 17:01:05
Can you give an example for each of these?
nweiz
2013/06/26 20:08:01
Done.
| |
| 20 | |
| 21 final _initialDot = new RegExp(r"^\."); | |
| 22 | |
| 15 /// A single stack frame. Each frame points to a precise location in Dart code. | 23 /// A single stack frame. Each frame points to a precise location in Dart code. |
| 16 class Frame { | 24 class Frame { |
| 17 /// The URI of the file in which the code is located. | 25 /// The URI of the file in which the code is located. |
| 18 /// | 26 /// |
| 19 /// This URI will usually have the scheme `dart`, `file`, `http`, or `https`. | 27 /// This URI will usually have the scheme `dart`, `file`, `http`, or `https`. |
| 20 final Uri uri; | 28 final Uri uri; |
| 21 | 29 |
| 22 /// The line number on which the code location is located. | 30 /// The line number on which the code location is located. |
| 23 /// | 31 /// |
| 24 /// This can be null, indicating that the line number is unknown or | 32 /// This can be null, indicating that the line number is unknown or |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 /// higher than `1`, it will return higher frames. | 77 /// higher than `1`, it will return higher frames. |
| 70 factory Frame.caller([int level=1]) { | 78 factory Frame.caller([int level=1]) { |
| 71 if (level < 0) { | 79 if (level < 0) { |
| 72 throw new ArgumentError("Argument [level] must be greater than or equal " | 80 throw new ArgumentError("Argument [level] must be greater than or equal " |
| 73 "to 0."); | 81 "to 0."); |
| 74 } | 82 } |
| 75 | 83 |
| 76 return new Trace.current(level + 1).frames.first; | 84 return new Trace.current(level + 1).frames.first; |
| 77 } | 85 } |
| 78 | 86 |
| 79 /// Parses a string representation of a stack frame. | 87 /// Parses a string representation of a Dart VM stack frame. |
| 80 /// | 88 factory Frame.parseVM(String frame) { |
| 81 /// [frame] should be formatted in the same way as a native stack trace frame. | 89 var match = _vmFrame.firstMatch(frame); |
| 82 factory Frame.parse(String frame) { | |
| 83 var match = _nativeFrameRegExp.firstMatch(frame); | |
| 84 if (match == null) { | 90 if (match == null) { |
| 85 throw new FormatException("Couldn't parse stack trace line '$frame'."); | 91 throw new FormatException("Couldn't parse VM stack trace line '$frame'."); |
| 86 } | 92 } |
| 87 | 93 |
| 88 var uri = Uri.parse(match[2]); | 94 var uri = Uri.parse(match[2]); |
| 89 var member = match[1].replaceAll("<anonymous closure>", "<fn>"); | 95 var member = match[1].replaceAll("<anonymous closure>", "<fn>"); |
| 90 return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member); | 96 return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member); |
| 91 } | 97 } |
| 92 | 98 |
| 99 /// Parses a string representation of a Chrome/V8 stack frame. | |
| 100 factory Frame.parseV8(String frame) { | |
| 101 var match = _v8Frame.firstMatch(frame); | |
| 102 if (match == null) { | |
| 103 throw new FormatException("Couldn't parse V8 stack trace line '$frame'."); | |
| 104 } | |
| 105 | |
| 106 // V8 stack frames can be in two forms. | |
| 107 if (match[2] != null) { | |
| 108 // The first form looks like " at FUNCTION (URI:LINE:COL)" | |
| 109 var uri = Uri.parse(match[2]); | |
| 110 var member = match[1].replaceAll("<anonymous>", "<fn>"); | |
| 111 return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member); | |
| 112 } else { | |
| 113 // The second form looks like " at URI:LINE:COL", and is used for | |
| 114 // anonymous functions. | |
| 115 var uri = Uri.parse(match[5]); | |
| 116 return new Frame(uri, int.parse(match[6]), int.parse(match[7]), "<fn>"); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 /// Parses a string representation of a Firefox stack frame. | |
| 121 factory Frame.parseFirefox(String frame) { | |
| 122 var match = _firefoxFrame.firstMatch(frame); | |
| 123 if (match == null) { | |
| 124 throw new FormatException( | |
| 125 "Couldn't parse Firefox stack trace line '$frame'."); | |
| 126 } | |
| 127 | |
| 128 var uri = Uri.parse(match[3]); | |
| 129 var member = match[1]; | |
| 130 if (member == "") { | |
| 131 member = "<fn>"; | |
| 132 } else if (match[2] != null) { | |
| 133 member = "$member.<fn>"; | |
| 134 } | |
| 135 // Some Firefox members have initial dots. We remove them for consistency | |
| 136 // with other platforms. | |
| 137 member = member.replaceFirst(_initialDot, ''); | |
| 138 return new Frame(uri, int.parse(match[4]), null, member); | |
| 139 } | |
| 140 | |
| 93 Frame(this.uri, this.line, this.column, this.member); | 141 Frame(this.uri, this.line, this.column, this.member); |
| 94 | 142 |
| 95 String toString() => '$location in $member'; | 143 String toString() => '$location in $member'; |
| 96 } | 144 } |
| OLD | NEW |