Chromium Code Reviews| Index: pkg/compiler/lib/src/helpers/helpers.dart |
| diff --git a/pkg/compiler/lib/src/helpers/helpers.dart b/pkg/compiler/lib/src/helpers/helpers.dart |
| index bcfa12c9b5ff6b0d3ce3f92cb1f66d4ddd3bbc8d..886739f78f7399c9904bda2473b47e9f3fa4ec49 100644 |
| --- a/pkg/compiler/lib/src/helpers/helpers.dart |
| +++ b/pkg/compiler/lib/src/helpers/helpers.dart |
| @@ -93,3 +93,51 @@ _reportHere(Compiler compiler, Spannable node, String debugMessage) { |
| compiler.reportInfo(node, |
| MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); |
| } |
| + |
| +/// 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.
|
| +var _trackedObjects = new Set(); |
| + |
| +/// Global default value for the `printTrace` option of [track] and [ifTracked]. |
| +bool trackWithTrace = false; |
| + |
| +/// If [doTrack] is `true`, add [object] to the set of tracked objects. |
| +/// |
| +/// 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.
|
| +/// If [printTrace] is `true` a trace printed additionally. If [printTrace] is |
| +/// `null`, [trackWithTrace] determines whether a trace is printed. |
| +/// |
| +/// [object] is returned as the result of the method. |
| +track(bool doTrack, Object object, String message, {bool printTrace}) { |
| + if (!doTrack) return object; |
| + _trackedObjects.add(object); |
| + String msg = 'track: ${object.hashCode}:$object:$message'; |
| + if (printTrace == null) printTrace = trackWithTrace; |
| + if (printTrace) { |
| + trace(msg); |
| + } else { |
| + debugPrint(msg); |
| + } |
| + return object; |
| +} |
| + |
| +/// Returns `true` if [object] is in the set of tracked objects. |
| +/// |
| +/// If [message] is provided it is printed along the hash code and toString of |
| +/// [object]. If [printTrace] is `true` a trace printed additionally. If |
| +/// [printTrace] is `null`, [trackWithTrace] determines whether a trace is |
| +/// printed. |
| +bool ifTracked(Object object, {String message, bool printTrace}) { |
| + if (_trackedObjects.contains(object)) { |
| + if (message != null) { |
| + String msg = 'tracked: ${object.hashCode}:$object:$message'; |
| + if (printTrace == null) printTrace = trackWithTrace; |
| + if (printTrace) { |
| + trace(msg); |
| + } else { |
| + debugPrint(msg); |
| + } |
| + } |
| + return true; |
| + } |
| + return false; |
| +} |