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

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

Issue 18167002: Add support for V8 and Firefox stack traces in pkg/stack_trace. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make the browser tests work. 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 | « pkg/stack_trace/lib/src/frame.dart ('k') | pkg/stack_trace/test/frame_test.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 trace; 5 library trace;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'frame.dart'; 10 import 'frame.dart';
11 import 'lazy_trace.dart'; 11 import 'lazy_trace.dart';
12 12
13 final _terseRegExp = new RegExp(r"(-patch)?(/.*)?$"); 13 final _terseRegExp = new RegExp(r"(-patch)?(/.*)?$");
14 14
15 /// A RegExp to match Firefox's stack traces.
16 ///
17 /// Firefox's trace frames start with the name of the function in which the
18 /// error occurred, possibly including its parameters inside `()`. For example,
19 /// `.VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560`.
20 final _firefoxTrace = new RegExp(r"^([.0-9A-Za-z_$/<]*|\(.*\))*@");
21
15 /// A stack trace, comprised of a list of stack frames. 22 /// A stack trace, comprised of a list of stack frames.
16 class Trace implements StackTrace { 23 class Trace implements StackTrace {
17 /// The stack frames that comprise this stack trace. 24 /// The stack frames that comprise this stack trace.
18 final List<Frame> frames; 25 final List<Frame> frames;
19 26
20 /// Returns a human-readable representation of [stackTrace]. If [terse] is 27 /// Returns a human-readable representation of [stackTrace]. If [terse] is
21 /// set, this folds together multiple stack frames from the Dart core 28 /// set, this folds together multiple stack frames from the Dart core
22 /// libraries, so that only the core library method directly called from user 29 /// libraries, so that only the core library method directly called from user
23 /// code is visible (see [Trace.terse]). 30 /// code is visible (see [Trace.terse]).
24 static String format(StackTrace stackTrace, {bool terse: true}) { 31 static String format(StackTrace stackTrace, {bool terse: true}) {
(...skipping 25 matching lines...) Expand all
50 /// 57 ///
51 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's 58 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's
52 /// a [Trace], it will be returned as-is. 59 /// a [Trace], it will be returned as-is.
53 factory Trace.from(StackTrace trace) { 60 factory Trace.from(StackTrace trace) {
54 if (trace is Trace) return trace; 61 if (trace is Trace) return trace;
55 return new LazyTrace(() => new Trace.parse(trace.toString())); 62 return new LazyTrace(() => new Trace.parse(trace.toString()));
56 } 63 }
57 64
58 /// Parses a string representation of a stack trace. 65 /// Parses a string representation of a stack trace.
59 /// 66 ///
60 /// [trace] should be formatted in the same way as native stack traces. 67 /// [trace] should be formatted in the same way as a Dart VM or browser stack
61 Trace.parse(String trace) 68 /// trace.
62 : this(trace.trim().split("\n").map((line) => new Frame.parse(line))); 69 factory Trace.parse(String trace) {
70 if (trace.isEmpty) return new Trace(<Frame>[]);
71 if (trace.startsWith("Error\n")) return new Trace.parseV8(trace);
72 if (trace.contains(_firefoxTrace)) return new Trace.parseFirefox(trace);
73
74 // Default to parsing the stack trace as a VM trace. This is also hit on IE
75 // and Safari, where the stack trace is just an empty string (issue 11257).
76 return new Trace.parseVM(trace);
77 }
78
79 /// Parses a string representation of a Dart VM stack trace.
80 Trace.parseVM(String trace)
81 : this(trace.trim().split("\n").map((line) => new Frame.parseVM(line)));
82
83 /// Parses a string representation of a Chrome/V8 stack trace.
84 Trace.parseV8(String trace)
85 : this(trace.split("\n").skip(1).map((line) => new Frame.parseV8(line)));
86
87 /// Parses a string representation of a Firefox stack trace.
88 Trace.parseFirefox(String trace)
89 : this(trace.trim().split("\n")
90 .map((line) => new Frame.parseFirefox(line)));
63 91
64 /// Returns a new [Trace] comprised of [frames]. 92 /// Returns a new [Trace] comprised of [frames].
65 Trace(Iterable<Frame> frames) 93 Trace(Iterable<Frame> frames)
66 : frames = new UnmodifiableListView<Frame>(frames.toList()); 94 : frames = new UnmodifiableListView<Frame>(frames.toList());
67 95
68 // TODO(nweiz): Keep track of which [Frame]s are part of the partial stack 96 // TODO(nweiz): Keep track of which [Frame]s are part of the partial stack
69 // trace and only print them. 97 // trace and only print them.
70 /// Returns a string representation of this stack trace. 98 /// Returns a string representation of this stack trace.
71 /// 99 ///
72 /// This is identical to [toString]. It will not be formatted in the manner of 100 /// This is identical to [toString]. It will not be formatted in the manner of
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (string.length >= length) return string; 161 if (string.length >= length) return string;
134 162
135 var result = new StringBuffer(); 163 var result = new StringBuffer();
136 result.write(string); 164 result.write(string);
137 for (var i = 0; i < length - string.length; i++) { 165 for (var i = 0; i < length - string.length; i++) {
138 result.write(' '); 166 result.write(' ');
139 } 167 }
140 168
141 return result.toString(); 169 return result.toString();
142 } 170 }
OLDNEW
« no previous file with comments | « pkg/stack_trace/lib/src/frame.dart ('k') | pkg/stack_trace/test/frame_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698