From 5410d97493446241a687c9cca2f3d43dc0cfa366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Sat, 23 Dec 2023 10:21:19 +0000 Subject: [PATCH] [dart2wasm] Fix JSArrayImpl.setRange on BigInt arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes `setRange` tests reported in #54409. Change-Id: I04698563f44aa44f634d7c0418f8056d361836a5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343160 Reviewed-by: Martin Kustermann Commit-Queue: Ömer Ağacan --- sdk/lib/_internal/wasm/lib/js_typed_array.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sdk/lib/_internal/wasm/lib/js_typed_array.dart b/sdk/lib/_internal/wasm/lib/js_typed_array.dart index 35dfccfd8df3..f28cdc471557 100644 --- a/sdk/lib/_internal/wasm/lib/js_typed_array.dart +++ b/sdk/lib/_internal/wasm/lib/js_typed_array.dart @@ -608,10 +608,18 @@ mixin _IntListMixin implements List { if (iterable is JSArrayBase) { final JSArrayBase source = unsafeCast(iterable); - final length = end - start; - final sourceArray = source.toJSArrayExternRef(skipCount, length); - final targetArray = toJSArrayExternRef(start, length); - return _setRangeFast(targetArray, sourceArray); + + // JS `TypedArray.prototype.set` does not allow mixing `BigInt` and other + // types. Check that either both of the arrays are `BigInt`s (signed or + // unsigned), or none of them are. + final sourceBigInt = source.elementSizeInBytes == 8; + final targetBigInt = elementSizeInBytes == 8; + if (!(sourceBigInt ^ targetBigInt)) { + final length = end - start; + final sourceArray = source.toJSArrayExternRef(skipCount, length); + final targetArray = toJSArrayExternRef(start, length); + return _setRangeFast(targetArray, sourceArray); + } } List otherList = iterable.skip(skipCount).toList(growable: false);