OLD | NEW |
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 dart._interceptors; | 5 part of dart._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 @JsPeerInterface(name: 'Array') | 13 @JsPeerInterface(name: 'Array') |
14 class JSArray<E> implements List<E>, JSIndexable { | 14 class JSArray<E> implements List<E>, JSIndexable<E> { |
15 | 15 |
16 const JSArray(); | 16 const JSArray(); |
17 | 17 |
18 /** | 18 /** |
19 * Constructor for adding type parameters to an existing JavaScript Array. | 19 * Constructor for adding type parameters to an existing JavaScript Array. |
20 */ | 20 */ |
21 factory JSArray.typed(allocation) => | 21 factory JSArray.typed(allocation) => |
22 // TODO(jmesserly): skip this when E is dynamic and Object. | 22 // TODO(jmesserly): skip this when E is dynamic and Object. |
23 JS('-dynamic', 'dart.list(#, #)', allocation, E); | 23 JS('-dynamic', 'dart.list(#, #)', allocation, E); |
24 | 24 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 * Dummy subclasses that allow the backend to track more precise | 580 * Dummy subclasses that allow the backend to track more precise |
581 * information about arrays through their type. The CPA type inference | 581 * information about arrays through their type. The CPA type inference |
582 * relies on the fact that these classes do not override [] nor []=. | 582 * relies on the fact that these classes do not override [] nor []=. |
583 * | 583 * |
584 * These classes are really a fiction, and can have no methods, since | 584 * These classes are really a fiction, and can have no methods, since |
585 * getInterceptor always returns JSArray. We should consider pushing the | 585 * getInterceptor always returns JSArray. We should consider pushing the |
586 * 'isGrowable' and 'isMutable' checks into the getInterceptor implementation so | 586 * 'isGrowable' and 'isMutable' checks into the getInterceptor implementation so |
587 * these classes can have specialized implementations. Doing so will challenge | 587 * these classes can have specialized implementations. Doing so will challenge |
588 * many assuptions in the JS backend. | 588 * many assuptions in the JS backend. |
589 */ | 589 */ |
590 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} | 590 class JSMutableArray<E> extends JSArray<E> {} |
591 class JSFixedArray<E> extends JSMutableArray<E> {} | 591 class JSFixedArray<E> extends JSMutableArray<E> {} |
592 class JSExtendableArray<E> extends JSMutableArray<E> {} | 592 class JSExtendableArray<E> extends JSMutableArray<E> {} |
593 class JSUnmodifiableArray<E> extends JSArray<E> {} // Already is JSIndexable. | 593 class JSUnmodifiableArray<E> extends JSArray<E> {} // Already is JSIndexable. |
594 | 594 |
595 | 595 |
596 /// An [Iterator] that iterates a JSArray. | 596 /// An [Iterator] that iterates a JSArray. |
597 /// | 597 /// |
598 class ArrayIterator<E> implements Iterator<E> { | 598 class ArrayIterator<E> implements Iterator<E> { |
599 final JSArray<E> _iterable; | 599 final JSArray<E> _iterable; |
600 final int _length; | 600 final int _length; |
(...skipping 17 matching lines...) Expand all Loading... |
618 | 618 |
619 if (_index >= length) { | 619 if (_index >= length) { |
620 _current = null; | 620 _current = null; |
621 return false; | 621 return false; |
622 } | 622 } |
623 _current = _iterable[_index]; | 623 _current = _iterable[_index]; |
624 _index++; | 624 _index++; |
625 return true; | 625 return true; |
626 } | 626 } |
627 } | 627 } |
OLD | NEW |