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

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

Issue 18029023: Add a couple functions to package:stack_trace. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 6 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 | « no previous file | pkg/stack_trace/lib/src/lazy_trace.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6daca4650552fa74e632bd29fff7ef0eb4fd3498..6ba30794fbc928d0b873754118697e94d159f6ef 100644
--- a/pkg/stack_trace/lib/src/frame.dart
+++ b/pkg/stack_trace/lib/src/frame.dart
@@ -24,6 +24,11 @@ final _v8Frame = new RegExp(
final _firefoxFrame = new RegExp(
r'^([^@(/]*)(?:\(.*\))?(/[^<]*<?)?(?:\(.*\))?@(.*):(\d+)$');
+// foo/bar.dart 10:11 in Foo._bar
+// http://dartlang.org/foo/bar.dart in Foo._bar
+final _friendlyFrame = new RegExp(
+ r'^([^\s]+)(?: (\d+):(\d+))?\s+([^\d][^\s]*)$');
+
final _initialDot = new RegExp(r"^\.");
/// A single stack frame. Each frame points to a precise location in Dart code.
@@ -144,6 +149,26 @@ class Frame {
return new Frame(uri, int.parse(match[4]), null, member);
}
+ /// Parses this package's string representation of a stack frame.
+ factory Frame.parseFriendly(String frame) {
+ var match = _friendlyFrame.firstMatch(frame);
+ if (match == null) {
+ throw new FormatException(
+ "Couldn't parse package:stack_trace stack trace line '$frame'.");
+ }
+
+ var uri = Uri.parse(match[1]);
+ // If there's no scheme, this is a relative URI. We should interpret it as
+ // relative to the current working directory.
+ if (uri.scheme == '') {
+ uri = path.toUri(path.absolute(path.fromUri(uri)));
+ }
+
+ var line = match[2] == null ? null : int.parse(match[2]);
+ var column = match[3] == null ? null : int.parse(match[3]);
+ return new Frame(uri, line, column, match[4]);
+ }
+
Frame(this.uri, this.line, this.column, this.member);
String toString() => '$location in $member';
« no previous file with comments | « no previous file | pkg/stack_trace/lib/src/lazy_trace.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698