| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class ListFactory<E> { | 5 class ListFactory<E> { |
| 6 factory List.from(Iterable<E> other) { | 6 factory List.from(Iterable<E> other) { |
| 7 if (other == null) { | 7 if (other == null) { |
| 8 throw const NullPointerException(); | 8 throw const NullPointerException(); |
| 9 } | 9 } |
| 10 List<E> list = new List<E>(); | 10 List<E> list = new List<E>(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 | 36 |
| 37 class ListImplementation<T> implements List<T> native "Array" { | 37 class ListImplementation<T> implements List<T> native "Array" { |
| 38 // ListImplementation maps directly to a JavaScript array. If the list is | 38 // ListImplementation maps directly to a JavaScript array. If the list is |
| 39 // constructed by the ListFactory.List constructor, it has an | 39 // constructed by the ListFactory.List constructor, it has an |
| 40 // additional named property for '_isFixed'. If it is a literal, the | 40 // additional named property for '_isFixed'. If it is a literal, the |
| 41 // code generator will not add the property. It will be 'undefined' | 41 // code generator will not add the property. It will be 'undefined' |
| 42 // and coerce to false. | 42 // and coerce to false. |
| 43 bool _isFixed; | 43 bool _isFixed; |
| 44 | 44 |
| 45 T operator[](int index) { | 45 T operator[](int index) native; |
| 46 if (0 <= index && index < length) { | 46 void operator[]=(int index, T value) native; |
| 47 return _indexOperator(index); | |
| 48 } | |
| 49 throw new IndexOutOfRangeException(index); | |
| 50 } | |
| 51 | |
| 52 void operator[]=(int index, T value) { | |
| 53 if (index < 0 || length <= index) { | |
| 54 throw new IndexOutOfRangeException(index); | |
| 55 } | |
| 56 _indexAssignOperator(index, value); | |
| 57 } | |
| 58 | 47 |
| 59 Iterator<T> iterator() { | 48 Iterator<T> iterator() { |
| 60 if (_isFixed) { | 49 if (_isFixed) { |
| 61 return new FixedSizeListIterator<T>(this); | 50 return new FixedSizeListIterator<T>(this); |
| 62 } else { | 51 } else { |
| 63 return new VariableSizeListIterator<T>(this); | 52 return new VariableSizeListIterator<T>(this); |
| 64 } | 53 } |
| 65 } | 54 } |
| 66 | 55 |
| 67 T _indexOperator(int index) native; | |
| 68 void _indexAssignOperator(int index, T value) native; | |
| 69 int get length() native; | 56 int get length() native; |
| 70 void _setLength(int length) native; | 57 void _setLength(int length) native; |
| 71 void _add(T value) native; | 58 void _add(T value) native; |
| 72 void _removeRange(int start, int length) native; | 59 void _removeRange(int start, int length) native; |
| 73 void _insertRange(int start, int length, T initialValue) native; | 60 void _insertRange(int start, int length, T initialValue) native; |
| 74 | 61 |
| 75 void forEach(void f(T element)) { | 62 void forEach(void f(T element)) { |
| 76 Collections.forEach(this, f); | 63 Collections.forEach(this, f); |
| 77 } | 64 } |
| 78 | 65 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 256 } |
| 270 | 257 |
| 271 static List _newList(int len) native { | 258 static List _newList(int len) native { |
| 272 return new List(len); | 259 return new List(len); |
| 273 } | 260 } |
| 274 | 261 |
| 275 static void _throwIndexOutOfRangeException(int index) native { | 262 static void _throwIndexOutOfRangeException(int index) native { |
| 276 throw new IndexOutOfRangeException(index); | 263 throw new IndexOutOfRangeException(index); |
| 277 } | 264 } |
| 278 } | 265 } |
| OLD | NEW |