Index: runtime/lib/array.cc |
diff --git a/runtime/lib/array.cc b/runtime/lib/array.cc |
index 003f12ff99bc637d3f4235cef610b380ee786c15..ad9f95c700e3b2c5e823525f4c3bc766ce4a56bf 100644 |
--- a/runtime/lib/array.cc |
+++ b/runtime/lib/array.cc |
@@ -22,7 +22,7 @@ DEFINE_NATIVE_ENTRY(List_getIndexed, 2) { |
const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0)); |
GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); |
if ((index.Value() < 0) || (index.Value() >= array.Length())) { |
- Exceptions::ThrowRangeError("index", index, 0, array.Length()); |
+ Exceptions::ThrowRangeError("index", index, 0, array.Length() - 1); |
} |
return array.At(index.Value()); |
} |
@@ -33,7 +33,7 @@ DEFINE_NATIVE_ENTRY(List_setIndexed, 3) { |
GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); |
const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(2)); |
if ((index.Value() < 0) || (index.Value() >= array.Length())) { |
- Exceptions::ThrowRangeError("index", index, 0, array.Length()); |
+ Exceptions::ThrowRangeError("index", index, 0, array.Length() - 1); |
} |
array.SetAt(index.Value(), value); |
return Object::null(); |
@@ -52,22 +52,22 @@ DEFINE_NATIVE_ENTRY(List_slice, 4) { |
GET_NON_NULL_NATIVE_ARGUMENT(Smi, start, arguments->NativeArgAt(1)); |
GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(2)); |
GET_NON_NULL_NATIVE_ARGUMENT(Bool, needs_type_arg, arguments->NativeArgAt(3)); |
+ intptr_t istart = start.Value(); |
+ if ((istart < 0) || (istart > src.Length())) { |
+ Exceptions::ThrowRangeError( |
+ "start", |
+ Smi::Handle(Smi::New(istart)), |
Ivan Posva
2015/09/11 09:12:50
start
|
+ 0, |
+ src.Length()); |
+ } |
intptr_t icount = count.Value(); |
// Zero count should be handled outside already. |
if ((icount <= 0) || (icount > src.Length())) { |
Exceptions::ThrowRangeError( |
"count", |
Smi::Handle(Smi::New(icount)), |
Ivan Posva
2015/09/11 09:12:50
count
|
- 1, |
- src.Length() + 1); |
- } |
- intptr_t istart = start.Value(); |
- if ((istart < 0) || ((istart + icount) > src.Length())) { |
- Exceptions::ThrowRangeError( |
- "start", |
- Smi::Handle(Smi::New(istart)), |
- 0, |
- src.Length() - icount + 1); |
+ 0, // This is the limit the user sees. |
+ src.Length() - istart); |
srdjan
2015/09/25 20:32:17
Shouldn't this be "src.Length()" only.
Lasse Reichstein Nielsen
2015/09/25 23:28:22
Probably. Maybe it would be simpler to pass `end`
Lasse Reichstein Nielsen
2015/09/25 23:29:15
... but that would mean changing "count" above to
|
} |
return src.Slice(istart, icount, needs_type_arg.value()); |