Chromium Code Reviews| 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 /// Library for debugging helpers. The unittest analyze_unused_test checks that | 5 /// Library for debugging helpers. The unittest analyze_unused_test checks that |
| 6 /// the helper are not used in production code. | 6 /// the helper are not used in production code. |
| 7 | 7 |
| 8 library dart2js.helpers; | 8 library dart2js.helpers; |
| 9 | 9 |
| 10 import 'dart:async' show EventSink; | 10 import 'dart:async' show EventSink; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 ReportHere get reportHere { | 86 ReportHere get reportHere { |
| 87 enableDebugMode(); | 87 enableDebugMode(); |
| 88 return _reportHere; | 88 return _reportHere; |
| 89 } | 89 } |
| 90 | 90 |
| 91 /// Implementation of [reportHere] | 91 /// Implementation of [reportHere] |
| 92 _reportHere(Compiler compiler, Spannable node, String debugMessage) { | 92 _reportHere(Compiler compiler, Spannable node, String debugMessage) { |
| 93 compiler.reportInfo(node, | 93 compiler.reportInfo(node, |
| 94 MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); | 94 MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); |
| 95 } | 95 } |
| 96 | |
| 97 /// Set of tracked objects used by [track] and [ifTracked]. | |
|
karlklose
2015/07/10 12:44:40
Maybe this change should be in its own CL.
Johnni Winther
2015/07/10 13:26:38
Maybe. It was used to create this CL.
| |
| 98 var _trackedObjects = new Set(); | |
| 99 | |
| 100 /// Global default value for the `printTrace` option of [track] and [ifTracked]. | |
| 101 bool trackWithTrace = false; | |
| 102 | |
| 103 /// If [doTrack] is `true`, add [object] to the set of tracked objects. | |
| 104 /// | |
| 105 /// If tracked, [message] is printed along the hash code and toString of [object ]. | |
|
karlklose
2015/07/10 12:44:40
Long line.
Johnni Winther
2015/07/10 13:26:38
Done.
| |
| 106 /// If [printTrace] is `true` a trace printed additionally. If [printTrace] is | |
| 107 /// `null`, [trackWithTrace] determines whether a trace is printed. | |
| 108 /// | |
| 109 /// [object] is returned as the result of the method. | |
| 110 track(bool doTrack, Object object, String message, {bool printTrace}) { | |
| 111 if (!doTrack) return object; | |
| 112 _trackedObjects.add(object); | |
| 113 String msg = 'track: ${object.hashCode}:$object:$message'; | |
| 114 if (printTrace == null) printTrace = trackWithTrace; | |
| 115 if (printTrace) { | |
| 116 trace(msg); | |
| 117 } else { | |
| 118 debugPrint(msg); | |
| 119 } | |
| 120 return object; | |
| 121 } | |
| 122 | |
| 123 /// Returns `true` if [object] is in the set of tracked objects. | |
| 124 /// | |
| 125 /// If [message] is provided it is printed along the hash code and toString of | |
| 126 /// [object]. If [printTrace] is `true` a trace printed additionally. If | |
| 127 /// [printTrace] is `null`, [trackWithTrace] determines whether a trace is | |
| 128 /// printed. | |
| 129 bool ifTracked(Object object, {String message, bool printTrace}) { | |
| 130 if (_trackedObjects.contains(object)) { | |
| 131 if (message != null) { | |
| 132 String msg = 'tracked: ${object.hashCode}:$object:$message'; | |
| 133 if (printTrace == null) printTrace = trackWithTrace; | |
| 134 if (printTrace) { | |
| 135 trace(msg); | |
| 136 } else { | |
| 137 debugPrint(msg); | |
| 138 } | |
| 139 } | |
| 140 return true; | |
| 141 } | |
| 142 return false; | |
| 143 } | |
| OLD | NEW |