[dart2wasm] Tweak setRange error checking

Error checking copied from VM.

New passing test: corelib/list_set_range_test

Change-Id: Iaac3be44037bac5646498a733828ee1f71f0eeb6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275861
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
Ömer Sinan Ağacan 2022-12-15 21:36:22 +00:00 committed by Commit Queue
parent f652c7962b
commit 0a1e05acab
2 changed files with 6 additions and 6 deletions

View file

@ -70,6 +70,10 @@ const bool has63BitSmis = false;
class Lists {
static void copy(List src, int srcStart, List dst, int dstStart, int count) {
if (srcStart + count > src.length) {
throw IterableElementError.tooFew();
}
// TODO(askesc): Intrinsify for efficient copying
if (srcStart < dstStart) {
for (int i = srcStart + count - 1, j = dstStart + count - 1;

View file

@ -60,14 +60,10 @@ abstract class _ModifiableList<E> extends _ListBase<E> {
// List interface.
void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
if (start < 0 || start > this.length) {
throw new RangeError.range(start, 0, this.length);
}
if (end < start || end > this.length) {
throw new RangeError.range(end, start, this.length);
}
RangeError.checkValidRange(start, end, this.length);
int length = end - start;
if (length == 0) return;
RangeError.checkNotNegative(skipCount, "skipCount");
if (identical(this, iterable)) {
Lists.copy(this, skipCount, this, start, length);
} else if (iterable is List<E>) {