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

Side by Side Diff: pkg/stack_trace/lib/src/frame.dart

Issue 16097012: Make the StackTrace library better handle core library frames. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/stack_trace/lib/src/trace.dart » ('j') | pkg/stack_trace/test/frame_test.dart » ('J')
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 import 'utils.dart'; 11 import 'utils.dart';
12 12
13 final _nativeFrameRegExp = new RegExp( 13 final _nativeFrameRegExp = new RegExp(
14 r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$'); 14 r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$');
15 15
16 /// A single stack frame. Each frame points to a precise location in Dart code. 16 /// A single stack frame. Each frame points to a precise location in Dart code.
17 class Frame { 17 class Frame {
18 /// The URI of the file in which the code is located. 18 /// The URI of the file in which the code is located.
19 /// 19 ///
20 /// This URI will usually have the scheme `dart`, `file`, `http`, or `https`. 20 /// This URI will usually have the scheme `dart`, `file`, `http`, or `https`.
21 final Uri uri; 21 final Uri uri;
22 22
23 /// The line number on which the code location is located. 23 /// The line number on which the code location is located.
24 ///
25 /// This can be null, indicating that the line number is unknown or
26 /// unimportant.
24 final int line; 27 final int line;
25 28
26 /// The column number of the code location. 29 /// The column number of the code location.
30 ///
31 /// This can be null, indicating that the column number is unknown or
32 /// unimportant.
27 final int column; 33 final int column;
28 34
29 /// The name of the member in which the code location occurs. 35 /// The name of the member in which the code location occurs.
30 /// 36 ///
31 /// Anonymous closures are represented as `<fn>` in this member string. 37 /// Anonymous closures are represented as `<fn>` in this member string.
32 final String member; 38 final String member;
33 39
34 /// Whether this stack frame comes from the Dart core libraries. 40 /// Whether this stack frame comes from the Dart core libraries.
35 bool get isCore => uri.scheme == 'dart'; 41 bool get isCore => uri.scheme == 'dart';
36 42
37 /// Returns a human-friendly description of the library that this stack frame 43 /// Returns a human-friendly description of the library that this stack frame
38 /// comes from. 44 /// comes from.
39 /// 45 ///
40 /// This will usually be the string form of [uri], but a relative path will be 46 /// This will usually be the string form of [uri], but a relative path will be
41 /// used if possible. 47 /// used if possible.
42 String get library { 48 String get library {
43 // TODO(nweiz): handle relative URIs here as well once pathos supports that. 49 // TODO(nweiz): handle relative URIs here as well once pathos supports that.
44 if (uri.scheme != 'file') return uri.toString(); 50 if (uri.scheme != 'file') return uri.toString();
45 return path.relative(fileUriToPath(uri)); 51 return path.relative(fileUriToPath(uri));
46 } 52 }
47 53
48 /// Returns the name of the package this stack frame comes from, or `null` if 54 /// Returns the name of the package this stack frame comes from, or `null` if
49 /// this stack frame doesn't come from a `package:` URL. 55 /// this stack frame doesn't come from a `package:` URL.
50 String get package { 56 String get package {
51 if (uri.scheme != 'package') return null; 57 if (uri.scheme != 'package') return null;
52 return uri.path.split('/').first; 58 return uri.path.split('/').first;
53 } 59 }
54 60
55 /// A human-friendly description of the code location. 61 /// A human-friendly description of the code location.
56 ///
57 /// For Dart core libraries, this will omit the line and column information,
58 /// since those are useless for baked-in libraries.
59 String get location { 62 String get location {
60 if (isCore) return library; 63 if (line == null || column == null) return library;
61 return '$library $line:$column'; 64 return '$library $line:$column';
62 } 65 }
63 66
64 /// Returns a single frame of the current stack. 67 /// Returns a single frame of the current stack.
65 /// 68 ///
66 /// By default, this will return the frame above the current method. If 69 /// By default, this will return the frame above the current method. If
67 /// [level] is `0`, it will return the current method's frame; if [level] is 70 /// [level] is `0`, it will return the current method's frame; if [level] is
68 /// higher than `1`, it will return higher frames. 71 /// higher than `1`, it will return higher frames.
69 factory Frame.caller([int level=1]) { 72 factory Frame.caller([int level=1]) {
70 if (level < 0) { 73 if (level < 0) {
(...skipping 15 matching lines...) Expand all
86 89
87 var uri = Uri.parse(match[2]); 90 var uri = Uri.parse(match[2]);
88 var member = match[1].replaceAll("<anonymous closure>", "<fn>"); 91 var member = match[1].replaceAll("<anonymous closure>", "<fn>");
89 return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member); 92 return new Frame(uri, int.parse(match[3]), int.parse(match[4]), member);
90 } 93 }
91 94
92 Frame(this.uri, this.line, this.column, this.member); 95 Frame(this.uri, this.line, this.column, this.member);
93 96
94 String toString() => '$location in $member'; 97 String toString() => '$location in $member';
95 } 98 }
OLDNEW
« no previous file with comments | « no previous file | pkg/stack_trace/lib/src/trace.dart » ('j') | pkg/stack_trace/test/frame_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698