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

Side by Side Diff: sdk/lib/_internal/lib/js_array.dart

Issue 18837002: Move toString() to collection classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 _interceptors; 5 part of _interceptors;
6 6
7 /** 7 /**
8 * The interceptor class for [List]. The compiler recognizes this 8 * The interceptor class for [List]. The compiler recognizes this
9 * class as an interceptor, and changes references to [:this:] to 9 * class as an interceptor, and changes references to [:this:] to
10 * actually use the receiver of the method, which is generated as an extra 10 * actually use the receiver of the method, which is generated as an extra
11 * argument added to each member. 11 * argument added to each member.
12 */ 12 */
13 class JSArray<E> extends Interceptor implements List<E>, JSIndexable { 13 class JSArray<E> extends Interceptor implements List<E>, JSIndexable {
14
15 static List _toStringList = new List();
16
14 const JSArray(); 17 const JSArray();
15 18
16 checkMutable(reason) { 19 checkMutable(reason) {
17 if (this is !JSMutableArray) { 20 if (this is !JSMutableArray) {
18 throw new UnsupportedError(reason); 21 throw new UnsupportedError(reason);
19 } 22 }
20 } 23 }
21 24
22 checkGrowable(reason) { 25 checkGrowable(reason) {
23 if (this is !JSExtendableArray) { 26 if (this is !JSExtendableArray) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 for (int i = 0; i < length; i++) { 257 for (int i = 0; i < length; i++) {
255 if (this[i] == other) return true; 258 if (this[i] == other) return true;
256 } 259 }
257 return false; 260 return false;
258 } 261 }
259 262
260 bool get isEmpty => length == 0; 263 bool get isEmpty => length == 0;
261 264
262 bool get isNotEmpty => !isEmpty; 265 bool get isNotEmpty => !isEmpty;
263 266
264 String toString() => ToString.iterableToString(this); 267 String toString() {
floitsch 2013/07/08 12:00:50 change to IterableMixinWorkaround.toStringList(thi
zarah 2013/07/08 14:35:15 Done.
265 268 for(int i = 0; i < _toStringList.length; i++) {
269 if(identical(_toStringList[i], this))
270 return '[...]';
271 }
272 _toStringList.add(this);
273 String result = IterableMixinWorkaround.toStringList(this);
274 _toStringList.remove(this);
275 return result;
276 }
277
266 List<E> toList({ bool growable: true }) => 278 List<E> toList({ bool growable: true }) =>
267 new List<E>.from(this, growable: growable); 279 new List<E>.from(this, growable: growable);
268 280
269 Set<E> toSet() => new Set<E>.from(this); 281 Set<E> toSet() => new Set<E>.from(this);
270 282
271 Iterator<E> get iterator => new ListIterator<E>(this); 283 Iterator<E> get iterator => new ListIterator<E>(this);
272 284
273 int get hashCode => Primitives.objectHashCode(this); 285 int get hashCode => Primitives.objectHashCode(this);
274 286
275 int get length => JS('int', r'#.length', this); 287 int get length => JS('int', r'#.length', this);
(...skipping 24 matching lines...) Expand all
300 } 312 }
301 313
302 /** 314 /**
303 * Dummy subclasses that allow the backend to track more precise 315 * Dummy subclasses that allow the backend to track more precise
304 * information about arrays through their type. The CPA type inference 316 * information about arrays through their type. The CPA type inference
305 * relies on the fact that these classes do not override [] nor []=. 317 * relies on the fact that these classes do not override [] nor []=.
306 */ 318 */
307 class JSMutableArray extends JSArray implements JSMutableIndexable {} 319 class JSMutableArray extends JSArray implements JSMutableIndexable {}
308 class JSFixedArray extends JSMutableArray {} 320 class JSFixedArray extends JSMutableArray {}
309 class JSExtendableArray extends JSMutableArray {} 321 class JSExtendableArray extends JSMutableArray {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698