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

Side by Side Diff: runtime/lib/growable_array.dart

Issue 9007015: Fix issue 920: do not allow length of a list go below 0. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/src/ListTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 class GrowableObjectArray<T> implements List<T> { 5 class GrowableObjectArray<T> implements List<T> {
6 ObjectArray<T> backingArray; 6 ObjectArray<T> backingArray;
7 7
8 factory GrowableObjectArray._uninstantiable() { 8 factory GrowableObjectArray._uninstantiable() {
9 throw const UnsupportedOperationException( 9 throw const UnsupportedOperationException(
10 "GrowableObjectArray can only be allocated by the VM"); 10 "GrowableObjectArray can only be allocated by the VM");
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 add(element); 156 add(element);
157 } 157 }
158 158
159 void addAll(Collection<T> collection) { 159 void addAll(Collection<T> collection) {
160 for (T elem in collection) { 160 for (T elem in collection) {
161 add(elem); 161 add(elem);
162 } 162 }
163 } 163 }
164 164
165 T removeLast() { 165 T removeLast() {
166 if (_length == 0) {
167 throw new IndexOutOfRangeException(-1);
168 }
166 _length--; 169 _length--;
167 return backingArray[_length]; 170 return backingArray[_length];
168 } 171 }
169 172
170 T last() { 173 T last() {
171 if (_length === 0) { 174 if (_length === 0) {
172 throw new IndexOutOfRangeException(-1); 175 throw new IndexOutOfRangeException(-1);
173 } 176 }
174 return backingArray[_length - 1]; 177 return backingArray[_length - 1];
175 } 178 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 if (!hasNext()) { 242 if (!hasNext()) {
240 throw const NoMoreElementsException(); 243 throw const NoMoreElementsException();
241 } 244 }
242 return _array[_pos++]; 245 return _array[_pos++];
243 } 246 }
244 247
245 final GrowableObjectArray<T> _array; 248 final GrowableObjectArray<T> _array;
246 int _pos; 249 int _pos;
247 } 250 }
248 251
OLDNEW
« no previous file with comments | « no previous file | tests/language/src/ListTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698