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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 return JS('var', '#[#]', this, index); | 357 return JS('var', '#[#]', this, index); |
358 } | 358 } |
359 | 359 |
360 void operator []=(int index, E value) { | 360 void operator []=(int index, E value) { |
361 checkMutable('indexed set'); | 361 checkMutable('indexed set'); |
362 if (index is !int) throw new ArgumentError(index); | 362 if (index is !int) throw new ArgumentError(index); |
363 if (index >= length || index < 0) throw new RangeError.value(index); | 363 if (index >= length || index < 0) throw new RangeError.value(index); |
364 JS('void', r'#[#] = #', this, index, value); | 364 JS('void', r'#[#] = #', this, index, value); |
365 } | 365 } |
366 | 366 |
367 void set last(E value) { | |
368 checkMutable('indexed set'); | |
369 if (length == 0) throw IterableElementError.noElement(); | |
370 JS('void', r'#[#] = #', this, this.length - 1, value); | |
371 } | |
372 | |
373 Map<int, E> asMap() { | 367 Map<int, E> asMap() { |
374 return IterableMixinWorkaround.asMapList(this); | 368 return IterableMixinWorkaround.asMapList(this); |
375 } | 369 } |
376 } | 370 } |
377 | 371 |
378 /** | 372 /** |
379 * Dummy subclasses that allow the backend to track more precise | 373 * Dummy subclasses that allow the backend to track more precise |
380 * information about arrays through their type. The CPA type inference | 374 * information about arrays through their type. The CPA type inference |
381 * relies on the fact that these classes do not override [] nor []=. | 375 * relies on the fact that these classes do not override [] nor []=. |
382 */ | 376 */ |
383 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} | 377 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} |
384 class JSFixedArray<E> extends JSMutableArray<E> {} | 378 class JSFixedArray<E> extends JSMutableArray<E> {} |
385 class JSExtendableArray<E> extends JSMutableArray<E> {} | 379 class JSExtendableArray<E> extends JSMutableArray<E> {} |
OLD | NEW |