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 /// Function signature for [trace]. | 7 /// Function signature for [trace]. |
8 typedef void Trace(String message, | 8 typedef void Trace(String message, |
9 {bool condition(String stackTrace), | 9 {bool condition(String stackTrace), |
10 int limit, | 10 int limit, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 /// Creates a function to use as an `condition` argument in [trace] that filters | 56 /// Creates a function to use as an `condition` argument in [trace] that filters |
57 /// stack traces that contains any of the [exceptions]. | 57 /// stack traces that contains any of the [exceptions]. |
58 traceExceptions(List<String> exceptions) { | 58 traceExceptions(List<String> exceptions) { |
59 return (String stackTrace) => !exceptions.any(stackTrace.contains); | 59 return (String stackTrace) => !exceptions.any(stackTrace.contains); |
60 } | 60 } |
61 | 61 |
62 /// Function signature of [traceAndReport]. | 62 /// Function signature of [traceAndReport]. |
63 typedef void TraceAndReport(Compiler compiler, Spannable node, String message, | 63 typedef void TraceAndReport(DiagnosticReporter reporter, |
64 {bool condition(String stackTrace), int limit, | 64 Spannable node, |
| 65 String message, |
| 66 {bool condition(String stackTrace), |
| 67 int limit, |
65 bool throwOnPrint}); | 68 bool throwOnPrint}); |
66 | 69 |
67 /// Calls [reportHere] and [trace] with the same message. | 70 /// Calls [reportHere] and [trace] with the same message. |
68 TraceAndReport get traceAndReport { | 71 TraceAndReport get traceAndReport { |
69 enableDebugMode(); | 72 enableDebugMode(); |
70 return _traceAndReport; | 73 return _traceAndReport; |
71 } | 74 } |
72 | 75 |
73 /// Calls [reportHere] and [trace] with the same message. | 76 /// Calls [reportHere] and [trace] with the same message. |
74 TraceAndReport get reportAndTrace => traceAndReport; | 77 TraceAndReport get reportAndTrace => traceAndReport; |
75 | 78 |
76 /// Implementation of [traceAndReport]. | 79 /// Implementation of [traceAndReport]. |
77 void _traceAndReport(Compiler compiler, Spannable node, String message, | 80 void _traceAndReport(DiagnosticReporter reporter, |
| 81 Spannable node, |
| 82 String message, |
78 {bool condition(String stackTrace), int limit, | 83 {bool condition(String stackTrace), int limit, |
79 bool throwOnPrint: false}) { | 84 bool throwOnPrint: false}) { |
80 | 85 |
81 trace(message, limit: limit, throwOnPrint: throwOnPrint, | 86 trace(message, limit: limit, throwOnPrint: throwOnPrint, |
82 condition: (String stackTrace) { | 87 condition: (String stackTrace) { |
83 bool result = condition != null ? condition(stackTrace) : true; | 88 bool result = condition != null ? condition(stackTrace) : true; |
84 if (result) { | 89 if (result) { |
85 reportHere(compiler, node, message); | 90 reportHere(reporter, node, message); |
86 } | 91 } |
87 return result; | 92 return result; |
88 }); | 93 }); |
89 } | 94 } |
90 | 95 |
91 /// Returns the [StackTraceLines] for the current call stack. | 96 /// Returns the [StackTraceLines] for the current call stack. |
92 /// | 97 /// |
93 /// Use [offset] to discard the first [offset] calls of the call stack. Defaults | 98 /// Use [offset] to discard the first [offset] calls of the call stack. Defaults |
94 /// to `1`, that is, discard the call to [stackTrace] itself. Use [limit] to | 99 /// to `1`, that is, discard the call to [stackTrace] itself. Use [limit] to |
95 /// limit the length of the stack trace lines. | 100 /// limit the length of the stack trace lines. |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 353 } |
349 for (int index = text.length ; index < intendedLength ; index ++) { | 354 for (int index = text.length ; index < intendedLength ; index ++) { |
350 int dotsIndex = index % dotsLength; | 355 int dotsIndex = index % dotsLength; |
351 sb.write(dots.substring(dotsIndex, dotsIndex + 1)); | 356 sb.write(dots.substring(dotsIndex, dotsIndex + 1)); |
352 } | 357 } |
353 if (padLeft) { | 358 if (padLeft) { |
354 sb.write(text); | 359 sb.write(text); |
355 } | 360 } |
356 return sb.toString(); | 361 return sb.toString(); |
357 } | 362 } |
OLD | NEW |