| OLD | NEW |
| 1 // -- start List<$E> mixins. | 1 // -- start List<$E> mixins. |
| 2 // $E is the element type. | 2 // $E is the element type. |
| 3 | 3 |
| 4 $if DEFINE_LENGTH_AS_NUM_ITEMS | 4 $if DEFINE_LENGTH_AS_NUM_ITEMS |
| 5 // SVG Collections expose numberOfItems rather than length. | 5 // SVG Collections expose numberOfItems rather than length. |
| 6 int get length => numberOfItems; | 6 int get length => numberOfItems; |
| 7 $endif | 7 $endif |
| 8 | 8 |
| 9 $if DEFINE_LENGTH_SETTER | 9 $if DEFINE_LENGTH_SETTER |
| 10 set length(int value) { | 10 set length(int value) { |
| 11 throw new UnsupportedError("Cannot resize immutable List."); | 11 throw new UnsupportedError("Cannot resize immutable List."); |
| 12 } | 12 } |
| 13 $endif | 13 $endif |
| 14 | 14 |
| 15 $E get first { | 15 $E get first { |
| 16 if (this.length > 0) { | 16 if (this.length > 0) { |
| 17 $if DART2JS | |
| 18 return JS('$EJS', '#[0]', this); | 17 return JS('$EJS', '#[0]', this); |
| 19 $else | |
| 20 $if USE_NATIVE_INDEXED_GETTER | 18 $if USE_NATIVE_INDEXED_GETTER |
| 21 return $GETTER(0); | 19 return $GETTER(0); |
| 22 $else | 20 $else |
| 23 return this[0]; | 21 return this[0]; |
| 24 $endif | 22 $endif |
| 25 $endif | |
| 26 } | 23 } |
| 27 throw new StateError("No elements"); | 24 throw new StateError("No elements"); |
| 28 } | 25 } |
| 29 | 26 |
| 30 $E get last { | 27 $E get last { |
| 31 int len = this.length; | 28 int len = this.length; |
| 32 if (len > 0) { | 29 if (len > 0) { |
| 33 $if DART2JS | |
| 34 return JS('$EJS', '#[#]', this, len - 1); | 30 return JS('$EJS', '#[#]', this, len - 1); |
| 35 $else | |
| 36 $if USE_NATIVE_INDEXED_GETTER | 31 $if USE_NATIVE_INDEXED_GETTER |
| 37 return $GETTER(len - 1); | 32 return $GETTER(len - 1); |
| 38 $else | 33 $else |
| 39 return this[len - 1]; | 34 return this[len - 1]; |
| 40 $endif | 35 $endif |
| 41 $endif | |
| 42 } | 36 } |
| 43 throw new StateError("No elements"); | 37 throw new StateError("No elements"); |
| 44 } | 38 } |
| 45 | 39 |
| 46 $E get single { | 40 $E get single { |
| 47 int len = this.length; | 41 int len = this.length; |
| 48 if (len == 1) { | 42 if (len == 1) { |
| 49 $if DART2JS | |
| 50 return JS('$EJS', '#[0]', this); | 43 return JS('$EJS', '#[0]', this); |
| 51 $else | |
| 52 $if USE_NATIVE_INDEXED_GETTER | 44 $if USE_NATIVE_INDEXED_GETTER |
| 53 return $GETTER(0); | 45 return $GETTER(0); |
| 54 $else | 46 $else |
| 55 return this[0]; | 47 return this[0]; |
| 56 $endif | 48 $endif |
| 57 $endif | |
| 58 } | 49 } |
| 59 if (len == 0) throw new StateError("No elements"); | 50 if (len == 0) throw new StateError("No elements"); |
| 60 throw new StateError("More than one element"); | 51 throw new StateError("More than one element"); |
| 61 } | 52 } |
| 62 | 53 |
| 63 $E elementAt(int index) => this[index]; | 54 $E elementAt(int index) => this[index]; |
| 64 // -- end List<$E> mixins. | 55 // -- end List<$E> mixins. |
| OLD | NEW |