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

Unified Diff: runtime/lib/array.cc

Issue 1318943005: Update range errors to agree on the numbers. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: More tests Created 5 years, 3 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 | runtime/lib/growable_array.cc » ('j') | runtime/vm/exceptions.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « no previous file | runtime/lib/growable_array.cc » ('j') | runtime/vm/exceptions.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698