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

Unified Diff: frog/lib/corelib_impl.dart

Issue 9129023: adds array bounds checking (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged Created 8 years, 11 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 | « frog/gen.dart ('k') | frog/member.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/lib/corelib_impl.dart
diff --git a/frog/lib/corelib_impl.dart b/frog/lib/corelib_impl.dart
index 83224984a42295eee0e49bae265df619e742d7dd..6bc55b591fa7459ad20f268943ef6edb955d6a0e 100644
--- a/frog/lib/corelib_impl.dart
+++ b/frog/lib/corelib_impl.dart
@@ -69,8 +69,14 @@ class ListFactory<E> implements List<E> native "Array" {
E last() => this[this.length-1];
- List<E> getRange(int start, int length) native
- "return this.slice(start, start + length);";
+ List<E> getRange(int start, int length) native """
+ if (length == 0) return [];
+ if (length < 0) throw new IllegalArgumentException('length');
+ if (start < 0 || start + length > this.length)
+ throw new IndexOutOfRangeException(start);
+ return this.slice(start, start + length);
+ """ { throw new IllegalArgumentException('');
+ throw new IndexOutOfRangeException(0); }
void setRange(int start, int length, List<E> from, [int startFrom = 0]) {
// length of 0 prevails and should not throw exceptions.
@@ -91,10 +97,21 @@ class ListFactory<E> implements List<E> native "Array" {
this[start + i] = from[startFrom + i];
}
- void removeRange(int start, int length) native "this.splice(start, length);";
+ void removeRange(int start, int length) native """
+ if (length == 0) return;
+ if (length < 0) throw new IllegalArgumentException('length');
+ if (start < 0 || start + length > this.length)
+ throw new IndexOutOfRangeException(start);
+ this.splice(start, length);
+ """ { throw new IllegalArgumentException('');
+ throw new IndexOutOfRangeException(0); }
+
+ void insertRange(int start, int length, [E initialValue]) native """
+ if (length == 0) return;
+ if (length < 0) throw new IllegalArgumentException('length');
+ if (start < 0 || start > this.length)
+ throw new IndexOutOfRangeException(start);
- void insertRange(int start, int length, [E initialValue]) native
- """
// Splice in the values with a minimum of array allocations.
var args = new Array(length + 2);
args[0] = start;
@@ -103,7 +120,8 @@ class ListFactory<E> implements List<E> native "Array" {
args[i + 2] = initialValue;
}
this.splice.apply(this, args);
- """;
+ """ { throw new IllegalArgumentException('');
+ throw new IndexOutOfRangeException(0); }
// Collection<E> members:
void forEach(void f(E element)) native;
« no previous file with comments | « frog/gen.dart ('k') | frog/member.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698