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:uri'; | 7 import 'dart:uri'; |
| 8 import 'dart:math'; | |
|
nweiz
2013/04/12 19:47:33
Please import dart:math with a prefix. It has a lo
floitsch
2013/04/13 13:15:51
done in https://codereview.chromium.org/14111004
| |
| 8 | 9 |
| 9 import 'frame.dart'; | 10 import 'frame.dart'; |
| 10 | 11 |
| 11 final _patchRegExp = new RegExp(r"-patch$"); | 12 final _patchRegExp = new RegExp(r"-patch$"); |
| 12 | 13 |
| 13 /// A stack trace, comprised of a list of stack frames. | 14 /// A stack trace, comprised of a list of stack frames. |
| 14 class Trace implements StackTrace { | 15 class Trace implements StackTrace { |
| 15 // TODO(nweiz): make this read-only once issue 8321 is fixed. | 16 // TODO(nweiz): make this read-only once issue 8321 is fixed. |
| 16 /// The stack frames that comprise this stack trace. | 17 /// The stack frames that comprise this stack trace. |
| 17 final List<Frame> frames; | 18 final List<Frame> frames; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 } | 110 } |
| 110 | 111 |
| 111 return new Trace(newFrames.reversed); | 112 return new Trace(newFrames.reversed); |
| 112 } | 113 } |
| 113 | 114 |
| 114 /// Returns a human-readable string representation of [this]. | 115 /// Returns a human-readable string representation of [this]. |
| 115 String toString() { | 116 String toString() { |
| 116 if (frames.length == '') return ''; | 117 if (frames.length == '') return ''; |
| 117 | 118 |
| 118 // Figure out the longest path so we know how much to pad. | 119 // Figure out the longest path so we know how much to pad. |
| 119 var longest = frames.map((frame) => frame.location.length).max(); | 120 var longest = frames.map((frame) => frame.location.length).reduce(max); |
| 120 | 121 |
| 121 // Print out the stack trace nicely formatted. | 122 // Print out the stack trace nicely formatted. |
| 122 return frames.map((frame) { | 123 return frames.map((frame) { |
| 123 return '${_padRight(frame.location, longest)} ${frame.member}\n'; | 124 return '${_padRight(frame.location, longest)} ${frame.member}\n'; |
| 124 }).join(); | 125 }).join(); |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 /// Returns [string] with enough spaces added to the end to make it [length] | 129 /// Returns [string] with enough spaces added to the end to make it [length] |
| 129 /// characters long. | 130 /// characters long. |
| 130 String _padRight(String string, int length) { | 131 String _padRight(String string, int length) { |
| 131 if (string.length >= length) return string; | 132 if (string.length >= length) return string; |
| 132 | 133 |
| 133 var result = new StringBuffer(); | 134 var result = new StringBuffer(); |
| 134 result.write(string); | 135 result.write(string); |
| 135 for (var i = 0; i < length - string.length; i++) { | 136 for (var i = 0; i < length - string.length; i++) { |
| 136 result.write(' '); | 137 result.write(' '); |
| 137 } | 138 } |
| 138 | 139 |
| 139 return result.toString(); | 140 return result.toString(); |
| 140 } | 141 } |
| OLD | NEW |