| 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 _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 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 JS('void', r'#.fixed$length = Array', list); | 76 JS('void', r'#.fixed$length = Array', list); |
| 77 return JS('JSFixedArray', '#', list); | 77 return JS('JSFixedArray', '#', list); |
| 78 } | 78 } |
| 79 | 79 |
| 80 static List markUnmodifiableList(List list) { | 80 static List markUnmodifiableList(List list) { |
| 81 // Functions are stored in the hidden class and not as properties in | 81 // Functions are stored in the hidden class and not as properties in |
| 82 // the object. We never actually look at the value, but only want | 82 // the object. We never actually look at the value, but only want |
| 83 // to know if the property exists. | 83 // to know if the property exists. |
| 84 JS('void', r'#.fixed$length = Array', list); | 84 JS('void', r'#.fixed$length = Array', list); |
| 85 JS('void', r'#.immutable$list = Array', list); | 85 JS('void', r'#.immutable$list = Array', list); |
| 86 // TODO(23309): Make it detectable that the list has fixed length. | 86 return JS('JSUnmodifiableArray', '#', list); |
| 87 return JS('JSArray', '#', list); | |
| 88 } | 87 } |
| 89 | 88 |
| 90 checkMutable(reason) { | 89 checkMutable(reason) { |
| 91 if (this is !JSMutableArray) { | 90 if (this is !JSMutableArray) { |
| 92 throw new UnsupportedError(reason); | 91 throw new UnsupportedError(reason); |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 | 94 |
| 96 checkGrowable(reason) { | 95 checkGrowable(reason) { |
| 97 if (this is !JSExtendableArray) { | 96 if (this is !JSExtendableArray) { |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 * | 605 * |
| 607 * These classes are really a fiction, and can have no methods, since | 606 * These classes are really a fiction, and can have no methods, since |
| 608 * getInterceptor always returns JSArray. We should consider pushing the | 607 * getInterceptor always returns JSArray. We should consider pushing the |
| 609 * 'isGrowable' and 'isMutable' checks into the getInterceptor implementation so | 608 * 'isGrowable' and 'isMutable' checks into the getInterceptor implementation so |
| 610 * these classes can have specialized implementations. Doing so will challenge | 609 * these classes can have specialized implementations. Doing so will challenge |
| 611 * many assuptions in the JS backend. | 610 * many assuptions in the JS backend. |
| 612 */ | 611 */ |
| 613 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} | 612 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} |
| 614 class JSFixedArray<E> extends JSMutableArray<E> {} | 613 class JSFixedArray<E> extends JSMutableArray<E> {} |
| 615 class JSExtendableArray<E> extends JSMutableArray<E> {} | 614 class JSExtendableArray<E> extends JSMutableArray<E> {} |
| 615 class JSUnmodifiableArray<E> extends JSArray<E> {} // Already is JSIndexable. |
| 616 | 616 |
| 617 | 617 |
| 618 /// An [Iterator] that iterates a JSArray. | 618 /// An [Iterator] that iterates a JSArray. |
| 619 /// | 619 /// |
| 620 class ArrayIterator<E> implements Iterator<E> { | 620 class ArrayIterator<E> implements Iterator<E> { |
| 621 final JSArray<E> _iterable; | 621 final JSArray<E> _iterable; |
| 622 final int _length; | 622 final int _length; |
| 623 int _index; | 623 int _index; |
| 624 E _current; | 624 E _current; |
| 625 | 625 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 640 | 640 |
| 641 if (_index >= length) { | 641 if (_index >= length) { |
| 642 _current = null; | 642 _current = null; |
| 643 return false; | 643 return false; |
| 644 } | 644 } |
| 645 _current = _iterable[_index]; | 645 _current = _iterable[_index]; |
| 646 _index++; | 646 _index++; |
| 647 return true; | 647 return true; |
| 648 } | 648 } |
| 649 } | 649 } |
| OLD | NEW |