Chromium Code Reviews| Index: pkg/stack_trace/lib/src/frame.dart |
| diff --git a/pkg/stack_trace/lib/src/frame.dart b/pkg/stack_trace/lib/src/frame.dart |
| index d750b9178d56c1bd55af01da828f224be256717b..ae2f41779ae53cce974f756282c0a00869c5c0f0 100644 |
| --- a/pkg/stack_trace/lib/src/frame.dart |
| +++ b/pkg/stack_trace/lib/src/frame.dart |
| @@ -9,9 +9,17 @@ import 'package:pathos/path.dart' as path; |
| import 'trace.dart'; |
| -final _nativeFrameRegExp = new RegExp( |
| +final _vmFrame = new RegExp( |
| r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$'); |
| +final _v8Frame = new RegExp( |
| + r'^\s*at (?:([^\s].*) \((.+):(\d+):(\d+)\)|(.+):(\d+):(\d+))$'); |
| + |
| +final _firefoxFrame = new RegExp( |
| + 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.
|
| + |
| +final _initialDot = new RegExp(r"^\."); |
| + |
| /// A single stack frame. Each frame points to a precise location in Dart code. |
| class Frame { |
| /// The URI of the file in which the code is located. |
| @@ -76,13 +84,11 @@ class Frame { |
| return new Trace.current(level + 1).frames.first; |
| } |
| - /// Parses a string representation of a stack frame. |
| - /// |
| - /// [frame] should be formatted in the same way as a native stack trace frame. |
| - factory Frame.parse(String frame) { |
| - var match = _nativeFrameRegExp.firstMatch(frame); |
| + /// Parses a string representation of a Dart VM stack frame. |
| + factory Frame.parseVM(String frame) { |
| + var match = _vmFrame.firstMatch(frame); |
| if (match == null) { |
| - throw new FormatException("Couldn't parse stack trace line '$frame'."); |
| + throw new FormatException("Couldn't parse VM stack trace line '$frame'."); |
| } |
| var uri = Uri.parse(match[2]); |
| @@ -90,6 +96,48 @@ class Frame { |
| return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member); |
| } |
| + /// Parses a string representation of a Chrome/V8 stack frame. |
| + factory Frame.parseV8(String frame) { |
| + var match = _v8Frame.firstMatch(frame); |
| + if (match == null) { |
| + throw new FormatException("Couldn't parse V8 stack trace line '$frame'."); |
| + } |
| + |
| + // V8 stack frames can be in two forms. |
| + if (match[2] != null) { |
| + // The first form looks like " at FUNCTION (URI:LINE:COL)" |
| + var uri = Uri.parse(match[2]); |
| + var member = match[1].replaceAll("<anonymous>", "<fn>"); |
| + return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member); |
| + } else { |
| + // The second form looks like " at URI:LINE:COL", and is used for |
| + // anonymous functions. |
| + var uri = Uri.parse(match[5]); |
| + return new Frame(uri, int.parse(match[6]), int.parse(match[7]), "<fn>"); |
| + } |
| + } |
| + |
| + /// Parses a string representation of a Firefox stack frame. |
| + factory Frame.parseFirefox(String frame) { |
| + var match = _firefoxFrame.firstMatch(frame); |
| + if (match == null) { |
| + throw new FormatException( |
| + "Couldn't parse Firefox stack trace line '$frame'."); |
| + } |
| + |
| + var uri = Uri.parse(match[3]); |
| + var member = match[1]; |
| + if (member == "") { |
| + member = "<fn>"; |
| + } else if (match[2] != null) { |
| + member = "$member.<fn>"; |
| + } |
| + // Some Firefox members have initial dots. We remove them for consistency |
| + // with other platforms. |
| + member = member.replaceFirst(_initialDot, ''); |
| + return new Frame(uri, int.parse(match[4]), null, member); |
| + } |
| + |
| Frame(this.uri, this.line, this.column, this.member); |
| String toString() => '$location in $member'; |