| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of dart2js.helpers; | 5 part of dart2js.helpers; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Helper method for printing stack traces for debugging. | 8 * Helper method for printing stack traces for debugging. |
| 9 * | 9 * |
| 10 * [message] is printed as the header of the stack trace. | 10 * [message] is printed as the header of the stack trace. |
| 11 * | 11 * |
| 12 * If [condition] is provided, the stack trace is only printed if [condition] | 12 * If [condition] is provided, the stack trace is only printed if [condition] |
| 13 * returns [:true:] on the stack trace text. This can be used to filter the | 13 * returns [:true:] on the stack trace text. This can be used to filter the |
| 14 * printed stack traces based on their content. For instance only print stack | 14 * printed stack traces based on their content. For instance only print stack |
| 15 * traces that contain specific paths. | 15 * traces that contain specific paths. |
| 16 */ | 16 */ |
| 17 void trace(String message, [bool condition(String stackTrace)]) { | 17 void trace(String message, {bool condition(String stackTrace), int limit}) { |
| 18 try { | 18 try { |
| 19 throw ''; | 19 throw ''; |
| 20 } catch (e, s) { | 20 } catch (e, s) { |
| 21 String stackTrace = prettifyStackTrace( | 21 String stackTrace = prettifyStackTrace( |
| 22 s, rangeStart: 1, filePrefix: stackTraceFilePrefix); | 22 s, rangeStart: 1, rangeEnd: limit, filePrefix: stackTraceFilePrefix); |
| 23 if (condition != null) { | 23 if (condition != null) { |
| 24 if (!condition(stackTrace)) return; | 24 if (!condition(stackTrace)) return; |
| 25 } | 25 } |
| 26 print('$message\n$stackTrace'); | 26 print('$message\n$stackTrace'); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 void traceAndReport(Compiler compiler, Spannable node, | 30 void traceAndReport(Compiler compiler, Spannable node, String message, |
| 31 String message, [bool condition(String stackTrace)]) { | 31 {bool condition(String stackTrace), int limit}) { |
| 32 | 32 |
| 33 trace(message, (String stackTrace) { | 33 trace(message, condition: (String stackTrace) { |
| 34 bool result = condition != null ? condition(stackTrace) : true; | 34 bool result = condition != null ? condition(stackTrace) : true; |
| 35 if (result) { | 35 if (result) { |
| 36 reportHere(compiler, node, message); | 36 reportHere(compiler, node, message); |
| 37 } | 37 } |
| 38 return result; | 38 return result; |
| 39 }); | 39 }); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /// Helper class for the processing of stack traces in [prettifyStackTrace]. | 42 /// Helper class for the processing of stack traces in [prettifyStackTrace]. |
| 43 class _StackTraceLine { | 43 class _StackTraceLine { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 178 } |
| 179 for (int index = text.length ; index < intendedLength ; index ++) { | 179 for (int index = text.length ; index < intendedLength ; index ++) { |
| 180 int dotsIndex = index % dotsLength; | 180 int dotsIndex = index % dotsLength; |
| 181 sb.write(dots.substring(dotsIndex, dotsIndex + 1)); | 181 sb.write(dots.substring(dotsIndex, dotsIndex + 1)); |
| 182 } | 182 } |
| 183 if (padLeft) { | 183 if (padLeft) { |
| 184 sb.write(text); | 184 sb.write(text); |
| 185 } | 185 } |
| 186 return sb.toString(); | 186 return sb.toString(); |
| 187 } | 187 } |
| OLD | NEW |