Index: runtime/lib/array.cc |
diff --git a/runtime/lib/array.cc b/runtime/lib/array.cc |
index 7d9e076583483ae407786cab564af3ded01a1173..1bde5aceb14429b3e7ddb76945a7dc5e774a419f 100644 |
--- a/runtime/lib/array.cc |
+++ b/runtime/lib/array.cc |
@@ -23,9 +23,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())) { |
- const Array& args = Array::Handle(Array::New(1)); |
- args.SetAt(0, index); |
- Exceptions::ThrowByType(Exceptions::kRange, args); |
+ Exceptions::ThrowRangeError("index", index, 0, array.Length()); |
} |
return array.At(index.Value()); |
} |
@@ -36,9 +34,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())) { |
- const Array& args = Array::Handle(Array::New(1)); |
- args.SetAt(0, index); |
- Exceptions::ThrowByType(Exceptions::kRange, args); |
+ Exceptions::ThrowRangeError("index", index, 0, array.Length()); |
} |
array.SetAt(index.Value(), value); |
return Object::null(); |
@@ -51,6 +47,28 @@ DEFINE_NATIVE_ENTRY(List_getLength, 1) { |
} |
+static void CheckRange(const char* name, |
+ intptr_t start, |
+ intptr_t count, |
+ intptr_t length) { |
+ if ((start < 0) || ((start + count) > length)) { |
+ if (count > length) { |
+ Exceptions::ThrowRangeError( |
+ "count", |
+ Smi::Handle(Smi::New(count)), |
+ 0, |
+ length + 1); |
+ } else { |
+ Exceptions::ThrowRangeError( |
+ name, |
+ Smi::Handle(Smi::New(start)), |
+ 0, |
+ length - count); |
+ } |
+ } |
+} |
+ |
+ |
// ObjectArray src, int srcStart, int dstStart, int count. |
DEFINE_NATIVE_ENTRY(List_copyFromObjectArray, 5) { |
const Array& dest = Array::CheckedHandle(arguments->NativeArgAt(0)); |
@@ -67,18 +85,10 @@ DEFINE_NATIVE_ENTRY(List_copyFromObjectArray, 5) { |
} |
intptr_t isrc_start = src_start.Value(); |
intptr_t idst_start = dst_start.Value(); |
- if ((isrc_start < 0) || ((isrc_start + icount) > source.Length())) { |
- const Array& args = Array::Handle(Array::New(1)); |
- args.SetAt(0, src_start); |
- Exceptions::ThrowByType(Exceptions::kRange, args); |
- } |
- if ((idst_start < 0) || ((idst_start + icount) > dest.Length())) { |
- const Array& args = Array::Handle(Array::New(1)); |
- args.SetAt(0, dst_start); |
- Exceptions::ThrowByType(Exceptions::kRange, args); |
- } |
+ CheckRange("source", isrc_start, icount, source.Length()); |
+ CheckRange("destination", idst_start, icount, dest.Length()); |
- Object& src_obj = Object::Handle(); |
+ PassiveObject& src_obj = PassiveObject::Handle(); |
if (isrc_start < idst_start) { |
for (intptr_t i = icount - 1; i >= 0; i--) { |
src_obj = source.At(isrc_start + i); |
@@ -90,6 +100,7 @@ DEFINE_NATIVE_ENTRY(List_copyFromObjectArray, 5) { |
dest.SetAt(idst_start + i, src_obj); |
} |
} |
+ |
return Object::null(); |
} |