diff --git a/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets b/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets index 849e88064624475c9ee74e9f3c6b75e7b9125868..2091bd3574284b6a3ca2f6608c54e174bf81bb86 100644 --- a/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets +++ b/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets @@ -1754,9 +1754,6 @@ export final class Int16Array implements Iterable, ArrayLike { throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } - if (intByteLength % Int16Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of 2 as Int16Array.BYTES_PER_ELEMENT") - } if (intByteOffset % Int16Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of 2 as Int16Array.BYTES_PER_ELEMENT") } @@ -3382,9 +3379,6 @@ export final class Int32Array implements Iterable, ArrayLike { throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } - if (intByteLength % Int32Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of 4 as Int32Array.BYTES_PER_ELEMENT") - } if (intByteOffset % Int32Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of 4 as Int32Array.BYTES_PER_ELEMENT") } @@ -4967,9 +4961,6 @@ export final class BigInt64Array implements Iterable, ArrayLike throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } - if (intByteLength % BigInt64Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of 8 as BigInt64Array.BYTES_PER_ELEMENT") - } if (intByteOffset % BigInt64Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of 8 as BigInt64Array.BYTES_PER_ELEMENT") } @@ -6574,9 +6565,6 @@ export final class Float32Array implements Iterable, ArrayLike { throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } - if (intByteLength % Float32Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of 4 as Float32Array.BYTES_PER_ELEMENT") - } if (intByteOffset % Float32Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of 4 as Float32Array.BYTES_PER_ELEMENT") } @@ -8167,9 +8155,6 @@ export final class Float64Array implements Iterable, ArrayLike { throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } - if (intByteLength % Float64Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of 8 as Float64Array.BYTES_PER_ELEMENT") - } if (intByteOffset % Float64Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of 8 as Float64Array.BYTES_PER_ELEMENT") } diff --git a/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets b/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets index 15d9a06db7c7e029d781320a632598979eaae97c..77de5230e01bd741c9eb4ed25fa8600d65dde54f 100644 --- a/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets +++ b/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets @@ -3365,9 +3365,6 @@ export final class Uint16Array implements Iterable, ArrayLike { throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } - if (intByteLength % Uint16Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of 2 as Uint16Array.BYTES_PER_ELEMENT") - } if (intByteOffset % Uint16Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of 2 as Uint16Array.BYTES_PER_ELEMENT") } @@ -4974,9 +4971,6 @@ export final class Uint32Array implements Iterable, ArrayLike { throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } - if (intByteLength % Uint32Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of 4 as Uint32Array.BYTES_PER_ELEMENT") - } if (intByteOffset % Uint32Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of 4 as Uint32Array.BYTES_PER_ELEMENT") } @@ -6601,9 +6595,6 @@ export final class BigUint64Array implements Iterable, ArrayLike throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } - if (intByteLength % BigUint64Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of 8 as BigUint64Array.BYTES_PER_ELEMENT") - } if (intByteOffset % BigUint64Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of 8 as BigUint64Array.BYTES_PER_ELEMENT") } diff --git a/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 b/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 index 48e399041053ff77d1b2925043cb7fab06fd4379..cb924b099941c9354ee6d09c6605a92fd7d2f84a 100644 --- a/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 +++ b/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 @@ -174,9 +174,6 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } {% if S != 1 %} - if (intByteLength % {{N}}Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of {{S}} as {{N}}Array.BYTES_PER_ELEMENT") - } if (intByteOffset % {{N}}Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of {{S}} as {{N}}Array.BYTES_PER_ELEMENT") } diff --git a/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 b/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 index 70f2d21ee982617f01cec5b8a69fb59769f1ecf3..252cdb62f6965388751554ca0c266dedd12251de 100644 --- a/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 +++ b/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 @@ -186,9 +186,6 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse throw new RangeError("Range Error: byteLength " + intByteLength + " is outside the bounds of the buffer with byteOffset " + intByteOffset) } {% if element.get('bytes') != 1 %} - if (intByteLength % {{element['name']}}Array.BYTES_PER_ELEMENT.toInt() != 0) { - throw new RangeError("ArrayBuffer.byteLength should be multiple of {{element['bytes']}} as {{element['name']}}Array.BYTES_PER_ELEMENT") - } if (intByteOffset % {{element['name']}}Array.BYTES_PER_ELEMENT != 0) { throw new RangeError("byteOffset should be multiple of {{element['bytes']}} as {{element['name']}}Array.BYTES_PER_ELEMENT") } diff --git a/static_core/plugins/ets/tests/ets_func_tests/std/core/TypedArrayConstructorNumbersInts.ets b/static_core/plugins/ets/tests/ets_func_tests/std/core/TypedArrayConstructorNumbersInts.ets index 1575fea135c27e6b6dace96f24b9fbd2f9652da2..666d5e3a9d7434f33faf8e1195bee959e3da13e0 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/std/core/TypedArrayConstructorNumbersInts.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/std/core/TypedArrayConstructorNumbersInts.ets @@ -111,6 +111,26 @@ function testArrayConstructorsFromNumbersInts(): int { "1,2,3,4,5,4294967295,4294901760", "Uint32Array(int[])" ) + const buffer1 = new ArrayBuffer(17); + const array1 = new Uint32Array(buffer1, 0, 2); + array1[0] = 42; + array1[1] = 100; + failures += test( + array1.toString(), + "42,100", + "Uint32Array(ArrayBuffer, byteOffset, length) with values" + ) + const buffer2 = new ArrayBuffer(41); + const array2 = new Uint32Array(buffer2, 8, 3); + array2[0] = 1; + array2[1] = 4294967295; + array2[2] = 4294901760; + failures += test( + array2.toString(), + "1,4294967295,4294901760", + "Uint32Array(ArrayBuffer, byteOffset, length) with values" + ) + failures += test( (new Uint8Array(nums)).toString(),