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

Unified Diff: sdk/lib/_collection_dev/iterable.dart

Issue 17020004: State that skip/take does not accept negative arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/core/iterable.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_collection_dev/iterable.dart
diff --git a/sdk/lib/_collection_dev/iterable.dart b/sdk/lib/_collection_dev/iterable.dart
index a6a65b2096be9f464f02c67003decdce7f2b6caf..c0cba32b24a967a20edeba2d056d1b698f3d369b 100644
--- a/sdk/lib/_collection_dev/iterable.dart
+++ b/sdk/lib/_collection_dev/iterable.dart
@@ -216,7 +216,19 @@ class SubListIterable<E> extends ListIterable<E> {
/** If null, represents the length of the iterable. */
final int _endOrLength;
- SubListIterable(this._iterable, this._start, this._endOrLength);
+ SubListIterable(this._iterable, this._start, this._endOrLength) {
+ if (_start < 0) {
+ throw new RangeError.value(_start);
+ }
+ if (_endOrLength != null) {
+ if (_endOrLength < 0) {
+ throw new RangeError.value(_endOrLength);
+ }
+ if (_start > _endOrLength) {
+ throw new RangeError.range(_start, 0, _endOrLength);
+ }
+ }
+ }
int get _endIndex {
int length = _iterable.length;
@@ -248,12 +260,12 @@ class SubListIterable<E> extends ListIterable<E> {
}
Iterable<E> skip(int count) {
- if (count < 0) throw new ArgumentError(count);
+ if (count < 0) throw new RangeError.value(count);
return new SubListIterable(_iterable, _start + count, _endOrLength);
}
Iterable<E> take(int count) {
- if (count < 0) throw new ArgumentError(count);
+ if (count < 0) throw new RangeError.value(count);
if (_endOrLength == null) {
return new SubListIterable(_iterable, _start, _start + count);
} else {
@@ -518,13 +530,13 @@ class SkipIterable<E> extends IterableBase<E> {
SkipIterable(this._iterable, this._skipCount) {
if (_skipCount is! int || _skipCount < 0) {
- throw new ArgumentError(_skipCount);
+ throw new RangeError(_skipCount);
}
}
Iterable<E> skip(int n) {
if (n is! int || n < 0) {
- throw new ArgumentError(n);
+ throw new RangeError.value(n);
}
return new SkipIterable<E>(_iterable, _skipCount + n);
}
@@ -643,11 +655,17 @@ class EmptyIterable<E> extends IterableBase<E> {
return initialValue;
}
- Iterable<E> skip(int count) => this;
+ Iterable<E> skip(int count) {
+ if (count < 0) throw new RangeError.value(count);
+ return this;
+ }
Iterable<E> skipWhile(bool test(E element)) => this;
- Iterable<E> take(int count) => this;
+ Iterable<E> take(int count) {
+ if (count < 0) throw new RangeError.value(count);
+ this;
+ }
Iterable<E> takeWhile(bool test(E element)) => this;
« no previous file with comments | « no previous file | sdk/lib/core/iterable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698