Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/js_array.dart

Issue 1180713003: Better messages for optimized index errors. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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) throw new ArgumentError.value(newLength);
Lasse Reichstein Nielsen 2015/06/12 14:24:36 consider passing "newLength" as second argument.
sra1 2015/06/12 22:29:04 Done.
579 if (newLength < 0) throw new RangeError.value(newLength); 579 if (newLength < 0) throw new RangeError.value(newLength);
Lasse Reichstein Nielsen 2015/06/12 14:24:36 Consider using new RangeError.range(newLength, 0,
sra1 2015/06/12 22:29:05 I have done this for now. The error feels wordy a
580 JS('void', r'#.length = #', this, newLength); 580 JS('void', r'#.length = #', this, newLength);
581 } 581 }
582 582
583 E operator [](int index) { 583 E operator [](int index) {
584 if (index is !int) throw new ArgumentError(index); 584 if (index is !int) throw diagnoseIndexError(this, index);
585 if (index >= length || index < 0) throw new RangeError.value(index); 585 if (index >= length || index < 0) throw diagnoseIndexError(this, index);
586 return JS('var', '#[#]', this, index); 586 return JS('var', '#[#]', this, index);
587 } 587 }
588 588
589 void operator []=(int index, E value) { 589 void operator []=(int index, E value) {
590 checkMutable('indexed set'); 590 checkMutable('indexed set');
591 if (index is !int) throw new ArgumentError(index); 591 if (index is !int) throw diagnoseIndexError(this, index);
592 if (index >= length || index < 0) throw new RangeError.value(index); 592 if (index >= length || index < 0) throw diagnoseIndexError(this, index);
593 JS('void', r'#[#] = #', this, index, value); 593 JS('void', r'#[#] = #', this, index, value);
594 } 594 }
595 595
596 Map<int, E> asMap() { 596 Map<int, E> asMap() {
597 return new ListMapView<E>(this); 597 return new ListMapView<E>(this);
598 } 598 }
599 } 599 }
600 600
601 /** 601 /**
602 * Dummy subclasses that allow the backend to track more precise 602 * Dummy subclasses that allow the backend to track more precise
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 640
641 if (_index >= length) { 641 if (_index >= length) {
642 _current = null; 642 _current = null;
643 return false; 643 return false;
644 } 644 }
645 _current = _iterable[_index]; 645 _current = _iterable[_index];
646 _index++; 646 _index++;
647 return true; 647 return true;
648 } 648 }
649 } 649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698