Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 final _firefoxTrace = new RegExp(r"^[.0-9A-Za-z_$]*@"); | |
|
Bob Nystrom
2013/06/26 17:01:05
Document what this is for and an example of what t
nweiz
2013/06/26 20:08:01
Done.
| |
| 16 | |
| 15 /// A stack trace, comprised of a list of stack frames. | 17 /// A stack trace, comprised of a list of stack frames. |
| 16 class Trace implements StackTrace { | 18 class Trace implements StackTrace { |
| 17 /// The stack frames that comprise this stack trace. | 19 /// The stack frames that comprise this stack trace. |
| 18 final List<Frame> frames; | 20 final List<Frame> frames; |
| 19 | 21 |
| 20 /// Returns a human-readable representation of [stackTrace]. If [terse] is | 22 /// Returns a human-readable representation of [stackTrace]. If [terse] is |
| 21 /// set, this folds together multiple stack frames from the Dart core | 23 /// set, this folds together multiple stack frames from the Dart core |
| 22 /// libraries, so that only the core library method directly called from user | 24 /// libraries, so that only the core library method directly called from user |
| 23 /// code is visible (see [Trace.terse]). | 25 /// code is visible (see [Trace.terse]). |
| 24 static String format(StackTrace stackTrace, {bool terse: true}) { | 26 static String format(StackTrace stackTrace, {bool terse: true}) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 50 /// | 52 /// |
| 51 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's | 53 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's |
| 52 /// a [Trace], it will be returned as-is. | 54 /// a [Trace], it will be returned as-is. |
| 53 factory Trace.from(StackTrace trace) { | 55 factory Trace.from(StackTrace trace) { |
| 54 if (trace is Trace) return trace; | 56 if (trace is Trace) return trace; |
| 55 return new LazyTrace(() => new Trace.parse(trace.toString())); | 57 return new LazyTrace(() => new Trace.parse(trace.toString())); |
| 56 } | 58 } |
| 57 | 59 |
| 58 /// Parses a string representation of a stack trace. | 60 /// Parses a string representation of a stack trace. |
| 59 /// | 61 /// |
| 60 /// [trace] should be formatted in the same way as native stack traces. | 62 /// [trace] should be formatted in the same way as a Dart VM or browser stack |
| 61 Trace.parse(String trace) | 63 /// trace. |
| 62 : this(trace.trim().split("\n").map((line) => new Frame.parse(line))); | 64 factory Trace.parse(String trace) { |
| 65 if (trace.startsWith("Error\n")) return new Trace.parseV8(trace); | |
| 66 if (trace.contains(_firefoxTrace)) return new Trace.parseFirefox(trace); | |
| 67 | |
| 68 // Default to parsing the stack trace as a VM trace. This is also hit on IE | |
| 69 // and Safari, where the stack trace is just an empty string (issue 11257). | |
| 70 return new Trace.parseVM(trace); | |
| 71 } | |
| 72 | |
| 73 /// Parses a string representation of a Dart VM stack trace. | |
| 74 Trace.parseVM(String trace) | |
| 75 : this(trace.trim().split("\n").map((line) => new Frame.parseVM(line))); | |
| 76 | |
| 77 /// Parses a string representation of a Chrome/V8 stack trace. | |
| 78 Trace.parseV8(String trace) | |
| 79 : this(trace.split("\n").skip(1).map((line) => new Frame.parseV8(line))); | |
| 80 | |
| 81 /// Parses a string representation of a Firefox stack trace. | |
| 82 Trace.parseFirefox(String trace) | |
| 83 : this(trace.trim().split("\n") | |
| 84 .map((line) => new Frame.parseFirefox(line))); | |
| 63 | 85 |
| 64 /// Returns a new [Trace] comprised of [frames]. | 86 /// Returns a new [Trace] comprised of [frames]. |
| 65 Trace(Iterable<Frame> frames) | 87 Trace(Iterable<Frame> frames) |
| 66 : frames = new UnmodifiableListView<Frame>(frames.toList()); | 88 : frames = new UnmodifiableListView<Frame>(frames.toList()); |
| 67 | 89 |
| 68 // TODO(nweiz): Keep track of which [Frame]s are part of the partial stack | 90 // TODO(nweiz): Keep track of which [Frame]s are part of the partial stack |
| 69 // trace and only print them. | 91 // trace and only print them. |
| 70 /// Returns a string representation of this stack trace. | 92 /// Returns a string representation of this stack trace. |
| 71 /// | 93 /// |
| 72 /// This is identical to [toString]. It will not be formatted in the manner of | 94 /// 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 Loading... | |
| 133 if (string.length >= length) return string; | 155 if (string.length >= length) return string; |
| 134 | 156 |
| 135 var result = new StringBuffer(); | 157 var result = new StringBuffer(); |
| 136 result.write(string); | 158 result.write(string); |
| 137 for (var i = 0; i < length - string.length; i++) { | 159 for (var i = 0; i < length - string.length; i++) { |
| 138 result.write(' '); | 160 result.write(' '); |
| 139 } | 161 } |
| 140 | 162 |
| 141 return result.toString(); | 163 return result.toString(); |
| 142 } | 164 } |
| OLD | NEW |