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

Unified Diff: pkg/stack_trace/lib/src/trace.dart

Issue 578993002: Unify parsing of Firefox and Safari stack traces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/stack_trace/lib/src/frame.dart ('k') | pkg/stack_trace/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/stack_trace/lib/src/trace.dart
diff --git a/pkg/stack_trace/lib/src/trace.dart b/pkg/stack_trace/lib/src/trace.dart
index c540d78c67ba9c1cbc66dc3c8871c2f032443cff..2690ece17a2fac811a86413328eb2fd3fd7a1b58 100644
--- a/pkg/stack_trace/lib/src/trace.dart
+++ b/pkg/stack_trace/lib/src/trace.dart
@@ -29,25 +29,28 @@ final _v8Trace = new RegExp(r"\n ?at ");
/// though it is possible for the message to match this as well.
final _v8TraceLine = new RegExp(r" ?at ");
-/// A RegExp to match Safari's stack traces.
+/// A RegExp to match Firefox and Safari's stack traces.
///
-/// Prior to version 6, Safari's stack traces were uncapturable. In v6 they were
-/// almost identical to Firefox traces, and so are handled by the Firefox code.
-/// In v6.1+, they have their own format that's similar to Firefox but distinct
-/// enough to warrant handling separately.
-///
-/// Most notably, Safari traces occasionally don't include the initial method
-/// name followed by "@", and they always have both the line and column number
-/// (or just a trailing colon if no column number is available).
-final _safariTrace = new RegExp(r"^([0-9A-Za-z_$]*@)?.*:\d*:\d*$",
- multiLine: true);
-
-/// A RegExp to match Firefox's stack traces.
+/// Firefox and Safari have very similar stack trace formats, so we use the same
+/// logic for parsing them.
///
/// Firefox's trace frames start with the name of the function in which the
/// error occurred, possibly including its parameters inside `()`. For example,
/// `.VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560`.
-final _firefoxTrace = new RegExp(r"^([.0-9A-Za-z_$/<]|\(.*\))*@");
+///
+/// Safari traces occasionally don't include the initial method name followed by
+/// "@", and they always have both the line and column number (or just a
+/// trailing colon if no column number is available). They can also contain
+/// empty lines or lines consisting only of `[native code]`.
+final _firefoxSafariTrace = new RegExp(
+ r"^"
+ r"(" // Member description. Not present in some Safari frames.
+ r"([.0-9A-Za-z_$/<]|\(.*\))*" // Member name and arguments.
+ r"@"
+ r")?"
+ r"[^\s]*" // Frame URL.
+ r":\d*" // Line or column number. Some older frames only have a line number.
+ r"$", multiLine: true);
/// A RegExp to match this package's stack traces.
final _friendlyTrace = new RegExp(r"^[^\s]+( \d+(:\d+)?)?[ \t]+[^\s]+$",
@@ -112,12 +115,9 @@ class Trace implements StackTrace {
try {
if (trace.isEmpty) return new Trace(<Frame>[]);
if (trace.contains(_v8Trace)) return new Trace.parseV8(trace);
- // Safari 6.1+ traces could be misinterpreted as Firefox traces, so we
- // check for them first.
- if (trace.contains(_safariTrace)) return new Trace.parseSafari6_1(trace);
- // Safari 6.0 traces are a superset of Firefox traces, so we parse those
- // two together.
- if (trace.contains(_firefoxTrace)) return new Trace.parseSafari6_0(trace);
+ if (trace.contains(_firefoxSafariTrace)) {
+ return new Trace.parseFirefox(trace);
+ }
if (trace.contains(_friendlyTrace)) {
return new Trace.parseFriendly(trace);
}
@@ -157,29 +157,20 @@ class Trace implements StackTrace {
/// Parses a string representation of a Firefox stack trace.
Trace.parseFirefox(String trace)
: this(trace.trim().split("\n")
+ .where((line) => line.isNotEmpty && line != '[native code]')
.map((line) => new Frame.parseFirefox(line)));
/// Parses a string representation of a Safari stack trace.
- ///
- /// This will automatically decide between [parseSafari6_0] and
- /// [parseSafari6_1] based on the contents of [trace].
- factory Trace.parseSafari(String trace) {
- if (trace.contains(_safariTrace)) return new Trace.parseSafari6_1(trace);
- return new Trace.parseSafari6_0(trace);
- }
+ Trace.parseSafari(String trace)
+ : this.parseFirefox(trace);
/// Parses a string representation of a Safari 6.1+ stack trace.
+ @Deprecated("Use Trace.parseSafari instead.")
Trace.parseSafari6_1(String trace)
- : this(trace.trim().split("\n")
- .where((line) => line.isNotEmpty)
- .map((line) => new Frame.parseSafari6_1(line)));
+ : this.parseSafari(trace);
/// Parses a string representation of a Safari 6.0 stack trace.
- ///
- /// Safari 6.0 stack traces look just like Firefox traces, except that they
- /// sometimes (e.g. in isolates) have a "[native code]" frame. We just ignore
- /// this frame to make the stack format more consistent between browsers.
- /// Prior to Safari 6.0, stack traces can't be retrieved.
+ @Deprecated("Use Trace.parseSafari instead.")
Trace.parseSafari6_0(String trace)
: this(trace.trim().split("\n")
.where((line) => line != '[native code]')
« no previous file with comments | « pkg/stack_trace/lib/src/frame.dart ('k') | pkg/stack_trace/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698