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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/helpers/trace.dart

Issue 304153014: Remove element from DynamicType. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup Created 6 years, 6 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
OLDNEW
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 *
karlklose 2014/06/02 09:39:38 I prefer changes to the helpers in separate CLs.
17 * If [limit] is provided, the stack trace is limited to [limit] entries.
18 *
19 * If [throwOnPrint] is `true`, [message] will be thrown after the stack trace
20 * has been printed. Together with [condition] this can be used to discover
21 * unknown call-sites in tests by filtering known call-sites and throwning
22 * otherwise.
16 */ 23 */
17 void trace(String message, {bool condition(String stackTrace), int limit}) { 24 void trace(String message, {bool condition(String stackTrace), int limit,
25 bool throwOnPrint: false}) {
18 try { 26 try {
19 throw ''; 27 throw '';
20 } catch (e, s) { 28 } catch (e, s) {
21 String stackTrace = prettifyStackTrace( 29 String stackTrace = prettifyStackTrace(
22 s, rangeStart: 1, rangeEnd: limit, filePrefix: stackTraceFilePrefix); 30 s, rangeStart: 1, rangeEnd: limit, filePrefix: stackTraceFilePrefix);
23 if (condition != null) { 31 if (condition != null) {
24 if (!condition(stackTrace)) return; 32 if (!condition(stackTrace)) return;
25 } 33 }
26 print('$message\n$stackTrace'); 34 print('$message\n$stackTrace');
35 if (throwOnPrint) throw message;
27 } 36 }
28 } 37 }
29 38
30 void traceAndReport(Compiler compiler, Spannable node, String message, 39 void traceAndReport(Compiler compiler, Spannable node, String message,
31 {bool condition(String stackTrace), int limit}) { 40 {bool condition(String stackTrace), int limit,
41 bool throwOnPrint: false}) {
32 42
33 trace(message, condition: (String stackTrace) { 43 trace(message, limit: limit, throwOnPrint: throwOnPrint,
44 condition: (String stackTrace) {
34 bool result = condition != null ? condition(stackTrace) : true; 45 bool result = condition != null ? condition(stackTrace) : true;
35 if (result) { 46 if (result) {
36 reportHere(compiler, node, message); 47 reportHere(compiler, node, message);
37 } 48 }
38 return result; 49 return result;
39 }); 50 });
40 } 51 }
41 52
42 /// Helper class for the processing of stack traces in [prettifyStackTrace]. 53 /// Helper class for the processing of stack traces in [prettifyStackTrace].
43 class _StackTraceLine { 54 class _StackTraceLine {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 189 }
179 for (int index = text.length ; index < intendedLength ; index ++) { 190 for (int index = text.length ; index < intendedLength ; index ++) {
180 int dotsIndex = index % dotsLength; 191 int dotsIndex = index % dotsLength;
181 sb.write(dots.substring(dotsIndex, dotsIndex + 1)); 192 sb.write(dots.substring(dotsIndex, dotsIndex + 1));
182 } 193 }
183 if (padLeft) { 194 if (padLeft) {
184 sb.write(text); 195 sb.write(text);
185 } 196 }
186 return sb.toString(); 197 return sb.toString();
187 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698