From 0a1e05acabedba4044c536cc56452d7bc64bba2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 15 Dec 2022 21:36:22 +0000 Subject: [PATCH] [dart2wasm] Tweak setRange error checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Commit-Queue: Ömer Ağacan --- sdk/lib/_internal/wasm/lib/internal_patch.dart | 4 ++++ sdk/lib/_internal/wasm/lib/list.dart | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/lib/_internal/wasm/lib/internal_patch.dart b/sdk/lib/_internal/wasm/lib/internal_patch.dart index f0fec447d10..257f5b59cc3 100644 --- a/sdk/lib/_internal/wasm/lib/internal_patch.dart +++ b/sdk/lib/_internal/wasm/lib/internal_patch.dart @@ -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; diff --git a/sdk/lib/_internal/wasm/lib/list.dart b/sdk/lib/_internal/wasm/lib/list.dart index 9b0bf687e64..081bd4913fb 100644 --- a/sdk/lib/_internal/wasm/lib/list.dart +++ b/sdk/lib/_internal/wasm/lib/list.dart @@ -60,14 +60,10 @@ abstract class _ModifiableList extends _ListBase { // List interface. void setRange(int start, int end, Iterable 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) {