Chromium Code Reviews| Index: tools/dom/templates/immutable_list_mixin.darttemplate |
| diff --git a/tools/dom/templates/immutable_list_mixin.darttemplate b/tools/dom/templates/immutable_list_mixin.darttemplate |
| index e9bffe58e4524018b0aefc00e13bd149a0d22d17..7e2d68d035145748f5d4e109929207441ba76ad2 100644 |
| --- a/tools/dom/templates/immutable_list_mixin.darttemplate |
| +++ b/tools/dom/templates/immutable_list_mixin.darttemplate |
| @@ -12,4 +12,44 @@ $if DEFINE_LENGTH_SETTER |
| } |
| $endif |
| + $E get first { |
| + if (this.length > 0) { |
| +$if DART2JS |
| + return JS('$E', '#[0]', this); |
| +$else |
| + return this[0]; |
| +$endif |
| + } |
| + throw new StateError("No elements"); |
| + } |
| + |
| + $E get last { |
| + int len = this.length; |
| + if (len > 0) { |
| +$if DART2JS |
| + return JS('$E', '#[#]', this, len - 1); |
| +$else |
| + return this[len - 1]; |
| +$endif |
| + } |
| + throw new StateError("No elements"); |
| + } |
| + |
| + $E get single { |
| + int len = this.length; |
| + if (len == 1) { |
| +$if DART2JS |
| + return JS('$E', '#[0]', this); |
| +$else |
| + return this[0]; |
| +$endif |
| + } |
| + if (len == 0) throw new StateError("No elements"); |
| + throw new StateError("More than one element"); |
| + } |
| + |
| + $E elementAt(int index) { |
|
sra1
2013/05/09 19:55:50
nit: could be =>
|
| + return this[index]; |
| + } |
| + |
| // -- end List<$E> mixins. |