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

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: Addressed review comments 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 b224b8324132542da0b2bcc474635f577aeda3bd..c86a14fc94d89d1ddf7a57a8cc43643e6abe8e5e 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_array.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_array.dart
@@ -146,23 +146,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);
srdjan 2013/03/18 16:24:41 Isn't this different behavior than in the VM libra
floitsch 2013/03/18 17:02:14 If you want to have the same behavior on the VM an
- 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