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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 Set<E> toSet() => new Set<E>.from(this); | 568 Set<E> toSet() => new Set<E>.from(this); |
569 | 569 |
570 Iterator<E> get iterator => new ArrayIterator<E>(this); | 570 Iterator<E> get iterator => new ArrayIterator<E>(this); |
571 | 571 |
572 int get hashCode => Primitives.objectHashCode(this); | 572 int get hashCode => Primitives.objectHashCode(this); |
573 | 573 |
574 int get length => JS('JSUInt32', r'#.length', this); | 574 int get length => JS('JSUInt32', r'#.length', this); |
575 | 575 |
576 void set length(int newLength) { | 576 void set length(int newLength) { |
577 checkGrowable('set length'); | 577 checkGrowable('set length'); |
578 if (newLength is !int) throw new ArgumentError(newLength); | 578 if (newLength is !int) { |
579 if (newLength < 0) throw new RangeError.value(newLength); | 579 throw new ArgumentError.value(newLength, 'newLength'); |
| 580 } |
| 581 // TODO(sra): Remove this test and let JavaScript throw an error. |
| 582 if (newLength < 0) { |
| 583 throw new RangeError.range(newLength, 0, null, 'newLength'); |
| 584 } |
| 585 // JavaScript with throw a RangeError for numbers that are too big. The |
| 586 // message does not contain the value. |
580 JS('void', r'#.length = #', this, newLength); | 587 JS('void', r'#.length = #', this, newLength); |
581 } | 588 } |
582 | 589 |
583 E operator [](int index) { | 590 E operator [](int index) { |
584 if (index is !int) throw new ArgumentError(index); | 591 if (index is !int) throw diagnoseIndexError(this, index); |
585 if (index >= length || index < 0) throw new RangeError.value(index); | 592 if (index >= length || index < 0) throw diagnoseIndexError(this, index); |
586 return JS('var', '#[#]', this, index); | 593 return JS('var', '#[#]', this, index); |
587 } | 594 } |
588 | 595 |
589 void operator []=(int index, E value) { | 596 void operator []=(int index, E value) { |
590 checkMutable('indexed set'); | 597 checkMutable('indexed set'); |
591 if (index is !int) throw new ArgumentError(index); | 598 if (index is !int) throw diagnoseIndexError(this, index); |
592 if (index >= length || index < 0) throw new RangeError.value(index); | 599 if (index >= length || index < 0) throw diagnoseIndexError(this, index); |
593 JS('void', r'#[#] = #', this, index, value); | 600 JS('void', r'#[#] = #', this, index, value); |
594 } | 601 } |
595 | 602 |
596 Map<int, E> asMap() { | 603 Map<int, E> asMap() { |
597 return new ListMapView<E>(this); | 604 return new ListMapView<E>(this); |
598 } | 605 } |
599 } | 606 } |
600 | 607 |
601 /** | 608 /** |
602 * Dummy subclasses that allow the backend to track more precise | 609 * Dummy subclasses that allow the backend to track more precise |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 | 647 |
641 if (_index >= length) { | 648 if (_index >= length) { |
642 _current = null; | 649 _current = null; |
643 return false; | 650 return false; |
644 } | 651 } |
645 _current = _iterable[_index]; | 652 _current = _iterable[_index]; |
646 _index++; | 653 _index++; |
647 return true; | 654 return true; |
648 } | 655 } |
649 } | 656 } |
OLD | NEW |