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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/js_array.dart

Issue 12817003: Change getRange to sublist. Make getRange deprecated. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
Index: sdk/lib/_internal/compiler/implementation/lib/js_array.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/js_array.dart b/sdk/lib/_internal/compiler/implementation/lib/js_array.dart
index 10059c788a114df3c6396617c70f4cb1819b0969..07620a4aac9f490ca8adcf3f7d658af2997d6b43 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_array.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_array.dart
@@ -137,23 +137,30 @@ class JSArray<E> implements List<E>, JSIndexable {
return this[index];
}
- List<E> getRange(int start, int length) {
- // TODO(ngeoffray): Parameterize the return value.
- if (0 == length) return [];
+ List<E> sublist(int start, [int end]) {
checkNull(start); // TODO(ahe): This is not specified but co19 tests it.
- checkNull(length); // TODO(ahe): This is not specified but co19 tests it.
if (start is !int) throw new ArgumentError(start);
- if (length is !int) throw new ArgumentError(length);
- if (length < 0) throw new ArgumentError(length);
- if (start < 0) throw new RangeError.value(start);
- int end = start + length;
- if (end > this.length) {
- throw new RangeError.value(length);
+ if (start < 0 || start > length) {
+ throw new RangeError.range(start, 0, length);
}
- if (length < 0) throw new ArgumentError(length);
+ if (end == null) {
+ end = length;
+ } else {
+ if (end is !int) throw new ArgumentError(end);
+ if (end < start || end > length) {
+ throw new RangeError.range(end, start, length);
+ }
+ }
+ // TODO(ngeoffray): Parameterize the return value.
+ if (start == end) return [];
return JS('=List', r'#.slice(#, #)', this, start, end);
}
+
+ List<E> getRange(int start, int length) {
+ return sublist(start, start + length);
+ }
+
void insertRange(int start, int length, [E initialValue]) {
checkGrowable(this, 'insertRange');
if (length == 0) {

Powered by Google App Engine
This is Rietveld 408576698