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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/stack_trace/lib/src/lazy_trace.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // #1 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21) 12 // #1 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21)
13 final _vmFrame = new RegExp( 13 final _vmFrame = new RegExp(
14 r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$'); 14 r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$');
15 15
16 // at VW.call$0 (http://pub.dartlang.org/stuff.dart.js:560:28) 16 // at VW.call$0 (http://pub.dartlang.org/stuff.dart.js:560:28)
17 // at http://pub.dartlang.org/stuff.dart.js:560:28 17 // at http://pub.dartlang.org/stuff.dart.js:560:28
18 final _v8Frame = new RegExp( 18 final _v8Frame = new RegExp(
19 r'^\s*at (?:([^\s].*) \((.+):(\d+):(\d+)\)|(.+):(\d+):(\d+))$'); 19 r'^\s*at (?:([^\s].*) \((.+):(\d+):(\d+)\)|(.+):(\d+):(\d+))$');
20 20
21 // .VW.call$0@http://pub.dartlang.org/stuff.dart.js:560 21 // .VW.call$0@http://pub.dartlang.org/stuff.dart.js:560
22 // .VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560 22 // .VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560
23 // .VW.call$0/name<@http://pub.dartlang.org/stuff.dart.js:560 23 // .VW.call$0/name<@http://pub.dartlang.org/stuff.dart.js:560
24 final _firefoxFrame = new RegExp( 24 final _firefoxFrame = new RegExp(
25 r'^([^@(/]*)(?:\(.*\))?(/[^<]*<?)?(?:\(.*\))?@(.*):(\d+)$'); 25 r'^([^@(/]*)(?:\(.*\))?(/[^<]*<?)?(?:\(.*\))?@(.*):(\d+)$');
26 26
27 // foo/bar.dart 10:11 in Foo._bar
28 // http://dartlang.org/foo/bar.dart in Foo._bar
29 final _friendlyFrame = new RegExp(
30 r'^([^\s]+)(?: (\d+):(\d+))?\s+([^\d][^\s]*)$');
31
27 final _initialDot = new RegExp(r"^\."); 32 final _initialDot = new RegExp(r"^\.");
28 33
29 /// A single stack frame. Each frame points to a precise location in Dart code. 34 /// A single stack frame. Each frame points to a precise location in Dart code.
30 class Frame { 35 class Frame {
31 /// The URI of the file in which the code is located. 36 /// The URI of the file in which the code is located.
32 /// 37 ///
33 /// This URI will usually have the scheme `dart`, `file`, `http`, or `https`. 38 /// This URI will usually have the scheme `dart`, `file`, `http`, or `https`.
34 final Uri uri; 39 final Uri uri;
35 40
36 /// The line number on which the code location is located. 41 /// The line number on which the code location is located.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 member = "<fn>"; 142 member = "<fn>";
138 } else if (match[2] != null) { 143 } else if (match[2] != null) {
139 member = "$member.<fn>"; 144 member = "$member.<fn>";
140 } 145 }
141 // Some Firefox members have initial dots. We remove them for consistency 146 // Some Firefox members have initial dots. We remove them for consistency
142 // with other platforms. 147 // with other platforms.
143 member = member.replaceFirst(_initialDot, ''); 148 member = member.replaceFirst(_initialDot, '');
144 return new Frame(uri, int.parse(match[4]), null, member); 149 return new Frame(uri, int.parse(match[4]), null, member);
145 } 150 }
146 151
152 /// Parses this package's string representation of a stack frame.
153 factory Frame.parseFriendly(String frame) {
154 var match = _friendlyFrame.firstMatch(frame);
155 if (match == null) {
156 throw new FormatException(
157 "Couldn't parse package:stack_trace stack trace line '$frame'.");
158 }
159
160 var uri = Uri.parse(match[1]);
161 // If there's no scheme, this is a relative URI. We should interpret it as
162 // relative to the current working directory.
163 if (uri.scheme == '') {
164 uri = path.toUri(path.absolute(path.fromUri(uri)));
165 }
166
167 var line = match[2] == null ? null : int.parse(match[2]);
168 var column = match[3] == null ? null : int.parse(match[3]);
169 return new Frame(uri, line, column, match[4]);
170 }
171
147 Frame(this.uri, this.line, this.column, this.member); 172 Frame(this.uri, this.line, this.column, this.member);
148 173
149 String toString() => '$location in $member'; 174 String toString() => '$location in $member';
150 } 175 }
OLDNEW
« 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