Index: sdk/lib/collection/list.dart |
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart |
index 7669a70a5bba94806fb18257b019807330157ae4..b6e1a11b66e2882ebfc6701a9ecaf54787d7a460 100644 |
--- a/sdk/lib/collection/list.dart |
+++ b/sdk/lib/collection/list.dart |
@@ -4,9 +4,6 @@ |
part of dart.collection; |
-/** A reusable set used to identify cyclic lists during toString() calls. */ |
-Set _toStringVisiting = new HashSet.identity(); |
- |
/** |
* Abstract implementation of a list. |
* |
@@ -22,7 +19,16 @@ Set _toStringVisiting = new HashSet.identity(); |
* to the growable list, or, preferably, use `DelegatingList` from |
* "package:collection/wrappers.dart" instead. |
*/ |
-abstract class ListBase<E> = Object with ListMixin<E>; |
+abstract class ListBase<E> extends Object with ListMixin<E> { |
+ /** |
+ * Convert a `List` to a string as `[each, element, as, string]`. |
+ * |
+ * Handles circular references where converting one of the elements |
+ * to a string ends up converting [list] to a string again. |
+ */ |
+ static String listToString(List list) => |
+ IterableBase.iterableToFullString(list, '[', ']'); |
+} |
/** |
* Base implementation of a [List] class. |
@@ -501,21 +507,5 @@ abstract class ListMixin<E> implements List<E> { |
Iterable<E> get reversed => new ReversedListIterable(this); |
- String toString() { |
- if (_toStringVisiting.contains(this)) { |
- return '[...]'; |
- } |
- |
- var result = new StringBuffer(); |
- try { |
- _toStringVisiting.add(this); |
- result.write('['); |
- result.writeAll(this, ', '); |
- result.write(']'); |
- } finally { |
- _toStringVisiting.remove(this); |
- } |
- |
- return result.toString(); |
- } |
+ String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
} |