From 63b49dfc8ef255f39856e5a73ed8fbe465f2678a Mon Sep 17 00:00:00 2001 From: Kallen Tu Date: Tue, 8 Nov 2022 19:02:35 +0000 Subject: [PATCH] Deprecate checkValidIndex and avoid using it in the core library. TEST=No new behaviour, existing tests pass. Change-Id: Ia7a8e58543bd5e1d8dd14bd46c5083759333845b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259104 Reviewed-by: Nate Bosch Reviewed-by: Lasse Nielsen Commit-Queue: Kallen Tu Reviewed-by: Leaf Petersen --- CHANGELOG.md | 3 + .../utilities/extensions/library_element.dart | 2 +- runtime/tests/vm/dart/regress_47010_test.dart | 6 +- .../tests/vm/dart_2/regress_40462_test.dart | 17 +- runtime/vm/compiler/recognized_methods_list.h | 64 ++-- .../js_dev_runtime/private/js_array.dart | 4 +- .../js_dev_runtime/private/js_helper.dart | 6 +- .../js_dev_runtime/private/js_string.dart | 2 +- .../_internal/js_runtime/lib/js_helper.dart | 6 +- .../_internal/vm/lib/typed_data_patch.dart | 304 ++++++++++++------ sdk/lib/_internal/wasm/lib/list.dart | 4 +- sdk/lib/_internal/wasm/lib/simd_patch.dart | 18 +- sdk/lib/async/stream.dart | 3 +- sdk/lib/collection/iterable.dart | 3 +- sdk/lib/collection/queue.dart | 2 +- sdk/lib/collection/set.dart | 3 +- sdk/lib/core/errors.dart | 54 +++- sdk/lib/core/iterable.dart | 5 +- sdk/lib/core/list.dart | 2 +- sdk/lib/core/string.dart | 3 +- sdk/lib/html/dart2js/html_dart2js.dart | 34 +- sdk/lib/internal/iterable.dart | 3 +- sdk/lib/internal/list.dart | 2 +- sdk/lib/svg/dart2js/svg_dart2js.dart | 8 +- sdk/lib/web_sql/dart2js/web_sql_dart2js.dart | 2 +- tests/corelib/errors_test.dart | 30 +- tests/corelib/range_error_test.dart | 3 +- tests/corelib_2/errors_test.dart | 30 +- tests/corelib_2/range_error_test.dart | 3 +- tools/dom/scripts/systemhtml.py | 2 +- tools/dom/scripts/systemnative.py | 4 +- 31 files changed, 407 insertions(+), 225 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a027dd95eb4..4e3add4d662 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,9 @@ - Deprecated `FallThroughError`. Has not been thrown since Dart 2.0 (see [#49529]). - Added `copyWith` extension method on `DateTime` (see [#24644]). +- Deprecated `RangeError.checkValidIndex` in favor of `IndexError.check`. +- Deprecated `IndexError` constructor in favor of `IndexError.withLength` + constructor. [#49529]: https://github.com/dart-lang/sdk/issues/49529 [#24644]: https://github.com/dart-lang/sdk/issues/24644 diff --git a/pkg/analyzer/lib/src/utilities/extensions/library_element.dart b/pkg/analyzer/lib/src/utilities/extensions/library_element.dart index 3f2590121c4..45f8f13032c 100644 --- a/pkg/analyzer/lib/src/utilities/extensions/library_element.dart +++ b/pkg/analyzer/lib/src/utilities/extensions/library_element.dart @@ -21,7 +21,7 @@ extension _ElementExtension on Element { /// is a match up to [thisIndex]. Element? _locateElement(ElementLocation location, int thisIndex) { final components = location.components; - RangeError.checkValidIndex(thisIndex, components); + IndexError.check(thisIndex, components.length, indexable: components); final nextIndex = thisIndex + 1; if (nextIndex == components.length) { diff --git a/runtime/tests/vm/dart/regress_47010_test.dart b/runtime/tests/vm/dart/regress_47010_test.dart index 108ead2e575..b3545b67c25 100644 --- a/runtime/tests/vm/dart/regress_47010_test.dart +++ b/runtime/tests/vm/dart/regress_47010_test.dart @@ -61,8 +61,10 @@ ArgumentError var46 = ArgumentError.value(22, 'K90\u{1f600}QtS', 33); ArgumentError? var47 = ArgumentError.notNull(')'); RangeError var48 = RangeError.range(2, 23, 36, 'H', 'w&'); RangeError? var49 = new RangeError(22); -IndexError var50 = IndexError(15, 14, 'ZuC', '#1z9xJ', 1); -IndexError? var51 = IndexError(14, 36, 'V(', '9Jf!0\u2665', 2); +IndexError var50 = + IndexError.withLength(15, 1, indexable: 14, name: 'ZuC', message: '#1z9xJ'); +IndexError? var51 = IndexError.withLength(14, 2, + indexable: 36, name: 'V(', message: '9Jf!0\u2665'); FallThroughError var52 = FallThroughError(); FallThroughError? var53 = FallThroughError(); AbstractClassInstantiationError var54 = AbstractClassInstantiationError('J!'); diff --git a/runtime/tests/vm/dart_2/regress_40462_test.dart b/runtime/tests/vm/dart_2/regress_40462_test.dart index e3b791606ec..7e2c94bc465 100644 --- a/runtime/tests/vm/dart_2/regress_40462_test.dart +++ b/runtime/tests/vm/dart_2/regress_40462_test.dart @@ -51,8 +51,10 @@ TypeError var22 = TypeError(); CastError var23 = CastError(); NullThrownError var24 = new NullThrownError(); ArgumentError var25 = ArgumentError.value(27, '', 18); -RangeError var26 = RangeError.index(1, 42, '+m', 'JjY', 46); -IndexError var27 = IndexError(38, 29, 'R1Z', 'VnR7', 13); +RangeError var26 = + IndexError.withLength(1, 46, indexable: 42, name: '+m', message: 'JjY'); +IndexError var27 = + IndexError.withLength(38, 13, indexable: 29, name: 'R1Z', message: 'VnR7'); FallThroughError var28 = new FallThroughError(); AbstractClassInstantiationError var29 = AbstractClassInstantiationError('Sq'); UnsupportedError var30 = UnsupportedError('(OXv'); @@ -899,7 +901,8 @@ class X1 extends X0 { @override Int32x4List call(int par1) { - var26 ??= IndexError(27, 18, '+Qy9', '', 6); + var26 ??= + IndexError.withLength(27, 6, indexable: 18, name: '+Qy9', message: ''); { int loc0 = 41; while (--loc0 > 0) { @@ -939,7 +942,10 @@ class X1 extends X0 { ((loc0).modInverse(loc1) as int))) .isNegative), ('D\u2665Sp' == - IndexError(14, 12, 'PDTOXf', '&5e', 13)) + IndexError.withLength(14, 13, + indexable: 12, + name: 'PDTOXf', + message: '&5e')) ]) ?? [true, (!(false))]) : [true])); @@ -984,7 +990,8 @@ extension XE1 on X1 { : CastError()); } } - return IndexError(15, 17, 'yw', '', 20); + return IndexError.withLength(15, 20, + indexable: 17, name: 'yw', message: ''); } Expando foo1_Extension1() { diff --git a/runtime/vm/compiler/recognized_methods_list.h b/runtime/vm/compiler/recognized_methods_list.h index 5c1ad6087c3..772fa42a819 100644 --- a/runtime/vm/compiler/recognized_methods_list.h +++ b/runtime/vm/compiler/recognized_methods_list.h @@ -384,40 +384,40 @@ namespace dart { V(_IntegerImplementation, <<, Integer_shl, 0x4a95c65b) \ #define GRAPH_TYPED_DATA_INTRINSICS_LIST(V) \ - V(_Int8List, [], Int8ArrayGetIndexed, 0x35f3fab6) \ - V(_Int8List, []=, Int8ArraySetIndexed, 0x6e4fdaa7) \ - V(_Uint8List, [], Uint8ArrayGetIndexed, 0x9b6c7e76) \ - V(_Uint8List, []=, Uint8ArraySetIndexed, 0xbadee66b) \ - V(_ExternalUint8Array, [], ExternalUint8ArrayGetIndexed, 0x9b6c7e76) \ - V(_ExternalUint8Array, []=, ExternalUint8ArraySetIndexed, 0xbadee66b) \ - V(_Uint8ClampedList, [], Uint8ClampedArrayGetIndexed, 0x9b6c7e76) \ - V(_Uint8ClampedList, []=, Uint8ClampedArraySetIndexed, 0xb0de9c0b) \ + V(_Int8List, [], Int8ArrayGetIndexed, 0x3cf7f9ce) \ + V(_Int8List, []=, Int8ArraySetIndexed, 0xf6867b8f) \ + V(_Uint8List, [], Uint8ArrayGetIndexed, 0xa2707d8e) \ + V(_Uint8List, []=, Uint8ArraySetIndexed, 0x43158753) \ + V(_ExternalUint8Array, [], ExternalUint8ArrayGetIndexed, 0xa2707d8e) \ + V(_ExternalUint8Array, []=, ExternalUint8ArraySetIndexed, 0x43158753) \ + V(_Uint8ClampedList, [], Uint8ClampedArrayGetIndexed, 0xa2707d8e) \ + V(_Uint8ClampedList, []=, Uint8ClampedArraySetIndexed, 0x39153cf3) \ V(_ExternalUint8ClampedArray, [], ExternalUint8ClampedArrayGetIndexed, \ - 0x9b6c7e76) \ + 0xa2707d8e) \ V(_ExternalUint8ClampedArray, []=, ExternalUint8ClampedArraySetIndexed, \ - 0xb0de9c0b) \ - V(_Int16List, [], Int16ArrayGetIndexed, 0x15f25a16) \ - V(_Int16List, []=, Int16ArraySetIndexed, 0xfecf9e32) \ - V(_Uint16List, [], Uint16ArrayGetIndexed, 0xf9cb3616) \ - V(_Uint16List, []=, Uint16ArraySetIndexed, 0xe71245a9) \ - V(_Int32List, [], Int32ArrayGetIndexed, 0x178fffb5) \ - V(_Int32List, []=, Int32ArraySetIndexed, 0xdd041ad1) \ - V(_Uint32List, [], Uint32ArrayGetIndexed, 0x66e26555) \ - V(_Uint32List, []=, Uint32ArraySetIndexed, 0xc8a78f51) \ - V(_Int64List, [], Int64ArrayGetIndexed, 0x505859f5) \ - V(_Int64List, []=, Int64ArraySetIndexed, 0x5a2e23b7) \ - V(_Uint64List, [], Uint64ArrayGetIndexed, 0x8d1cbf75) \ - V(_Uint64List, []=, Uint64ArraySetIndexed, 0x258f94ef) \ - V(_Float64List, [], Float64ArrayGetIndexed, 0x6d778ebc) \ - V(_Float64List, []=, Float64ArraySetIndexed, 0xed47a595) \ - V(_Float32List, [], Float32ArrayGetIndexed, 0x43758fdc) \ - V(_Float32List, []=, Float32ArraySetIndexed, 0x489602c3) \ - V(_Float32x4List, [], Float32x4ArrayGetIndexed, 0xed5d8d35) \ - V(_Float32x4List, []=, Float32x4ArraySetIndexed, 0x0b093d30) \ - V(_Int32x4List, [], Int32x4ArrayGetIndexed, 0x834607ad) \ - V(_Int32x4List, []=, Int32x4ArraySetIndexed, 0x17a2cbc0) \ - V(_Float64x2List, [], Float64x2ArrayGetIndexed, 0xea0577df) \ - V(_Float64x2List, []=, Float64x2ArraySetIndexed, 0x8af8aa58) \ + 0x39153cf3) \ + V(_Int16List, [], Int16ArrayGetIndexed, 0x1cf6592e) \ + V(_Int16List, []=, Int16ArraySetIndexed, 0x87063f1a) \ + V(_Uint16List, [], Uint16ArrayGetIndexed, 0x00cf352e) \ + V(_Uint16List, []=, Uint16ArraySetIndexed, 0x6f48e691) \ + V(_Int32List, [], Int32ArrayGetIndexed, 0x1e93fecd) \ + V(_Int32List, []=, Int32ArraySetIndexed, 0x653abbb9) \ + V(_Uint32List, [], Uint32ArrayGetIndexed, 0x6de6646d) \ + V(_Uint32List, []=, Uint32ArraySetIndexed, 0x50de3039) \ + V(_Int64List, [], Int64ArrayGetIndexed, 0x575c590d) \ + V(_Int64List, []=, Int64ArraySetIndexed, 0x905d6bcf) \ + V(_Uint64List, [], Uint64ArrayGetIndexed, 0x9420be8d) \ + V(_Uint64List, []=, Uint64ArraySetIndexed, 0x5bbedd07) \ + V(_Float64List, [], Float64ArrayGetIndexed, 0x91192954) \ + V(_Float64List, []=, Float64ArraySetIndexed, 0x8f1ba92d) \ + V(_Float32List, [], Float32ArrayGetIndexed, 0x67172a74) \ + V(_Float32List, []=, Float32ArraySetIndexed, 0xea6a065b) \ + V(_Float32x4List, [], Float32x4ArrayGetIndexed, 0x68d7290d) \ + V(_Float32x4List, []=, Float32x4ArraySetIndexed, 0x6eb9f208) \ + V(_Int32x4List, [], Int32x4ArrayGetIndexed, 0x7e4ff185) \ + V(_Int32x4List, []=, Int32x4ArraySetIndexed, 0x58084e98) \ + V(_Float64x2List, [], Float64x2ArrayGetIndexed, 0xb2996c37) \ + V(_Float64x2List, []=, Float64x2ArraySetIndexed, 0x5e8f97b0) \ V(_TypedListBase, get:length, TypedListBaseLength, 0x5850f06b) \ V(_ByteDataView, get:length, ByteDataViewLength, 0x5850f06b) \ V(_Float32x4, get:x, Float32x4GetX, 0x3a398530) \ diff --git a/sdk/lib/_internal/js_dev_runtime/private/js_array.dart b/sdk/lib/_internal/js_dev_runtime/private/js_array.dart index 3fe9b226902..a0ce3d743c6 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/js_array.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/js_array.dart @@ -626,12 +626,12 @@ class JSArray implements List, JSIndexable { } void set first(E element) { - if (this.isEmpty) throw RangeError.index(0, this); + if (this.isEmpty) throw IndexError.withLength(0, length, indexable: this); this[0] = element; } void set last(E element) { - if (this.isEmpty) throw RangeError.index(0, this); + if (this.isEmpty) throw IndexError.withLength(0, length, indexable: this); this[this.length - 1] = element; } } diff --git a/sdk/lib/_internal/js_dev_runtime/private/js_helper.dart b/sdk/lib/_internal/js_dev_runtime/private/js_helper.dart index 9659650be1e..b5bbc9eacc3 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/js_helper.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/js_helper.dart @@ -478,9 +478,11 @@ class Primitives { Error diagnoseIndexError(indexable, int index) { int length = indexable.length; // The following returns the same error that would be thrown by calling - // [RangeError.checkValidIndex] with no optional parameters provided. + // [IndexError.check] with no optional parameters + // provided. if (index < 0 || index >= length) { - return RangeError.index(index, indexable, 'index', null, length); + return IndexError.withLength(index, length, + indexable: indexable, name: 'index'); } // The above should always match, but if it does not, use the following. return RangeError.value(index, 'index'); diff --git a/sdk/lib/_internal/js_dev_runtime/private/js_string.dart b/sdk/lib/_internal/js_dev_runtime/private/js_string.dart index 09b54dc87ee..6ba27e86336 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/js_string.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/js_string.dart @@ -20,7 +20,7 @@ class JSString extends Interceptor implements String, JSIndexable { // (JS String.length cannot be null). final len = this.length; if (index < 0 || index >= len) { - throw RangeError.index(index, this, 'index', null, len); + throw IndexError.withLength(index, len, indexable: this, name: 'index'); } return JS('!', r'#.charCodeAt(#)', this, index); } diff --git a/sdk/lib/_internal/js_runtime/lib/js_helper.dart b/sdk/lib/_internal/js_runtime/lib/js_helper.dart index 2114537d382..5f5e9143a09 100644 --- a/sdk/lib/_internal/js_runtime/lib/js_helper.dart +++ b/sdk/lib/_internal/js_runtime/lib/js_helper.dart @@ -1047,9 +1047,11 @@ Error diagnoseIndexError(indexable, index) { if (index is! int) return new ArgumentError.value(index, 'index'); int length = indexable.length; // The following returns the same error that would be thrown by calling - // [RangeError.checkValidIndex] with no optional parameters provided. + // [IndexError.check] with no optional parameters + // provided. if (index < 0 || index >= length) { - return new RangeError.index(index, indexable, 'index', null, length); + return new IndexError.withLength(index, length, + indexable: indexable, name: 'index'); } // The above should always match, but if it does not, use the following. return new RangeError.value(index, 'index'); diff --git a/sdk/lib/_internal/vm/lib/typed_data_patch.dart b/sdk/lib/_internal/vm/lib/typed_data_patch.dart index a1250e11c59..6add8ca7264 100644 --- a/sdk/lib/_internal/vm/lib/typed_data_patch.dart +++ b/sdk/lib/_internal/vm/lib/typed_data_patch.dart @@ -129,12 +129,16 @@ mixin _IntListMixin implements List { List cast() => List.castFrom(this); void set first(int value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[0] = value; } void set last(int value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[this.length - 1] = value; } @@ -479,12 +483,16 @@ mixin _DoubleListMixin implements List { List cast() => List.castFrom(this); void set first(double value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[0] = value; } void set last(double value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[this.length - 1] = value; } @@ -835,12 +843,16 @@ abstract class _Float32x4ListMixin implements List { List cast() => List.castFrom(this); void set first(Float32x4 value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[0] = value; } void set last(Float32x4 value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[this.length - 1] = value; } @@ -1189,12 +1201,16 @@ abstract class _Int32x4ListMixin implements List { List cast() => List.castFrom(this); void set first(Int32x4 value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[0] = value; } void set last(Int32x4 value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[this.length - 1] = value; } @@ -1542,12 +1558,16 @@ abstract class _Float64x2ListMixin implements List { List cast() => List.castFrom(this); void set first(Float64x2 value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[0] = value; } void set last(Float64x2 value) { - if (this.length == 0) throw new RangeError.index(0, this); + if (this.length == 0) { + throw new IndexError.withLength(0, length, indexable: this); + } this[this.length - 1] = value; } @@ -2189,7 +2209,8 @@ class _Int8List extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Smi") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getInt8(index); } @@ -2197,7 +2218,8 @@ class _Int8List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setInt8(index, _toInt8(value)); } @@ -2243,7 +2265,8 @@ class _Uint8List extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Smi") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getUint8(index); } @@ -2251,7 +2274,8 @@ class _Uint8List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setUint8(index, _toUint8(value)); } @@ -2297,7 +2321,8 @@ class _Uint8ClampedList extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Smi") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getUint8(index); } @@ -2305,7 +2330,8 @@ class _Uint8ClampedList extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setUint8(index, _toClampedUint8(value)); } @@ -2351,7 +2377,8 @@ class _Int16List extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Smi") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedInt16(index); } @@ -2359,7 +2386,8 @@ class _Int16List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedInt16(index, _toInt16(value)); } @@ -2425,7 +2453,8 @@ class _Uint16List extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Smi") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedUint16(index); } @@ -2433,7 +2462,8 @@ class _Uint16List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedUint16(index, _toUint16(value)); } @@ -2498,7 +2528,8 @@ class _Int32List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedInt32(index); } @@ -2506,7 +2537,8 @@ class _Int32List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedInt32(index, _toInt32(value)); } @@ -2559,7 +2591,8 @@ class _Uint32List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedUint32(index); } @@ -2567,7 +2600,8 @@ class _Uint32List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedUint32(index, _toUint32(value)); } @@ -2620,7 +2654,8 @@ class _Int64List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedInt64(index); } @@ -2628,7 +2663,8 @@ class _Int64List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedInt64(index, value); } @@ -2681,7 +2717,8 @@ class _Uint64List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedUint64(index); } @@ -2689,7 +2726,8 @@ class _Uint64List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedUint64(index, value); } @@ -2743,7 +2781,8 @@ class _Float32List extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Double") double operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedFloat32(index); } @@ -2751,7 +2790,8 @@ class _Float32List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, double value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedFloat32(index, value); } @@ -2805,7 +2845,8 @@ class _Float64List extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Double") double operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedFloat64(index); } @@ -2813,7 +2854,8 @@ class _Float64List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, double value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedFloat64(index, value); } @@ -2865,7 +2907,8 @@ class _Float32x4List extends _TypedList @pragma("vm:exact-result-type", _Float32x4) Float32x4 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedFloat32x4(index); } @@ -2873,7 +2916,8 @@ class _Float32x4List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, Float32x4 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedFloat32x4(index, value); } @@ -2925,7 +2969,8 @@ class _Int32x4List extends _TypedList @pragma("vm:exact-result-type", _Int32x4) Int32x4 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedInt32x4(index); } @@ -2933,7 +2978,8 @@ class _Int32x4List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, Int32x4 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedInt32x4(index, value); } @@ -2985,7 +3031,8 @@ class _Float64x2List extends _TypedList @pragma("vm:exact-result-type", _Float64x2) Float64x2 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedFloat64x2(index); } @@ -2993,7 +3040,8 @@ class _Float64x2List extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, Float64x2 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedFloat64x2(index, value); } @@ -3028,14 +3076,16 @@ class _ExternalInt8Array extends _TypedList // Method(s) implementing the List interface. int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getInt8(index); } void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setInt8(index, value); } @@ -3065,7 +3115,8 @@ class _ExternalUint8Array extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Smi") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getUint8(index); } @@ -3073,7 +3124,8 @@ class _ExternalUint8Array extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setUint8(index, _toUint8(value)); } @@ -3102,7 +3154,8 @@ class _ExternalUint8ClampedArray extends _TypedList @pragma("vm:exact-result-type", "dart:core#_Smi") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getUint8(index); } @@ -3110,7 +3163,8 @@ class _ExternalUint8ClampedArray extends _TypedList @pragma("vm:recognized", "graph-intrinsic") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setUint8(index, _toClampedUint8(value)); } @@ -3137,14 +3191,16 @@ class _ExternalInt16Array extends _TypedList // Method(s) implementing the List interface. int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedInt16(index); } void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedInt16(index, _toInt16(value)); } @@ -3179,14 +3235,16 @@ class _ExternalUint16Array extends _TypedList // Method(s) implementing the List interface. int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedUint16(index); } void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedUint16(index, _toUint16(value)); } @@ -3221,14 +3279,16 @@ class _ExternalInt32Array extends _TypedList // Method(s) implementing the List interface. int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedInt32(index); } void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedInt32(index, _toInt32(value)); } @@ -3263,14 +3323,16 @@ class _ExternalUint32Array extends _TypedList // Method(s) implementing the List interface. int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedUint32(index); } void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedUint32(index, _toUint32(value)); } @@ -3305,14 +3367,16 @@ class _ExternalInt64Array extends _TypedList // Method(s) implementing the List interface. int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedInt64(index); } void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedInt64(index, value); } @@ -3347,14 +3411,16 @@ class _ExternalUint64Array extends _TypedList // Method(s) implementing the List interface. int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedUint64(index); } void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedUint64(index, value); } @@ -3389,14 +3455,16 @@ class _ExternalFloat32Array extends _TypedList // Method(s) implementing the List interface. double operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedFloat32(index); } void operator []=(int index, double value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedFloat32(index, value); } @@ -3431,14 +3499,16 @@ class _ExternalFloat64Array extends _TypedList // Method(s) implementing the List interface. double operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedFloat64(index); } void operator []=(int index, double value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedFloat64(index, value); } @@ -3473,14 +3543,16 @@ class _ExternalFloat32x4Array extends _TypedList // Method(s) implementing the List interface. Float32x4 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedFloat32x4(index); } void operator []=(int index, Float32x4 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedFloat32x4(index, value); } @@ -3515,14 +3587,16 @@ class _ExternalInt32x4Array extends _TypedList // Method(s) implementing the List interface. Int32x4 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedInt32x4(index); } void operator []=(int index, Int32x4 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedInt32x4(index, value); } @@ -3557,14 +3631,16 @@ class _ExternalFloat64x2Array extends _TypedList // Method(s) implementing the List interface. Float64x2 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _getIndexedFloat64x2(index); } void operator []=(int index, Float64x2 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _setIndexedFloat64x2(index, value); } @@ -4153,7 +4229,8 @@ class _Int8ArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getInt8(offsetInBytes + (index * Int8List.bytesPerElement)); @@ -4162,7 +4239,8 @@ class _Int8ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setInt8( offsetInBytes + (index * Int8List.bytesPerElement), _toInt8(value)); @@ -4195,7 +4273,8 @@ class _Uint8ArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getUint8(offsetInBytes + (index * Uint8List.bytesPerElement)); @@ -4204,7 +4283,8 @@ class _Uint8ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setUint8( offsetInBytes + (index * Uint8List.bytesPerElement), _toUint8(value)); @@ -4237,7 +4317,8 @@ class _Uint8ClampedArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getUint8(offsetInBytes + (index * Uint8List.bytesPerElement)); @@ -4246,7 +4327,8 @@ class _Uint8ClampedArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setUint8(offsetInBytes + (index * Uint8List.bytesPerElement), _toClampedUint8(value)); @@ -4279,7 +4361,8 @@ class _Int16ArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getInt16(offsetInBytes + (index * Int16List.bytesPerElement)); @@ -4288,7 +4371,8 @@ class _Int16ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setInt16( offsetInBytes + (index * Int16List.bytesPerElement), _toInt16(value)); @@ -4334,7 +4418,8 @@ class _Uint16ArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getUint16(offsetInBytes + (index * Uint16List.bytesPerElement)); @@ -4343,7 +4428,8 @@ class _Uint16ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setUint16( offsetInBytes + (index * Uint16List.bytesPerElement), _toUint16(value)); @@ -4390,7 +4476,8 @@ class _Int32ArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getInt32(offsetInBytes + (index * Int32List.bytesPerElement)); @@ -4399,7 +4486,8 @@ class _Int32ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setInt32( offsetInBytes + (index * Int32List.bytesPerElement), _toInt32(value)); @@ -4432,7 +4520,8 @@ class _Uint32ArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getUint32(offsetInBytes + (index * Uint32List.bytesPerElement)); @@ -4441,7 +4530,8 @@ class _Uint32ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setUint32( offsetInBytes + (index * Uint32List.bytesPerElement), _toUint32(value)); @@ -4474,7 +4564,8 @@ class _Int64ArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getInt64(offsetInBytes + (index * Int64List.bytesPerElement)); @@ -4483,7 +4574,8 @@ class _Int64ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setInt64( offsetInBytes + (index * Int64List.bytesPerElement), value); @@ -4516,7 +4608,8 @@ class _Uint64ArrayView extends _TypedListView @pragma("vm:prefer-inline") int operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getUint64(offsetInBytes + (index * Uint64List.bytesPerElement)); @@ -4525,7 +4618,8 @@ class _Uint64ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, int value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setUint64( offsetInBytes + (index * Uint64List.bytesPerElement), value); @@ -4558,7 +4652,8 @@ class _Float32ArrayView extends _TypedListView @pragma("vm:prefer-inline") double operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getFloat32(offsetInBytes + (index * Float32List.bytesPerElement)); @@ -4567,7 +4662,8 @@ class _Float32ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, double value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setFloat32( offsetInBytes + (index * Float32List.bytesPerElement), value); @@ -4600,7 +4696,8 @@ class _Float64ArrayView extends _TypedListView @pragma("vm:prefer-inline") double operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getFloat64(offsetInBytes + (index * Float64List.bytesPerElement)); @@ -4609,7 +4706,8 @@ class _Float64ArrayView extends _TypedListView @pragma("vm:prefer-inline") void operator []=(int index, double value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setFloat64( offsetInBytes + (index * Float64List.bytesPerElement), value); @@ -4641,7 +4739,8 @@ class _Float32x4ArrayView extends _TypedListView // Method(s) implementing List interface. Float32x4 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getFloat32x4(offsetInBytes + (index * Float32x4List.bytesPerElement)); @@ -4649,7 +4748,8 @@ class _Float32x4ArrayView extends _TypedListView void operator []=(int index, Float32x4 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setFloat32x4( offsetInBytes + (index * Float32x4List.bytesPerElement), value); @@ -4681,7 +4781,8 @@ class _Int32x4ArrayView extends _TypedListView // Method(s) implementing List interface. Int32x4 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getInt32x4(offsetInBytes + (index * Int32x4List.bytesPerElement)); @@ -4689,7 +4790,8 @@ class _Int32x4ArrayView extends _TypedListView void operator []=(int index, Int32x4 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setInt32x4( offsetInBytes + (index * Int32x4List.bytesPerElement), value); @@ -4721,7 +4823,8 @@ class _Float64x2ArrayView extends _TypedListView // Method(s) implementing List interface. Float64x2 operator [](int index) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } return _typedData ._getFloat64x2(offsetInBytes + (index * Float64x2List.bytesPerElement)); @@ -4729,7 +4832,8 @@ class _Float64x2ArrayView extends _TypedListView void operator []=(int index, Float64x2 value) { if (index < 0 || index >= length) { - throw new RangeError.index(index, this, "index"); + throw new IndexError.withLength(index, length, + indexable: this, name: "index"); } _typedData._setFloat64x2( offsetInBytes + (index * Float64x2List.bytesPerElement), value); @@ -4773,7 +4877,8 @@ class _ByteDataView implements ByteData { @pragma("vm:prefer-inline") int getInt8(int byteOffset) { if (byteOffset < 0 || byteOffset >= length) { - throw new RangeError.index(byteOffset, this, "byteOffset"); + throw new IndexError.withLength(byteOffset, length, + indexable: this, name: "byteOffset"); } return _typedData._getInt8(offsetInBytes + byteOffset); } @@ -4781,7 +4886,8 @@ class _ByteDataView implements ByteData { @pragma("vm:prefer-inline") void setInt8(int byteOffset, int value) { if (byteOffset < 0 || byteOffset >= length) { - throw new RangeError.index(byteOffset, this, "byteOffset"); + throw new IndexError.withLength(byteOffset, length, + indexable: this, name: "byteOffset"); } _typedData._setInt8(offsetInBytes + byteOffset, value); } @@ -4789,7 +4895,8 @@ class _ByteDataView implements ByteData { @pragma("vm:prefer-inline") int getUint8(int byteOffset) { if (byteOffset < 0 || byteOffset >= length) { - throw new RangeError.index(byteOffset, this, "byteOffset"); + throw new IndexError.withLength(byteOffset, length, + indexable: this, name: "byteOffset"); } return _typedData._getUint8(offsetInBytes + byteOffset); } @@ -4797,7 +4904,8 @@ class _ByteDataView implements ByteData { @pragma("vm:prefer-inline") void setUint8(int byteOffset, int value) { if (byteOffset < 0 || byteOffset >= length) { - throw new RangeError.index(byteOffset, this, "byteOffset"); + throw new IndexError.withLength(byteOffset, length, + indexable: this, name: "byteOffset"); } _typedData._setUint8(offsetInBytes + byteOffset, value); } diff --git a/sdk/lib/_internal/wasm/lib/list.dart b/sdk/lib/_internal/wasm/lib/list.dart index c1b35dd69bd..e03e0b9ff46 100644 --- a/sdk/lib/_internal/wasm/lib/list.dart +++ b/sdk/lib/_internal/wasm/lib/list.dart @@ -19,7 +19,7 @@ abstract class _ListBase extends ListBase { _ListBase._withData(this._length, this._data); E operator [](int index) { - RangeError.checkValidIndex(index, this, "[]", _length); + IndexError.check(index, _length, indexable: this, name: "[]"); return unsafeCast(_data.read(index)); } @@ -53,7 +53,7 @@ abstract class _ModifiableList extends _ListBase { : super._withData(length, data); void operator []=(int index, E value) { - RangeError.checkValidIndex(index, this, "[]=", _length); + IndexError.check(index, _length, indexable: this, name: "[]="); _data.write(index, value); } diff --git a/sdk/lib/_internal/wasm/lib/simd_patch.dart b/sdk/lib/_internal/wasm/lib/simd_patch.dart index 83fd89d010b..5d1f2623724 100644 --- a/sdk/lib/_internal/wasm/lib/simd_patch.dart +++ b/sdk/lib/_internal/wasm/lib/simd_patch.dart @@ -147,7 +147,7 @@ class _NaiveInt32x4List extends Object int get length => _storage.length ~/ 4; Int32x4 operator [](int index) { - RangeError.checkValidIndex(index, this, "[]", length); + IndexError.check(index, length, indexable: this, name: "[]"); int _x = _storage[(index * 4) + 0]; int _y = _storage[(index * 4) + 1]; int _z = _storage[(index * 4) + 2]; @@ -156,7 +156,7 @@ class _NaiveInt32x4List extends Object } void operator []=(int index, Int32x4 value) { - RangeError.checkValidIndex(index, this, "[]=", length); + IndexError.check(index, length, indexable: this, name: "[]="); _storage[(index * 4) + 0] = value.x; _storage[(index * 4) + 1] = value.y; _storage[(index * 4) + 2] = value.z; @@ -164,7 +164,7 @@ class _NaiveInt32x4List extends Object } Int32x4List sublist(int start, [int? end]) { - RangeError.checkValidIndex(start, this, "sublist", length); + IndexError.check(start, length, indexable: this, name: "sublist"); int stop = _checkValidRange(start, end, length); return _NaiveInt32x4List._externalStorage( _storage.sublist(start * 4, stop * 4)); @@ -211,7 +211,7 @@ class _NaiveFloat32x4List extends Object int get length => _storage.length ~/ 4; Float32x4 operator [](int index) { - RangeError.checkValidIndex(index, this, "[]", length); + IndexError.check(index, length, indexable: this, name: "[]"); double _x = _storage[(index * 4) + 0]; double _y = _storage[(index * 4) + 1]; double _z = _storage[(index * 4) + 2]; @@ -220,7 +220,7 @@ class _NaiveFloat32x4List extends Object } void operator []=(int index, Float32x4 value) { - RangeError.checkValidIndex(index, this, "[]=", length); + IndexError.check(index, length, indexable: this, name: "[]="); _storage[(index * 4) + 0] = value.x; _storage[(index * 4) + 1] = value.y; _storage[(index * 4) + 2] = value.z; @@ -228,7 +228,7 @@ class _NaiveFloat32x4List extends Object } Float32x4List sublist(int start, [int? end]) { - RangeError.checkValidIndex(start, this, "sublist", length); + IndexError.check(start, length, indexable: this, name: "sublist"); int stop = _checkValidRange(start, end, length); return _NaiveFloat32x4List._externalStorage( _storage.sublist(start * 4, stop * 4)); @@ -273,20 +273,20 @@ class _NaiveFloat64x2List extends Object int get length => _storage.length ~/ 2; Float64x2 operator [](int index) { - RangeError.checkValidIndex(index, this, "[]", length); + IndexError.check(index, length, indexable: this, name: "[]"); double _x = _storage[(index * 2) + 0]; double _y = _storage[(index * 2) + 1]; return Float64x2(_x, _y); } void operator []=(int index, Float64x2 value) { - RangeError.checkValidIndex(index, this, "[]=", length); + IndexError.check(index, length, indexable: this, name: "[]="); _storage[(index * 2) + 0] = value.x; _storage[(index * 2) + 1] = value.y; } Float64x2List sublist(int start, [int? end]) { - RangeError.checkValidIndex(start, this, "sublist", length); + IndexError.check(start, length, indexable: this, name: "sublist"); int stop = _checkValidRange(start, end, length); return _NaiveFloat64x2List._externalStorage( _storage.sublist(start * 2, stop * 2)); diff --git a/sdk/lib/async/stream.dart b/sdk/lib/async/stream.dart index 038c3bb5513..cc89846b5c4 100644 --- a/sdk/lib/async/stream.dart +++ b/sdk/lib/async/stream.dart @@ -1855,7 +1855,8 @@ abstract class Stream { subscription = this.listen(null, onError: result._completeError, onDone: () { result._completeError( - new RangeError.index(index, this, "index", null, elementIndex), + new IndexError.withLength(index, elementIndex, + indexable: this, name: "index"), StackTrace.empty); }, cancelOnError: true); subscription.onData((T value) { diff --git a/sdk/lib/collection/iterable.dart b/sdk/lib/collection/iterable.dart index 5395c8dbe69..864edd7826f 100644 --- a/sdk/lib/collection/iterable.dart +++ b/sdk/lib/collection/iterable.dart @@ -205,7 +205,8 @@ abstract class IterableMixin implements Iterable { if (index == elementIndex) return element; elementIndex++; } - throw RangeError.index(index, this, "index", null, elementIndex); + throw IndexError.withLength(index, elementIndex, + indexable: this, name: "index"); } String toString() => IterableBase.iterableToShortString(this, '(', ')'); diff --git a/sdk/lib/collection/queue.dart b/sdk/lib/collection/queue.dart index fa8b785c7ed..5609528326d 100644 --- a/sdk/lib/collection/queue.dart +++ b/sdk/lib/collection/queue.dart @@ -698,7 +698,7 @@ class ListQueue extends ListIterable implements Queue { } E elementAt(int index) { - RangeError.checkValidIndex(index, this); + IndexError.check(index, length, indexable: this); return _table[(_head + index) & (_table.length - 1)] as E; } diff --git a/sdk/lib/collection/set.dart b/sdk/lib/collection/set.dart index f59b56d3071..1ba001fbb93 100644 --- a/sdk/lib/collection/set.dart +++ b/sdk/lib/collection/set.dart @@ -275,7 +275,8 @@ abstract class SetMixin implements Set { if (index == elementIndex) return element; elementIndex++; } - throw RangeError.index(index, this, "index", null, elementIndex); + throw IndexError.withLength(index, elementIndex, + indexable: this, name: "index"); } } diff --git a/sdk/lib/core/errors.dart b/sdk/lib/core/errors.dart index 7edce311be1..c78b4b8e910 100644 --- a/sdk/lib/core/errors.dart +++ b/sdk/lib/core/errors.dart @@ -313,7 +313,7 @@ class RangeError extends ArgumentError { /// /// Throws if [index] is not a valid index into [indexable]. /// - /// An indexable object is one that has a `length` and a and index-operator + /// An indexable object is one that has a `length` and an index-operator /// `[]` that accepts an index if `0 <= index < length`. /// /// If [name] or [message] are provided, they are used as the parameter @@ -324,15 +324,12 @@ class RangeError extends ArgumentError { /// otherwise the length is found as `indexable.length`. /// /// Returns [index] if it is a valid index. + @Deprecated("Use IndexError.check instead.") static int checkValidIndex(int index, dynamic indexable, [String? name, int? length, String? message]) { length ??= (indexable.length as int); - // Comparing with `0` as receiver produces better dart2js type inference. - if (0 > index || index >= length) { - name ??= "index"; - throw RangeError.index(index, indexable, name, message, length); - } - return index; + return IndexError.check(index, length, + indexable: indexable, name: name, message: message); } /// Check that a range represents a slice of an indexable object. @@ -415,7 +412,7 @@ class RangeError extends ArgumentError { /// and the invalid index itself. class IndexError extends ArgumentError implements RangeError { /// The indexable object that [invalidValue] was not a valid index into. - final indexable; + final Object? indexable; /// The length of [indexable] at the time of the error. final int length; @@ -427,12 +424,53 @@ class IndexError extends ArgumentError implements RangeError { /// If `length` is omitted, it defaults to `indexable.length`. /// /// The message is used as part of the string representation of the error. + @Deprecated("Use IndexError.withLength instead.") IndexError(int invalidValue, dynamic indexable, [String? name, String? message, int? length]) : this.indexable = indexable, + // ignore: avoid_dynamic_calls this.length = length ?? indexable.length, super.value(invalidValue, name, message ?? "Index out of range"); + /// Creates a new [IndexError] stating that [invalidValue] is not a valid index + /// into [indexable]. + /// + /// The [length] is the length of [indexable] at the time of the error. + /// + /// The message is used as part of the string representation of the error. + IndexError.withLength(int invalidValue, this.length, + {this.indexable, String? name, String? message}) + : super.value(invalidValue, name, message ?? "Index out of range"); + + /// Check that [index] is a valid index into an indexable object. + /// + /// Throws if [index] is not a valid index. + /// + /// An indexable object is one that has a `length` and an index-operator + /// `[]` that accepts an index if `0 <= index < length`. + /// + /// The [length] is the length of the indexable object. + /// + /// The [indexable], if provided, is the indexable object. + /// + /// The [name] is the parameter name of the index value. Defaults to "index", + /// and can be set to null to omit a name from the error string, + /// if the invalid index was not a parameter. + /// + /// The [message], if provided, is included in the error string. + /// + /// Returns [index] if it is a valid index. + static int check(int index, int length, + {Object? indexable, String? name, String? message}) { + // Comparing with `0` as receiver produces better dart2js type inference. + if (0 > index || index >= length) { + name ??= "index"; + throw IndexError.withLength(index, length, + indexable: indexable, name: name, message: message); + } + return index; + } + // Getters inherited from RangeError. int get start => 0; int get end => length - 1; diff --git a/sdk/lib/core/iterable.dart b/sdk/lib/core/iterable.dart index e710e73cf52..1960f2980c6 100644 --- a/sdk/lib/core/iterable.dart +++ b/sdk/lib/core/iterable.dart @@ -778,7 +778,8 @@ abstract class Iterable { if (index == elementIndex) return element; elementIndex++; } - throw RangeError.index(index, this, "index", null, elementIndex); + throw IndexError.withLength(index, elementIndex, + indexable: this, name: "index"); } /// Returns a string representation of (some of) the elements of `this`. @@ -814,7 +815,7 @@ class _GeneratorIterable extends ListIterable { _generator = generator ?? (_id as E Function(int)); E elementAt(int index) { - RangeError.checkValidIndex(index, this); + IndexError.check(index, length, indexable: this); return _generator(index); } diff --git a/sdk/lib/core/list.dart b/sdk/lib/core/list.dart index bc3ac77851a..14f91226cfa 100644 --- a/sdk/lib/core/list.dart +++ b/sdk/lib/core/list.dart @@ -346,7 +346,7 @@ abstract class List implements EfficientLengthIterable { int targetLength = target.length; for (var element in source) { if (index == targetLength) { - throw IndexError(targetLength, target); + throw IndexError.withLength(index, targetLength, indexable: target); } target[index] = element; index++; diff --git a/sdk/lib/core/string.dart b/sdk/lib/core/string.dart index d3ec0f0ed70..694ce732025 100644 --- a/sdk/lib/core/string.dart +++ b/sdk/lib/core/string.dart @@ -861,7 +861,8 @@ class RuneIterator implements BidirectionalIterator { /// Setting the position to the end of the string means that there is no /// current rune. void set rawIndex(int rawIndex) { - RangeError.checkValidIndex(rawIndex, string, "rawIndex"); + IndexError.check(rawIndex, string.length, + indexable: string, name: "rawIndex"); reset(rawIndex); moveNext(); } diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart index 26d027a6229..06db27b4b1c 100644 --- a/sdk/lib/html/dart2js/html_dart2js.dart +++ b/sdk/lib/html/dart2js/html_dart2js.dart @@ -11427,7 +11427,7 @@ class DomRectList extends JavaScriptObject Rectangle operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("Rectangle", "#[#]", this, index); } @@ -11677,7 +11677,7 @@ class DomStringList extends JavaScriptObject String operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("String", "#[#]", this, index); } @@ -16217,7 +16217,7 @@ class FileList extends JavaScriptObject File operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("File", "#[#]", this, index); } @@ -17730,7 +17730,7 @@ class HtmlCollection extends JavaScriptObject Node operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("Node", "#[#]", this, index); } @@ -22209,7 +22209,7 @@ class MimeTypeArray extends JavaScriptObject MimeType operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("MimeType", "#[#]", this, index); } @@ -23732,7 +23732,7 @@ class NodeList extends JavaScriptObject Node operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("Node", "#[#]", this, index); } @@ -25745,7 +25745,7 @@ class PluginArray extends JavaScriptObject Plugin operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("Plugin", "#[#]", this, index); } @@ -28437,7 +28437,7 @@ class SourceBufferList extends EventTarget SourceBuffer operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("SourceBuffer", "#[#]", this, index); } @@ -28594,7 +28594,7 @@ class SpeechGrammarList extends JavaScriptObject SpeechGrammar operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("SpeechGrammar", "#[#]", this, index); } @@ -30242,7 +30242,7 @@ class TextTrackCueList extends JavaScriptObject TextTrackCue operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("TextTrackCue", "#[#]", this, index); } @@ -30316,7 +30316,7 @@ class TextTrackList extends EventTarget TextTrack operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("TextTrack", "#[#]", this, index); } @@ -30585,7 +30585,7 @@ class TouchList extends JavaScriptObject Touch operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("Touch", "#[#]", this, index); } @@ -34546,7 +34546,7 @@ class _CssRuleList extends JavaScriptObject CssRule operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("CssRule", "#[#]", this, index); } @@ -34864,7 +34864,7 @@ class _GamepadList extends JavaScriptObject Gamepad? operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("Gamepad|Null", "#[#]", this, index); } @@ -35136,7 +35136,7 @@ class _NamedNodeMap extends JavaScriptObject Node operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("Node", "#[#]", this, index); } @@ -35330,7 +35330,7 @@ class _SpeechRecognitionResultList extends JavaScriptObject SpeechRecognitionResult operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("SpeechRecognitionResult", "#[#]", this, index); } @@ -35390,7 +35390,7 @@ class _StyleSheetList extends JavaScriptObject StyleSheet operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return JS("StyleSheet", "#[#]", this, index); } diff --git a/sdk/lib/internal/iterable.dart b/sdk/lib/internal/iterable.dart index 1661ccbb250..96bf7ba189a 100644 --- a/sdk/lib/internal/iterable.dart +++ b/sdk/lib/internal/iterable.dart @@ -265,7 +265,8 @@ class SubListIterable extends ListIterable { E elementAt(int index) { int realIndex = _startIndex + index; if (index < 0 || realIndex >= _endIndex) { - throw RangeError.index(index, this, "index"); + throw IndexError.withLength(index, length, + indexable: this, name: "index"); } return _iterable.elementAt(realIndex); } diff --git a/sdk/lib/internal/list.dart b/sdk/lib/internal/list.dart index fc24360bf40..5815293e349 100644 --- a/sdk/lib/internal/list.dart +++ b/sdk/lib/internal/list.dart @@ -215,7 +215,7 @@ class _ListIndicesIterable extends ListIterable { int get length => _backedList.length; int elementAt(int index) { - RangeError.checkValidIndex(index, this); + IndexError.check(index, length, indexable: this); return index; } } diff --git a/sdk/lib/svg/dart2js/svg_dart2js.dart b/sdk/lib/svg/dart2js/svg_dart2js.dart index f6309c6b977..5efb6bb040e 100644 --- a/sdk/lib/svg/dart2js/svg_dart2js.dart +++ b/sdk/lib/svg/dart2js/svg_dart2js.dart @@ -2052,7 +2052,7 @@ class LengthList extends JavaScriptObject Length operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return this.getItem(index); } @@ -2377,7 +2377,7 @@ class NumberList extends JavaScriptObject Number operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return this.getItem(index); } @@ -2860,7 +2860,7 @@ class StringList extends JavaScriptObject String operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return this.getItem(index); } @@ -3849,7 +3849,7 @@ class TransformList extends JavaScriptObject Transform operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return this.getItem(index); } diff --git a/sdk/lib/web_sql/dart2js/web_sql_dart2js.dart b/sdk/lib/web_sql/dart2js/web_sql_dart2js.dart index 584b15a3018..19b26b60433 100644 --- a/sdk/lib/web_sql/dart2js/web_sql_dart2js.dart +++ b/sdk/lib/web_sql/dart2js/web_sql_dart2js.dart @@ -225,7 +225,7 @@ class SqlResultSetRowList extends JavaScriptObject Map operator [](int index) { if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length)) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return this.item(index)!; } diff --git a/tests/corelib/errors_test.dart b/tests/corelib/errors_test.dart index b96ffea2ef2..782f8ce0a21 100644 --- a/tests/corelib/errors_test.dart +++ b/tests/corelib/errors_test.dart @@ -52,27 +52,33 @@ main() { Expect.equals( "RangeError: Index out of range: " "index should be less than 3: 42", - new RangeError.index(42, [1, 2, 3]).toString()); + new IndexError.withLength(42, 3, indexable: [1, 2, 3]).toString()); Expect.equals( "RangeError (foo): Index out of range: " "index should be less than 3: 42", - new RangeError.index(42, [1, 2, 3], "foo").toString()); + new IndexError.withLength(42, 3, indexable: [1, 2, 3], name: "foo") + .toString()); Expect.equals( "RangeError (foo): message: " "index should be less than 3: 42", - new RangeError.index(42, [1, 2, 3], "foo", "message").toString()); + new IndexError.withLength(42, 3, + indexable: [1, 2, 3], name: "foo", message: "message") + .toString()); Expect.equals( "RangeError: message: " "index should be less than 3: 42", - new RangeError.index(42, [1, 2, 3], null, "message").toString()); + new IndexError.withLength(42, 3, indexable: [1, 2, 3], message: "message") + .toString()); Expect.equals( "RangeError (foo): message: " "index should be less than 2: 42", - new RangeError.index(42, [1, 2, 3], "foo", "message", 2).toString()); + new IndexError.withLength(42, 2, + indexable: [1, 2, 3], name: "foo", message: "message") + .toString()); Expect.equals( "RangeError: Index out of range: " "index must not be negative: -5", - new RangeError.index(-5, [1, 2, 3]).toString()); + new IndexError.withLength(-5, 3, indexable: [1, 2, 3]).toString()); Expect.equals(42, ArgumentError.checkNotNull(42)); Expect.equals(42, ArgumentError.checkNotNull(42, "name")); @@ -90,10 +96,10 @@ main() { Expect.throwsRangeError(() => RangeError.checkValueInInterval(1, 1, 0)); Expect.throwsRangeError(() => RangeError.checkValueInInterval(0, 1, 0)); - Expect.equals(1, RangeError.checkValidIndex(1, [1, 2])); - Expect.equals(1, RangeError.checkValidIndex(1, null, null, 2)); - Expect.throwsRangeError(() => RangeError.checkValidIndex(1, [])); - Expect.throwsRangeError(() => RangeError.checkValidIndex(1, null, null, 1)); - Expect.throwsRangeError(() => RangeError.checkValidIndex(-1, [1, 2, 3])); - Expect.throwsRangeError(() => RangeError.checkValidIndex(-1, null, null, 3)); + Expect.equals(1, IndexError.check(1, 2, indexable: [1, 2])); + Expect.equals(1, IndexError.check(1, 2)); + Expect.throwsRangeError(() => IndexError.check(1, 0, indexable: [])); + Expect.throwsRangeError(() => IndexError.check(1, 1)); + Expect.throwsRangeError(() => IndexError.check(-1, 3, indexable: [1, 2, 3])); + Expect.throwsRangeError(() => IndexError.check(-1, 3)); } diff --git a/tests/corelib/range_error_test.dart b/tests/corelib/range_error_test.dart index 341c6a742a2..a163826c822 100644 --- a/tests/corelib/range_error_test.dart +++ b/tests/corelib/range_error_test.dart @@ -48,7 +48,8 @@ void testToString() { for (var re in [ new ArgumentError.value(value, name, message), new RangeError.value(value, name, message), - new RangeError.index(value, [], name, message), + new IndexError.withLength(value, 0, + indexable: [], name: name, message: message), new RangeError.range(value, 0, 24, name, message) ]) { var str = re.toString(); diff --git a/tests/corelib_2/errors_test.dart b/tests/corelib_2/errors_test.dart index ed1a2b7b8a2..8033bead1db 100644 --- a/tests/corelib_2/errors_test.dart +++ b/tests/corelib_2/errors_test.dart @@ -54,27 +54,33 @@ main() { Expect.equals( "RangeError: Index out of range: " "index should be less than 3: 42", - new RangeError.index(42, [1, 2, 3]).toString()); + new IndexError.withLength(42, 3, indexable: [1, 2, 3]).toString()); Expect.equals( "RangeError (foo): Index out of range: " "index should be less than 3: 42", - new RangeError.index(42, [1, 2, 3], "foo").toString()); + new IndexError.withLength(42, 3, indexable: [1, 2, 3], name: "foo") + .toString()); Expect.equals( "RangeError (foo): message: " "index should be less than 3: 42", - new RangeError.index(42, [1, 2, 3], "foo", "message").toString()); + new IndexError.withLength(42, 3, + indexable: [1, 2, 3], name: "foo", message: "message") + .toString()); Expect.equals( "RangeError: message: " "index should be less than 3: 42", - new RangeError.index(42, [1, 2, 3], null, "message").toString()); + new IndexError.withLength(42, 3, indexable: [1, 2, 3], message: "message") + .toString()); Expect.equals( "RangeError (foo): message: " "index should be less than 2: 42", - new RangeError.index(42, [1, 2, 3], "foo", "message", 2).toString()); + new IndexError.withLength(42, 2, + indexable: [1, 2, 3], name: "foo", message: "message") + .toString()); Expect.equals( "RangeError: Index out of range: " "index must not be negative: -5", - new RangeError.index(-5, [1, 2, 3]).toString()); + new IndexError.withLength(-5, 3, indexable: [1, 2, 3]).toString()); Expect.equals(42, ArgumentError.checkNotNull(42)); Expect.equals(42, ArgumentError.checkNotNull(42, "name")); @@ -92,10 +98,10 @@ main() { Expect.throwsRangeError(() => RangeError.checkValueInInterval(1, 1, 0)); Expect.throwsRangeError(() => RangeError.checkValueInInterval(0, 1, 0)); - Expect.equals(1, RangeError.checkValidIndex(1, [1, 2])); - Expect.equals(1, RangeError.checkValidIndex(1, null, null, 2)); - Expect.throwsRangeError(() => RangeError.checkValidIndex(1, [])); - Expect.throwsRangeError(() => RangeError.checkValidIndex(1, null, null, 1)); - Expect.throwsRangeError(() => RangeError.checkValidIndex(-1, [1, 2, 3])); - Expect.throwsRangeError(() => RangeError.checkValidIndex(-1, null, null, 3)); + Expect.equals(1, IndexError.check(1, 2, indexable: [1, 2])); + Expect.equals(1, IndexError.check(1, 2)); + Expect.throwsRangeError(() => IndexError.check(1, 0, indexable: [])); + Expect.throwsRangeError(() => IndexError.check(1, 1)); + Expect.throwsRangeError(() => IndexError.check(-1, 3, indexable: [1, 2, 3])); + Expect.throwsRangeError(() => IndexError.check(-1, 3)); } diff --git a/tests/corelib_2/range_error_test.dart b/tests/corelib_2/range_error_test.dart index c985baeb8cd..35f39536209 100644 --- a/tests/corelib_2/range_error_test.dart +++ b/tests/corelib_2/range_error_test.dart @@ -60,7 +60,8 @@ void testToString() { for (var re in [ new ArgumentError.value(value, name, message), new RangeError.value(value, name, message), - new RangeError.index(value, [], name, message), + new IndexError.withLength(value, 0, + indexable: [], name: name, message: message), new RangeError.range(value, 0, 24, name, message) ]) { var str = re.toString(); diff --git a/tools/dom/scripts/systemhtml.py b/tools/dom/scripts/systemhtml.py index c20bbb6d2f2..4ea618762ea 100644 --- a/tools/dom/scripts/systemhtml.py +++ b/tools/dom/scripts/systemhtml.py @@ -1484,7 +1484,7 @@ class Dart2JSBackend(HtmlDartGenerator): ' $TYPE operator[](int index) {\n' ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n' ' index, index, length))\n' - ' throw new RangeError.index(index, this);\n' + ' throw new IndexError.withLength(index, length, indexable: this);\n' ' return $INDEXED_GETTER$NULLASSERT;\n' ' }', INDEXED_GETTER=indexed_getter, diff --git a/tools/dom/scripts/systemnative.py b/tools/dom/scripts/systemnative.py index 2c2ab7c37b8..fc99793b354 100644 --- a/tools/dom/scripts/systemnative.py +++ b/tools/dom/scripts/systemnative.py @@ -749,7 +749,7 @@ class DartiumBackend(HtmlDartGenerator): blinkNativeIndexed = """ $TYPE operator[](int index) { if (index < 0 || index >= length) - throw new RangeError.index(index, this); + throw new IndexError.withLength(index, length, indexable: this); return _nativeIndexedGetter(index); } @@ -813,7 +813,7 @@ class DartiumBackend(HtmlDartGenerator): '\n' ' $TYPE operator[](int index) {\n' ' if (index < 0 || index >= length)\n' - ' throw new RangeError.index(index, this);\n' + ' throw new IndexError.withLength(index, length, indexable: this);\n' ' return $INDEXED_GETTER(index);\n' ' }\n', TYPE=dart_element_type,