From 3d0eff8ab1e5fe35d0904b59260cc3fbf77768b8 Mon Sep 17 00:00:00 2001 From: qiu_yu_jia Date: Thu, 28 Aug 2025 13:47:37 +0800 Subject: [PATCH] TypedArray and TypedUArray number2int Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICV7G9 Signed-off-by: qiu_yu_jia --- .../ets/runtime/ets_libbase_runtime.yaml | 22 +- .../ets/stdlib/escompat/TypedArrays.ets | 1595 ++--------------- .../ets/stdlib/escompat/TypedUArrays.ets | 1304 +------------- .../ets/templates/stdlib/typedArray.ets.j2 | 275 +-- .../ets/templates/stdlib/typedUArray.ets.j2 | 258 +-- .../tests/ets_es_checked/float32array.yaml | 4 +- .../tests/ets_es_checked/float64array.yaml | 4 +- .../ets/tests/ets_es_checked/int16array.yaml | 4 +- .../ets/tests/ets_es_checked/int32array.yaml | 4 +- .../ets/tests/ets_es_checked/int8array.yaml | 4 +- .../ets/tests/ets_es_checked/uint16array.yaml | 4 +- .../ets/tests/ets_es_checked/uint32array.yaml | 4 +- .../ets/tests/ets_es_checked/uint8array.yaml | 4 +- .../ets_es_checked/uint8clampedarray.yaml | 4 +- .../utils/test_core_typedarray_function2.j2 | 4 +- .../utils/test_core_typedarray_slicing.j2 | 4 +- .../utils/test_core_typeduarray_function2.j2 | 4 +- .../utils/test_core_typeduarray_slicing.j2 | 4 +- 18 files changed, 291 insertions(+), 3215 deletions(-) diff --git a/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml b/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml index 1f6af1d923..a8729da5b8 100644 --- a/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml +++ b/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml @@ -3020,7 +3020,7 @@ intrinsics: - name: Int8ArrayCopyWithin space: ets class_name: escompat.Int8Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Int8Array @@ -3030,7 +3030,7 @@ intrinsics: - name: Int16ArrayCopyWithin space: ets class_name: escompat.Int16Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Int16Array @@ -3040,7 +3040,7 @@ intrinsics: - name: Int32ArrayCopyWithin space: ets class_name: escompat.Int32Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Int32Array @@ -3050,7 +3050,7 @@ intrinsics: - name: BigInt64ArrayCopyWithin space: ets class_name: escompat.BigInt64Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.BigInt64Array @@ -3060,7 +3060,7 @@ intrinsics: - name: Float32ArrayCopyWithin space: ets class_name: escompat.Float32Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Float32Array @@ -3070,7 +3070,7 @@ intrinsics: - name: Float64ArrayCopyWithin space: ets class_name: escompat.Float64Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Float64Array @@ -3080,7 +3080,7 @@ intrinsics: - name: UInt8ArrayCopyWithin space: ets class_name: escompat.Uint8Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Uint8Array @@ -3090,7 +3090,7 @@ intrinsics: - name: UInt16ArrayCopyWithin space: ets class_name: escompat.Uint16Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Uint16Array @@ -3100,7 +3100,7 @@ intrinsics: - name: UInt32ArrayCopyWithin space: ets class_name: escompat.Uint32Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Uint32Array @@ -3110,7 +3110,7 @@ intrinsics: - name: BigUInt64ArrayCopyWithin space: ets class_name: escompat.BigUint64Array - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.BigUint64Array @@ -3120,7 +3120,7 @@ intrinsics: - name: UInt8ClampedArrayCopyWithin space: ets class_name: escompat.Uint8ClampedArray - method_name: copyWithin + method_name: copyWithinInternal static: false signature: ret: escompat.Uint8ClampedArray diff --git a/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets b/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets index bdf49e0099..f33094dfbb 100644 --- a/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets +++ b/static_core/plugins/ets/stdlib/escompat/TypedArrays.ets @@ -86,7 +86,6 @@ class Int8ArrayIteratorEntries implements IterableIterator<[Number, Number]> { export final class Int8Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 1 public readonly BYTES_PER_ELEMENT: int = Int8Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } protected readonly lengthInt: int /** @@ -349,17 +348,6 @@ export final class Int8Array implements Iterable, ArrayLike { */ public native $_get(index: int): number - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index. * @@ -391,53 +379,8 @@ export final class Int8Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): Int8Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): Int8Array { - return this.copyWithin(target, start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): Int8Array { - return this.copyWithin(target.toInt(), start, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): Int8Array { - return this.copyWithin(target, start, asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): Int8Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -451,19 +394,7 @@ export final class Int8Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): Int8Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of Int8Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): Int8Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): Int8Array /** * Makes a copy of internal elements to targetPos from begin to end of Int8Array. @@ -474,7 +405,7 @@ export final class Int8Array implements Iterable, ArrayLike { * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): Int8Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -493,84 +424,11 @@ export final class Int8Array implements Iterable, ArrayLike { * * @returns modified Int8Array */ - public fill(value: number, start?: number, end?: number): this { - value = this.zeroIfInfinity(value) - this.fill(value.toByte(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Int8Array with specified value - * - * @param value new valuy - * - * @returns modified Int8Array - */ - public fill(value: number, start: int, end?: number): this { - value = this.zeroIfInfinity(value) - this.fill(value.toByte(), start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Int8Array with specified value - * - * @param value new valuy - * - * @returns modified Int8Array - */ - public fill(value: number, start: number, end: int): this { + public fill(value: number, start?: int, end?: int): this { value = this.zeroIfInfinity(value) - this.fill(value.toByte(), start.toInt(), end) - return this - } - - /** - * Fills the Int8Array with specified value - * - * @param value new valuy - * - * @returns modified Int8Array - */ - public fill(value: number, start: int, end: int): this { - value = this.zeroIfInfinity(value) - this.fill(value.toByte(), start, end) - return this - } - - /** - * Fills the Int8Array with specified value - * - * @param value new valuy - * - * @returns modified Int8Array - */ - public fill(value: byte, start?: number, end?: number): this { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Int8Array with specified value - * - * @param value new valuy - * - * @returns modified Int8Array - */ - public fill(value: byte, start: int, end?: number): this { - this.fill(value, start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Int8Array with specified value - * - * @param value new valuy - * - * @returns modified Int8Array - */ - public fill(value: byte, start: number, end: int): this { - this.fill(value, start.toInt(), end) + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value.toByte(), k, finalPos) return this } @@ -581,9 +439,9 @@ export final class Int8Array implements Iterable, ArrayLike { * * @returns modified Int8Array */ - public fill(value: byte, start: int, end: int): this { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) + public fill(value: byte, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) this.fillInternal(value, k, finalPos) return this } @@ -1182,55 +1040,10 @@ export final class Int8Array implements Iterable, ArrayLike { * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): Int8Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current Int8Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int8Array with elements of current Int8Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): Int8Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Int8Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int8Array with elements of current Int8Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): Int8Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Int8Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int8Array with elements of current Int8Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): Int8Array { + public slice(begin?: int, end?: int): Int8Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? this.lengthInt, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -1259,46 +1072,7 @@ export final class Int8Array implements Iterable, ArrayLike { * * @returns new Int8Array with the same underlying ArrayBuffer */ - public subarrayNN(begin?: number, end?: number): Int8Array { - return this.subarray(asIntOrDefault(begin, 0 as int), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Int8Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int8Array with the same underlying ArrayBuffer - */ - public subarrayIN(begin?: int, end?: number): Int8Array { - return this.subarray(begin ?? 0, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Int8Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int8Array with the same underlying ArrayBuffer - */ - public subarrayNI(begin?: number, end?: int): Int8Array { - return this.subarray(asIntOrDefault(begin, 0 as int), end ?? this.lengthInt) - } - - /** - * Creates a Int8Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int8Array with the same underlying ArrayBuffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): Int8Array { + public subarray(begin?: int, end?: int): Int8Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) @@ -1833,7 +1607,6 @@ class Int16ArrayIteratorEntries implements IterableIterator<[Number, Number]> { export final class Int16Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 2 public readonly BYTES_PER_ELEMENT: int = Int16Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } protected readonly lengthInt: int /** @@ -2103,17 +1876,6 @@ export final class Int16Array implements Iterable, ArrayLike { */ public native $_get(index: int): number - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index. * @@ -2145,53 +1907,8 @@ export final class Int16Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): Int16Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): Int16Array { - return this.copyWithin(target, start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): Int16Array { - return this.copyWithin(target.toInt(), start, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): Int16Array { - return this.copyWithin(target, start, asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): Int16Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -2205,19 +1922,7 @@ export final class Int16Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): Int16Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of Int16Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): Int16Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): Int16Array /** * Makes a copy of internal elements to targetPos from begin to end of Int16Array. @@ -2228,7 +1933,7 @@ export final class Int16Array implements Iterable, ArrayLike { * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): Int16Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -2247,9 +1952,11 @@ export final class Int16Array implements Iterable, ArrayLike { * * @returns modified Int16Array */ - public fill(value: number, start?: number, end?: number): this { + public fill(value: number, start?: int, end?: int): this { value = this.zeroIfInfinity(value) - this.fill(value.toShort(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value.toShort(), k, finalPos) return this } @@ -2260,85 +1967,10 @@ export final class Int16Array implements Iterable, ArrayLike { * * @returns modified Int16Array */ - public fill(value: number, start: int, end?: number): this { - value = this.zeroIfInfinity(value) - this.fill(value.toShort(), start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Int16Array with specified value - * - * @param value new valuy - * - * @returns modified Int16Array - */ - public fill(value: number, start: number, end: int): this { - value = this.zeroIfInfinity(value) - this.fill(value.toShort(), start.toInt(), end) - return this - } - - /** - * Fills the Int16Array with specified value - * - * @param value new valuy - * - * @returns modified Int16Array - */ - public fill(value: number, start: int, end: int): this { - value = this.zeroIfInfinity(value) - this.fill(value.toShort(), start, end) - return this - } - - /** - * Fills the Int16Array with specified value - * - * @param value new valuy - * - * @returns modified Int16Array - */ - public fill(value: short, start?: number, end?: number): this { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Int16Array with specified value - * - * @param value new valuy - * - * @returns modified Int16Array - */ - public fill(value: short, start: int, end?: number): this { - this.fill(value, start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Int16Array with specified value - * - * @param value new valuy - * - * @returns modified Int16Array - */ - public fill(value: short, start: number, end: int): this { - this.fill(value, start.toInt(), end) - return this - } - - /** - * Fills the Int16Array with specified value - * - * @param value new valuy - * - * @returns modified Int16Array - */ - public fill(value: short, start: int, end: int): this { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) - this.fillInternal(value, k, finalPos) + public fill(value: short, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value, k, finalPos) return this } @@ -2936,55 +2568,10 @@ export final class Int16Array implements Iterable, ArrayLike { * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): Int16Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current Int16Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int16Array with elements of current Int16Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): Int16Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Int16Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int16Array with elements of current Int16Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): Int16Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Int16Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int16Array with elements of current Int16Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): Int16Array { + public slice(begin?: int, end?: int): Int16Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? this.lengthInt, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -3013,46 +2600,7 @@ export final class Int16Array implements Iterable, ArrayLike { * * @returns new Int16Array with the same underlying ArrayBuffer */ - public subarrayNN(begin?: number, end?: number): Int16Array { - return this.subarray(asIntOrDefault(begin, 0 as int), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Int16Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int16Array with the same underlying ArrayBuffer - */ - public subarrayIN(begin?: int, end?: number): Int16Array { - return this.subarray(begin ?? 0, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Int16Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int16Array with the same underlying ArrayBuffer - */ - public subarrayNI(begin?: number, end?: int): Int16Array { - return this.subarray(asIntOrDefault(begin, 0 as int), end ?? this.lengthInt) - } - - /** - * Creates a Int16Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int16Array with the same underlying ArrayBuffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): Int16Array { + public subarray(begin?: int, end?: int): Int16Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) @@ -3600,7 +3148,6 @@ class Int32ArrayIteratorEntries implements IterableIterator<[Number, Number]> { export final class Int32Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 4 public readonly BYTES_PER_ELEMENT: int = Int32Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } protected readonly lengthInt: int /** @@ -3861,17 +3408,6 @@ export final class Int32Array implements Iterable, ArrayLike { */ public native $_get(index: int): number - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index. * @@ -3903,53 +3439,8 @@ export final class Int32Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): Int32Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): Int32Array { - return this.copyWithin(target, start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): Int32Array { - return this.copyWithin(target.toInt(), start, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): Int32Array { - return this.copyWithin(target, start, asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): Int32Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -3963,19 +3454,7 @@ export final class Int32Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): Int32Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of Int32Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): Int32Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): Int32Array /** * Makes a copy of internal elements to targetPos from begin to end of Int32Array. @@ -3986,7 +3465,7 @@ export final class Int32Array implements Iterable, ArrayLike { * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): Int32Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -4005,9 +3484,11 @@ export final class Int32Array implements Iterable, ArrayLike { * * @returns modified Int32Array */ - public fill(value: number, start?: number, end?: number): this { + public fill(value: number, start?: int, end?: int): this { value = this.zeroIfInfinity(value) - this.fill(value.toInt(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value.toInt(), k, finalPos) return this } @@ -4018,152 +3499,77 @@ export final class Int32Array implements Iterable, ArrayLike { * * @returns modified Int32Array */ - public fill(value: number, start: int, end?: number): this { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start, asIntOrDefault(end, this.lengthInt)) + public fill(value: int, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value, k, finalPos) return this } + private final native fillInternal(value: int, start: int, end: int): void + /** - * Fills the Int32Array with specified value + * Assigns val as element on insertPos. + * @description Added to avoid (un)packing a single value into array to use overloaded set(FixedArray, insertPos) * - * @param value new valuy + * @param val value to set * - * @returns modified Int32Array + * @param insertPos index to change */ - public fill(value: number, start: number, end: int): this { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start.toInt(), end) - return this + public set(insertPos: number, val: number): void { + this.$_set(insertPos.toInt(), val) } /** - * Fills the Int32Array with specified value + * Assigns val as element on insertPos. + * @description Added to avoid (un)packing a single value into array to use overloaded set(FixedArray, insertPos) * - * @param value new valuy + * @param val value to set * - * @returns modified Int32Array + * @param insertPos index to change */ - public fill(value: number, start: int, end: int): this { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start, end) - return this + public set(insertPos: int, val: int): void { + this.$_set(insertPos, val) } /** - * Fills the Int32Array with specified value + * Copies all elements of arr to the current Int32Array starting from insertPos. * - * @param value new valuy + * @param arr array to copy data from * - * @returns modified Int32Array + * @param insertPos start index where data from arr will be inserted + * + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set} */ - public fill(value: int, start?: number, end?: number): this { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this + public set(arr: FixedArray, insertPos: number): void { + const offset = insertPos.toInt() + if (offset < 0 || offset + arr.length > this.lengthInt) { + throw new RangeError("offset is out of bounds") + } + for (let i = 0; i < arr.length.toInt(); ++i) { + let v = this.zeroIfInfinity(arr[i]) + this.$_set(offset + i, v.toInt()) + } } /** - * Fills the Int32Array with specified value + * Copies all elements of arr to the current Int32Array starting from insertPos. * - * @param value new valuy + * @param arr array to copy data from * - * @returns modified Int32Array + * @param insertPos start index where data from arr will be inserted + * + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set} */ - public fill(value: int, start: int, end?: number): this { - this.fill(value, start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Int32Array with specified value - * - * @param value new valuy - * - * @returns modified Int32Array - */ - public fill(value: int, start: number, end: int): this { - this.fill(value, start.toInt(), end) - return this - } - - /** - * Fills the Int32Array with specified value - * - * @param value new valuy - * - * @returns modified Int32Array - */ - public fill(value: int, start: int, end: int): this { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) - this.fillInternal(value, k, finalPos) - return this - } - - private final native fillInternal(value: int, start: int, end: int): void - - /** - * Assigns val as element on insertPos. - * @description Added to avoid (un)packing a single value into array to use overloaded set(FixedArray, insertPos) - * - * @param val value to set - * - * @param insertPos index to change - */ - public set(insertPos: number, val: number): void { - this.$_set(insertPos.toInt(), val) - } - - /** - * Assigns val as element on insertPos. - * @description Added to avoid (un)packing a single value into array to use overloaded set(FixedArray, insertPos) - * - * @param val value to set - * - * @param insertPos index to change - */ - public set(insertPos: int, val: int): void { - this.$_set(insertPos, val) - } - - /** - * Copies all elements of arr to the current Int32Array starting from insertPos. - * - * @param arr array to copy data from - * - * @param insertPos start index where data from arr will be inserted - * - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set} - */ - public set(arr: FixedArray, insertPos: number): void { - const offset = insertPos.toInt() - if (offset < 0 || offset + arr.length > this.lengthInt) { - throw new RangeError("offset is out of bounds") - } - for (let i = 0; i < arr.length.toInt(); ++i) { - let v = this.zeroIfInfinity(arr[i]) - this.$_set(offset + i, v.toInt()) - } - } - - /** - * Copies all elements of arr to the current Int32Array starting from insertPos. - * - * @param arr array to copy data from - * - * @param insertPos start index where data from arr will be inserted - * - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set} - */ - public set(arr: FixedArray, insertPos: int): void { - const offset = insertPos - if (offset < 0 || offset + arr.length > this.lengthInt) { - throw new RangeError("offset is out of bounds") - } - for (let i = 0; i < arr.length.toInt(); ++i) { - let v = this.zeroIfInfinity(arr[i]) - this.$_set(offset + i, v) - } + public set(arr: FixedArray, insertPos: int): void { + const offset = insertPos + if (offset < 0 || offset + arr.length > this.lengthInt) { + throw new RangeError("offset is out of bounds") + } + for (let i = 0; i < arr.length.toInt(); ++i) { + let v = this.zeroIfInfinity(arr[i]) + this.$_set(offset + i, v) + } } /** @@ -4667,55 +4073,10 @@ export final class Int32Array implements Iterable, ArrayLike { * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): Int32Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current Int32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int32Array with elements of current Int32Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): Int32Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Int32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int32Array with elements of current Int32Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): Int32Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Int32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Int32Array with elements of current Int32Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): Int32Array { + public slice(begin?: int, end?: int): Int32Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? this.lengthInt, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -4744,46 +4105,7 @@ export final class Int32Array implements Iterable, ArrayLike { * * @returns new Int32Array with the same underlying ArrayBuffer */ - public subarrayNN(begin?: number, end?: number): Int32Array { - return this.subarray(asIntOrDefault(begin, 0 as int), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Int32Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int32Array with the same underlying ArrayBuffer - */ - public subarrayIN(begin?: int, end?: number): Int32Array { - return this.subarray(begin ?? 0, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Int32Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int32Array with the same underlying ArrayBuffer - */ - public subarrayNI(begin?: number, end?: int): Int32Array { - return this.subarray(asIntOrDefault(begin, 0 as int), end ?? this.lengthInt) - } - - /** - * Creates a Int32Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Int32Array with the same underlying ArrayBuffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): Int32Array { + public subarray(begin?: int, end?: int): Int32Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) @@ -5331,7 +4653,6 @@ class BigInt64ArrayIteratorEntries implements IterableIterator<[Number, BigInt]> export final class BigInt64Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 8 public readonly BYTES_PER_ELEMENT: int = BigInt64Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } protected readonly lengthInt: int /** @@ -5585,17 +4906,6 @@ export final class BigInt64Array implements Iterable, ArrayLike private native getLong(index: int): long - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): BigInt | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index. * @@ -5627,38 +4937,8 @@ export final class BigInt64Array implements Iterable, ArrayLike * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): BigInt64Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): BigInt64Array { - return this.copyWithin(target, start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): BigInt64Array { - return this.copyWithin(target.toInt(), start, asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): BigInt64Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -5672,34 +4952,7 @@ export final class BigInt64Array implements Iterable, ArrayLike * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: int, start: int, end?: number): BigInt64Array { - return this.copyWithin(target, start, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public native copyWithin(target: int, start: int, end: int): BigInt64Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of BigInt64Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): BigInt64Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): BigInt64Array /** * Makes a copy of internal elements to targetPos from begin to end of BigInt64Array. @@ -5710,7 +4963,7 @@ export final class BigInt64Array implements Iterable, ArrayLike * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): BigInt64Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -5729,56 +4982,10 @@ export final class BigInt64Array implements Iterable, ArrayLike * * @returns modified BigInt64Array */ - public fill(value: BigInt, start?: number, end?: number): this { - this.fill(value.getLong(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the BigInt64Array with specified value - * - * @param value new valuy - * - * @returns modified BigInt64Array - */ - public fill(value: BigInt, start: int, end?: number): this { - this.fill(value.getLong(), start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the BigInt64Array with specified value - * - * @param value new valuy - * - * @returns modified BigInt64Array - */ - public fill(value: BigInt, start: number, end: int): this { - this.fill(value.getLong(), start.toInt(), end) - return this - } - - /** - * Fills the BigInt64Array with specified value - * - * @param value new valuy - * - * @returns modified BigInt64Array - */ - public fill(value: BigInt, start: int, end: int): this { - this.fill(value.getLong(), start, end) - return this - } - - /** - * Fills the BigInt64Array with specified value - * - * @param value new valuy - * - * @returns modified BigInt64Array - */ - public fill(value: long, start?: number, end?: number): this { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) + public fill(value: BigInt, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value.getLong(), k, finalPos) return this } @@ -5789,33 +4996,9 @@ export final class BigInt64Array implements Iterable, ArrayLike * * @returns modified BigInt64Array */ - public fill(value: long, start: int, end?: number): this { - this.fill(value, start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the BigInt64Array with specified value - * - * @param value new valuy - * - * @returns modified BigInt64Array - */ - public fill(value: long, start: number, end: int): this { - this.fill(value, start.toInt(), end) - return this - } - - /** - * Fills the BigInt64Array with specified value - * - * @param value new valuy - * - * @returns modified BigInt64Array - */ - public fill(value: long, start: int, end: int): this { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) + public fill(value: long, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) this.fillInternal(value, k, finalPos) return this } @@ -6411,55 +5594,10 @@ export final class BigInt64Array implements Iterable, ArrayLike * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): BigInt64Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current BigInt64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new BigInt64Array with elements of current BigInt64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): BigInt64Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current BigInt64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new BigInt64Array with elements of current BigInt64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): BigInt64Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current BigInt64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new BigInt64Array with elements of current BigInt64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): BigInt64Array { + public slice(begin?: int, end?: int): BigInt64Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? this.lengthInt, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -6488,46 +5626,7 @@ export final class BigInt64Array implements Iterable, ArrayLike * * @returns new BigInt64Array with the same underlying ArrayBuffer */ - public subarrayNN(begin?: number, end?: number): BigInt64Array { - return this.subarray(asIntOrDefault(begin, 0 as int), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a BigInt64Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new BigInt64Array with the same underlying ArrayBuffer - */ - public subarrayIN(begin?: int, end?: number): BigInt64Array { - return this.subarray(begin ?? 0, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a BigInt64Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new BigInt64Array with the same underlying ArrayBuffer - */ - public subarrayNI(begin?: number, end?: int): BigInt64Array { - return this.subarray(asIntOrDefault(begin, 0 as int), end ?? this.lengthInt) - } - - /** - * Creates a BigInt64Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new BigInt64Array with the same underlying ArrayBuffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): BigInt64Array { + public subarray(begin?: int, end?: int): BigInt64Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) @@ -7079,7 +6178,6 @@ class Float32ArrayIteratorEntries implements IterableIterator<[Number, Number]> export final class Float32Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 4 public readonly BYTES_PER_ELEMENT: int = Float32Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } protected readonly lengthInt: int /** @@ -7319,17 +6417,6 @@ export final class Float32Array implements Iterable, ArrayLike { */ public native $_get(index: int): number - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index. * @@ -7361,23 +6448,8 @@ export final class Float32Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): Float32Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): Float32Array { - return this.copyWithin(target, start.toInt(), asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): Float32Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -7390,142 +6462,28 @@ export final class Float32Array implements Iterable, ArrayLike { * @param end last index to end copy from, excluded * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): Float32Array { - return this.copyWithin(target.toInt(), start, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): Float32Array { - return this.copyWithin(target, start, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public native copyWithin(target: int, start: int, end: int): Float32Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of Float32Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): Float32Array { - return this.copyWithin(target.toInt()) - } - - /** - * Makes a copy of internal elements to targetPos from begin to end of Float32Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: int): Float32Array { - return this.copyWithin(target, 0, this.lengthInt) - } - - /** - * Returns an array of key, value pairs for every entry in the Float32Array - * - * @returns key, value pairs for every entry in the array - */ - public entries(): IterableIterator<[Number, Number]> { - return new Float32ArrayIteratorEntries(this) - } - - /** - * Fills the Float32Array with specified value - * - * @param value new valuy - * - * @returns modified Float32Array - */ - public fill(value: number, start?: number, end?: number): this { - this.fill(value.toFloat(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Float32Array with specified value - * - * @param value new valuy - * - * @returns modified Float32Array - */ - public fill(value: number, start: int, end?: number): this { - this.fill(value.toFloat(), start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Float32Array with specified value - * - * @param value new valuy - * - * @returns modified Float32Array - */ - public fill(value: number, start: number, end: int): this { - this.fill(value.toFloat(), start.toInt(), end) - return this - } - - /** - * Fills the Float32Array with specified value - * - * @param value new valuy - * - * @returns modified Float32Array - */ - public fill(value: number, start: int, end: int): this { - this.fill(value.toFloat(), start, end) - return this - } + */ + private native copyWithinInternal(target: int, start: int, end: int): Float32Array /** - * Fills the Float32Array with specified value + * Makes a copy of internal elements to targetPos from begin to end of Float32Array. * - * @param value new valuy + * @param target insert index to place copied elements * - * @returns modified Float32Array + * See rules of parameters normalization: + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ - public fill(value: float, start?: number, end?: number): this { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this + public copyWithin(target: int): Float32Array { + return this.copyWithinInternal(target, 0, this.lengthInt) } /** - * Fills the Float32Array with specified value - * - * @param value new valuy + * Returns an array of key, value pairs for every entry in the Float32Array * - * @returns modified Float32Array + * @returns key, value pairs for every entry in the array */ - public fill(value: float, start: int, end?: number): this { - this.fill(value, start, asIntOrDefault(end, this.lengthInt)) - return this + public entries(): IterableIterator<[Number, Number]> { + return new Float32ArrayIteratorEntries(this) } /** @@ -7535,8 +6493,10 @@ export final class Float32Array implements Iterable, ArrayLike { * * @returns modified Float32Array */ - public fill(value: float, start: number, end: int): this { - this.fill(value, start.toInt(), end) + public fill(value: number, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value.toFloat(), k, finalPos) return this } @@ -7547,9 +6507,9 @@ export final class Float32Array implements Iterable, ArrayLike { * * @returns modified Float32Array */ - public fill(value: float, start: int, end: int): this { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) + public fill(value: float, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) this.fillInternal(value, k, finalPos) return this } @@ -8132,55 +7092,10 @@ export final class Float32Array implements Iterable, ArrayLike { * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): Float32Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current Float32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Float32Array with elements of current Float32Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): Float32Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Float32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Float32Array with elements of current Float32Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): Float32Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Float32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Float32Array with elements of current Float32Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): Float32Array { + public slice(begin?: int, end?: int): Float32Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? this.lengthInt, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -8209,46 +7124,7 @@ export final class Float32Array implements Iterable, ArrayLike { * * @returns new Float32Array with the same underlying ArrayBuffer */ - public subarrayNN(begin?: number, end?: number): Float32Array { - return this.subarray(asIntOrDefault(begin, 0 as int), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Float32Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Float32Array with the same underlying ArrayBuffer - */ - public subarrayIN(begin?: int, end?: number): Float32Array { - return this.subarray(begin ?? 0, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Float32Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Float32Array with the same underlying ArrayBuffer - */ - public subarrayNI(begin?: number, end?: int): Float32Array { - return this.subarray(asIntOrDefault(begin, 0 as int), end ?? this.lengthInt) - } - - /** - * Creates a Float32Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Float32Array with the same underlying ArrayBuffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): Float32Array { + public subarray(begin?: int, end?: int): Float32Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) @@ -8813,7 +7689,6 @@ class Float64ArrayIteratorEntries implements IterableIterator<[Number, Number]> export final class Float64Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 8 public readonly BYTES_PER_ELEMENT: int = Float64Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } protected readonly lengthInt: int /** @@ -9042,17 +7917,6 @@ export final class Float64Array implements Iterable, ArrayLike { */ public native $_get(index: int): number - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index. * @@ -9084,38 +7948,8 @@ export final class Float64Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): Float64Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): Float64Array { - return this.copyWithin(target, start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): Float64Array { - return this.copyWithin(target.toInt(), start, asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): Float64Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -9129,34 +7963,7 @@ export final class Float64Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: int, start: int, end?: number): Float64Array { - return this.copyWithin(target, start, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public native copyWithin(target: int, start: int, end: int): Float64Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of Float64Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): Float64Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): Float64Array /** * Makes a copy of internal elements to targetPos from begin to end of Float64Array. @@ -9167,7 +7974,7 @@ export final class Float64Array implements Iterable, ArrayLike { * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): Float64Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -9186,46 +7993,10 @@ export final class Float64Array implements Iterable, ArrayLike { * * @returns modified Float64Array */ - public fill(value: number, start?: number, end?: number): this { - this.fill(value.toDouble(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Float64Array with specified value - * - * @param value new valuy - * - * @returns modified Float64Array - */ - public fill(value: number, start: int, end?: number): this { - this.fill(value.toDouble(), start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Float64Array with specified value - * - * @param value new valuy - * - * @returns modified Float64Array - */ - public fill(value: number, start: number, end: int): this { - this.fill(value.toDouble(), start.toInt(), end) - return this - } - - /** - * Fills the Float64Array with specified value - * - * @param value new valuy - * - * @returns modified Float64Array - */ - public fill(value: double, start: int, end: int): this { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) - this.fillInternal(value, k, finalPos) + public fill(value: number, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value.toDouble(), k, finalPos) return this } @@ -9758,55 +8529,10 @@ export final class Float64Array implements Iterable, ArrayLike { * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): Float64Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current Float64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Float64Array with elements of current Float64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): Float64Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Float64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Float64Array with elements of current Float64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): Float64Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Float64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Float64Array with elements of current Float64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): Float64Array { + public slice(begin?: int, end?: int): Float64Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? this.lengthInt, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -9835,46 +8561,7 @@ export final class Float64Array implements Iterable, ArrayLike { * * @returns new Float64Array with the same underlying ArrayBuffer */ - public subarrayNN(begin?: number, end?: number): Float64Array { - return this.subarray(asIntOrDefault(begin, 0 as int), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Float64Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Float64Array with the same underlying ArrayBuffer - */ - public subarrayIN(begin?: int, end?: number): Float64Array { - return this.subarray(begin ?? 0, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Float64Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Float64Array with the same underlying ArrayBuffer - */ - public subarrayNI(begin?: number, end?: int): Float64Array { - return this.subarray(asIntOrDefault(begin, 0 as int), end ?? this.lengthInt) - } - - /** - * Creates a Float64Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Float64Array with the same underlying ArrayBuffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): Float64Array { + public subarray(begin?: int, end?: int): Float64Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) diff --git a/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets b/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets index 746a4f168f..b41f6b14dc 100644 --- a/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets +++ b/static_core/plugins/ets/stdlib/escompat/TypedUArrays.ets @@ -88,7 +88,6 @@ class Uint8ClampedArrayIteratorEntries implements IterableIterator<[Number, Numb export final class Uint8ClampedArray implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 1 public readonly BYTES_PER_ELEMENT: int = Uint8ClampedArray.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } /** Underlying Buffer */ public readonly buffer: ArrayBuffer @@ -301,17 +300,6 @@ export final class Uint8ClampedArray implements Iterable, ArrayLike, ArrayLike, ArrayLike, ArrayLike, ArrayLike, ArrayLike, ArrayLike, ArrayLike { export final class Uint8Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 1 public readonly BYTES_PER_ELEMENT: int = Uint8Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } /** Underlying Buffer */ public readonly buffer: ArrayBuffer @@ -2090,17 +1864,6 @@ export final class Uint8Array implements Iterable, ArrayLike { return this.values() } - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index if index is correct. * @@ -2162,53 +1925,8 @@ export final class Uint8Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): Uint8Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): Uint8Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): Uint8Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): Uint8Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): Uint8Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -2222,19 +1940,7 @@ export final class Uint8Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): Uint8Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of Uint8Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): Uint8Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): Uint8Array /** * Makes a copy of internal elements to targetPos from begin to end of Uint8Array. @@ -2245,7 +1951,7 @@ export final class Uint8Array implements Iterable, ArrayLike { * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): Uint8Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -2264,7 +1970,7 @@ export final class Uint8Array implements Iterable, ArrayLike { * * @returns modified Uint8Array */ - public fill(value: number, start?: number, end?: number): Uint8Array { + public fill(value: number, start?: int, end?: int): Uint8Array { value = this.zeroIfInfinity(value) this.fill(value.toInt(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) return this @@ -2277,94 +1983,19 @@ export final class Uint8Array implements Iterable, ArrayLike { * * @returns modified Uint8Array */ - public fill(value: number, start: int, end?: number): Uint8Array { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) + public fill(value: int, start?: int, end?: int): Uint8Array { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value, k, finalPos) return this } + private final native fillInternal(value: int, start: int, end: int): void + /** - * Fills the Uint8Array with specified value + * Assigns val as element on index. * - * @param value new value - * - * @returns modified Uint8Array - */ - public fill(value: number, start: number, end: int): Uint8Array { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint8Array with specified value - * - * @param value new value - * - * @returns modified Uint8Array - */ - public fill(value: number, start: int, end: int): Uint8Array { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint8Array with specified value - * - * @param value new value - * - * @returns modified Uint8Array - */ - public fill(value: int, start?: number, end?: number): Uint8Array { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Uint8Array with specified value - * - * @param value new value - * - * @returns modified Uint8Array - */ - public fill(value: int, start: int, end?: number): Uint8Array { - this.fill(value, start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Uint8Array with specified value - * - * @param value new value - * - * @returns modified Uint8Array - */ - public fill(value: int, start: number, end: int): Uint8Array { - this.fill(value, start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint8Array with specified value - * - * @param value new value - * - * @returns modified Uint8Array - */ - public fill(value: int, start: int, end: int): Uint8Array { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) - this.fillInternal(value, k, finalPos) - return this - } - - private final native fillInternal(value: int, start: int, end: int): void - - /** - * Assigns val as element on index. - * - * @param val value to set + * @param val value to set * * @param index index to change */ @@ -2970,55 +2601,10 @@ export final class Uint8Array implements Iterable, ArrayLike { * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): Uint8Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current Uint8Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Uint8Array with elements of current Uint8Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): Uint8Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Uint8Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Uint8Array with elements of current Uint8Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): Uint8Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Uint8Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Uint8Array with elements of current Uint8Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): Uint8Array { + public slice(begin?: int, end?: int): Uint8Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -3101,46 +2687,7 @@ export final class Uint8Array implements Iterable, ArrayLike { * * @returns new Uint8Array with the same underlying Buffer */ - public subarrayNN(begin?: number, end?: number): Uint8Array { - return this.subarray(asIntOrDefault(begin, 0), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Uint8Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint8Array with the same underlying Buffer - */ - public subarrayNI(begin?: number, end?: int): Uint8Array { - return this.subarray(asIntOrDefault(begin, 0), end) - } - - /** - * Creates a Uint8Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint8Array with the same underlying Buffer - */ - public subarrayIN(begin?: int, end?: number): Uint8Array { - return this.subarray(begin, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Uint8Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint8Array with the same underlying Buffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): Uint8Array { + public subarray(begin?: int, end?: int): Uint8Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) @@ -3634,7 +3181,6 @@ class Uint16ArrayIteratorEntries implements IterableIterator<[Number, Number]> { export final class Uint16Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 2 public readonly BYTES_PER_ELEMENT: int = Uint16Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } /** Underlying Buffer */ public readonly buffer: ArrayBuffer @@ -3872,17 +3418,6 @@ export final class Uint16Array implements Iterable, ArrayLike { return this.values() } - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index if index is correct. * @@ -3944,53 +3479,8 @@ export final class Uint16Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): Uint16Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): Uint16Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): Uint16Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): Uint16Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): Uint16Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -4004,19 +3494,7 @@ export final class Uint16Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): Uint16Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of Uint16Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): Uint16Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): Uint16Array /** * Makes a copy of internal elements to targetPos from begin to end of Uint16Array. @@ -4027,7 +3505,7 @@ export final class Uint16Array implements Iterable, ArrayLike { * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): Uint16Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -4046,7 +3524,7 @@ export final class Uint16Array implements Iterable, ArrayLike { * * @returns modified Uint16Array */ - public fill(value: number, start?: number, end?: number): Uint16Array { + public fill(value: number, start?: int, end?: int): Uint16Array { value = this.zeroIfInfinity(value) this.fill(value.toInt(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) return this @@ -4059,84 +3537,9 @@ export final class Uint16Array implements Iterable, ArrayLike { * * @returns modified Uint16Array */ - public fill(value: number, start: int, end?: number): Uint16Array { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Uint16Array with specified value - * - * @param value new value - * - * @returns modified Uint16Array - */ - public fill(value: number, start: number, end: int): Uint16Array { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint16Array with specified value - * - * @param value new value - * - * @returns modified Uint16Array - */ - public fill(value: number, start: int, end: int): Uint16Array { - value = this.zeroIfInfinity(value) - this.fill(value.toInt(), start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint16Array with specified value - * - * @param value new value - * - * @returns modified Uint16Array - */ - public fill(value: int, start?: number, end?: number): Uint16Array { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Uint16Array with specified value - * - * @param value new value - * - * @returns modified Uint16Array - */ - public fill(value: int, start: int, end?: number): Uint16Array { - this.fill(value, start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Uint16Array with specified value - * - * @param value new value - * - * @returns modified Uint16Array - */ - public fill(value: int, start: number, end: int): Uint16Array { - this.fill(value, start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint16Array with specified value - * - * @param value new value - * - * @returns modified Uint16Array - */ - public fill(value: int, start: int, end: int): Uint16Array { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) + public fill(value: int, start?: int, end?: int): Uint16Array { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) this.fillInternal(value, k, finalPos) return this } @@ -4738,55 +4141,10 @@ export final class Uint16Array implements Iterable, ArrayLike { * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): Uint16Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current Uint16Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Uint16Array with elements of current Uint16Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): Uint16Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Uint16Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Uint16Array with elements of current Uint16Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): Uint16Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current Uint16Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Uint16Array with elements of current Uint16Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): Uint16Array { + public slice(begin?: int, end?: int): Uint16Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -4869,46 +4227,7 @@ export final class Uint16Array implements Iterable, ArrayLike { * * @returns new Uint16Array with the same underlying Buffer */ - public subarrayNN(begin?: number, end?: number): Uint16Array { - return this.subarray(asIntOrDefault(begin, 0), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Uint16Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint16Array with the same underlying Buffer - */ - public subarrayNI(begin?: number, end?: int): Uint16Array { - return this.subarray(asIntOrDefault(begin, 0), end) - } - - /** - * Creates a Uint16Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint16Array with the same underlying Buffer - */ - public subarrayIN(begin?: int, end?: number): Uint16Array { - return this.subarray(begin, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Uint16Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint16Array with the same underlying Buffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): Uint16Array { + public subarray(begin?: int, end?: int): Uint16Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) @@ -5413,7 +4732,6 @@ class Uint32ArrayIteratorEntries implements IterableIterator<[Number, Number]> { export final class Uint32Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 4 public readonly BYTES_PER_ELEMENT: int = Uint32Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } /** Underlying Buffer */ public readonly buffer: ArrayBuffer @@ -5651,17 +4969,6 @@ export final class Uint32Array implements Iterable, ArrayLike { return this.values() } - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index if index is correct. * @@ -5732,53 +5039,8 @@ export final class Uint32Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): Uint32Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): Uint32Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): Uint32Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): Uint32Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): Uint32Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -5792,19 +5054,7 @@ export final class Uint32Array implements Iterable, ArrayLike { * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): Uint32Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of Uint32Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): Uint32Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): Uint32Array /** * Makes a copy of internal elements to targetPos from begin to end of Uint32Array. @@ -5815,7 +5065,7 @@ export final class Uint32Array implements Iterable, ArrayLike { * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): Uint32Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -5834,7 +5084,7 @@ export final class Uint32Array implements Iterable, ArrayLike { * * @returns modified Uint32Array */ - public fill(value: number, start?: number, end?: number): Uint32Array { + public fill(value: number, start?: int, end?: int): Uint32Array { value = this.zeroIfInfinity(value) this.fill(value.toLong(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) return this @@ -5847,84 +5097,9 @@ export final class Uint32Array implements Iterable, ArrayLike { * * @returns modified Uint32Array */ - public fill(value: number, start: int, end?: number): Uint32Array { - value = this.zeroIfInfinity(value) - this.fill(value.toLong(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Uint32Array with specified value - * - * @param value new value - * - * @returns modified Uint32Array - */ - public fill(value: number, start: number, end: int): Uint32Array { - value = this.zeroIfInfinity(value) - this.fill(value.toLong(), start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint32Array with specified value - * - * @param value new value - * - * @returns modified Uint32Array - */ - public fill(value: number, start: int, end: int): Uint32Array { - value = this.zeroIfInfinity(value) - this.fill(value.toLong(), start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint32Array with specified value - * - * @param value new value - * - * @returns modified Uint32Array - */ - public fill(value: long, start?: number, end?: number): Uint32Array { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Uint32Array with specified value - * - * @param value new value - * - * @returns modified Uint32Array - */ - public fill(value: long, start: int, end?: number): Uint32Array { - this.fill(value, start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the Uint32Array with specified value - * - * @param value new value - * - * @returns modified Uint32Array - */ - public fill(value: long, start: number, end: int): Uint32Array { - this.fill(value, start.toInt(), end.toInt()) - return this - } - - /** - * Fills the Uint32Array with specified value - * - * @param value new value - * - * @returns modified Uint32Array - */ - public fill(value: long, start: int, end: int): Uint32Array { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) + public fill(value: long, start?: int, end?: int): Uint32Array { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) this.fillInternal(value, k, finalPos) return this } @@ -6500,79 +5675,34 @@ export final class Uint32Array implements Iterable, ArrayLike { /** * Returns the index of the last occurrence of a value in Uint32Array. * - * @param searchElement The value to locate in the array. - * - * @param fromIndex The array index at which to begin the search. If fromIndex is undefined, the - * search starts at index 0. If fromIndex is omitted, the search begins at index length-1 - * - * @returns right-most index of searchElement. It must be less or equal than fromIndex. -1 if not found - */ - public lastIndexOf(searchElement: int): number { - return this.lastIndexOf(searchElement, this.lengthInt - 1) - } - - /** - * Creates a new Uint32Array using initializer - * - * @param data initializer - * - * @returns a new Uint32Array from data - */ - public of(...data: FixedArray): Uint32Array { - throw new Error("Uint32Array.of: not implemented") - } - - /** - * Creates a new Uint32Array using reversed data from the current one - * - * @returns a new Uint32Array using reversed data from the current one - */ - public native reverse(): Uint32Array - - /** - * Creates a slice of current Uint32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Uint32Array with elements of current Uint32Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin?: number, end?: number): Uint32Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current Uint32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice + * @param searchElement The value to locate in the array. * - * @returns a new Uint32Array with elements of current Uint32Array[begin;end) where end index is excluded + * @param fromIndex The array index at which to begin the search. If fromIndex is undefined, the + * search starts at index 0. If fromIndex is omitted, the search begins at index length-1 * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice + * @returns right-most index of searchElement. It must be less or equal than fromIndex. -1 if not found */ - public slice(begin: number, end: int): Uint32Array { - return this.slice(begin.toInt(), end.toInt()) + public lastIndexOf(searchElement: int): number { + return this.lastIndexOf(searchElement, this.lengthInt - 1) + } + + /** + * Creates a new Uint32Array using initializer + * + * @param data initializer + * + * @returns a new Uint32Array from data + */ + public of(...data: FixedArray): Uint32Array { + throw new Error("Uint32Array.of: not implemented") } /** - * Creates a slice of current Uint32Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new Uint32Array with elements of current Uint32Array[begin;end) where end index is excluded + * Creates a new Uint32Array using reversed data from the current one * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice + * @returns a new Uint32Array using reversed data from the current one */ - public slice(begin: int, end: number): Uint32Array { - return this.slice(begin.toInt(), end.toInt()) - } + public native reverse(): Uint32Array /** * Creates a slice of current Uint32Array using range [begin, end) @@ -6585,10 +5715,10 @@ export final class Uint32Array implements Iterable, ArrayLike { * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin: int, end: int): Uint32Array { + public slice(begin?: int, end?: int): Uint32Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -6671,46 +5801,7 @@ export final class Uint32Array implements Iterable, ArrayLike { * * @returns new Uint32Array with the same underlying Buffer */ - public subarrayNN(begin?: number, end?: number): Uint32Array { - return this.subarray(asIntOrDefault(begin, 0), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Uint32Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint32Array with the same underlying Buffer - */ - public subarrayNI(begin?: number, end?: int): Uint32Array { - return this.subarray(asIntOrDefault(begin, 0), end) - } - - /** - * Creates a Uint32Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint32Array with the same underlying Buffer - */ - public subarrayIN(begin?: int, end?: number): Uint32Array { - return this.subarray(begin, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a Uint32Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new Uint32Array with the same underlying Buffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): Uint32Array { + public subarray(begin?: int, end?: int): Uint32Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) @@ -7215,7 +6306,6 @@ class BigUint64ArrayIteratorEntries implements IterableIterator<[Number, BigInt] export final class BigUint64Array implements Iterable, ArrayLike { public static readonly BYTES_PER_ELEMENT: int = 8 public readonly BYTES_PER_ELEMENT: int = BigUint64Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } /** Underlying Buffer */ public readonly buffer: ArrayBuffer @@ -7444,17 +6534,6 @@ export final class BigUint64Array implements Iterable, ArrayLike return this.values() } - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): BigInt | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index if index is correct. * @@ -7527,53 +6606,8 @@ export final class BigUint64Array implements Iterable, ArrayLike * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): BigUint64Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): BigUint64Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): BigUint64Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): BigUint64Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): BigUint64Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -7587,19 +6621,7 @@ export final class BigUint64Array implements Iterable, ArrayLike * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): BigUint64Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of BigUint64Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): BigUint64Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): BigUint64Array /** * Makes a copy of internal elements to targetPos from begin to end of BigUint64Array. @@ -7610,7 +6632,7 @@ export final class BigUint64Array implements Iterable, ArrayLike * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): BigUint64Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -7629,7 +6651,7 @@ export final class BigUint64Array implements Iterable, ArrayLike * * @returns modified BigUint64Array */ - public fill(value: BigInt, start?: number, end?: number): BigUint64Array { + public fill(value: BigInt, start?: int, end?: int): BigUint64Array { this.fill(value.getULong(), asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) return this } @@ -7641,81 +6663,9 @@ export final class BigUint64Array implements Iterable, ArrayLike * * @returns modified BigUint64Array */ - public fill(value: BigInt, start: int, end?: number): BigUint64Array { - this.fill(value.getULong(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the BigUint64Array with specified value - * - * @param value new value - * - * @returns modified BigUint64Array - */ - public fill(value: BigInt, start: number, end: int): BigUint64Array { - this.fill(value.getULong(), start.toInt(), end.toInt()) - return this - } - - /** - * Fills the BigUint64Array with specified value - * - * @param value new value - * - * @returns modified BigUint64Array - */ - public fill(value: BigInt, start: int, end: int): BigUint64Array { - this.fill(value.getULong(), start.toInt(), end.toInt()) - return this - } - - /** - * Fills the BigUint64Array with specified value - * - * @param value new value - * - * @returns modified BigUint64Array - */ - public fill(value: long, start?: number, end?: number): BigUint64Array { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the BigUint64Array with specified value - * - * @param value new value - * - * @returns modified BigUint64Array - */ - public fill(value: long, start: int, end?: number): BigUint64Array { - this.fill(value, start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the BigUint64Array with specified value - * - * @param value new value - * - * @returns modified BigUint64Array - */ - public fill(value: long, start: number, end: int): BigUint64Array { - this.fill(value, start.toInt(), end.toInt()) - return this - } - - /** - * Fills the BigUint64Array with specified value - * - * @param value new value - * - * @returns modified BigUint64Array - */ - public fill(value: long, start: int, end: int): BigUint64Array { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) + public fill(value: long, start?: int, end?: int): BigUint64Array { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) this.fillInternal(value, k, finalPos) return this } @@ -8329,55 +7279,10 @@ export final class BigUint64Array implements Iterable, ArrayLike * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): BigUint64Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current BigUint64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new BigUint64Array with elements of current BigUint64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): BigUint64Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current BigUint64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new BigUint64Array with elements of current BigUint64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): BigUint64Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current BigUint64Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new BigUint64Array with elements of current BigUint64Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): BigUint64Array { + public slice(begin?: int, end?: int): BigUint64Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -8464,46 +7369,7 @@ export final class BigUint64Array implements Iterable, ArrayLike * * @returns new BigUint64Array with the same underlying Buffer */ - public subarrayNN(begin?: number, end?: number): BigUint64Array { - return this.subarray(asIntOrDefault(begin, 0), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a BigUint64Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new BigUint64Array with the same underlying Buffer - */ - public subarrayNI(begin?: number, end?: int): BigUint64Array { - return this.subarray(asIntOrDefault(begin, 0), end) - } - - /** - * Creates a BigUint64Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new BigUint64Array with the same underlying Buffer - */ - public subarrayIN(begin?: int, end?: number): BigUint64Array { - return this.subarray(begin, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a BigUint64Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new BigUint64Array with the same underlying Buffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): BigUint64Array { + public subarray(begin?: int, end?: int): BigUint64Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) diff --git a/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 b/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 index b3399b5091..3dd274993a 100644 --- a/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 +++ b/static_core/plugins/ets/templates/stdlib/typedArray.ets.j2 @@ -105,7 +105,6 @@ class {{N}}ArrayIteratorEntries implements IterableIterator<{{subsetTypeValuesEn export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLike<{{subsetTypeValues}}> { public static readonly BYTES_PER_ELEMENT: int = {{S}} public readonly BYTES_PER_ELEMENT: int = {{N}}Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } protected readonly lengthInt: int /** @@ -437,17 +436,6 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi {%- if T != 'long' %} - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): Number | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index. * @@ -469,17 +457,6 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi } {%- else %} - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): {{elementCompat}} | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index. * @@ -512,53 +489,8 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): {{N}}Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): {{N}}Array { - return this.copyWithin(target, start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): {{N}}Array { - return this.copyWithin(target.toInt(), start, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): {{N}}Array { - return this.copyWithin(target, start, asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): {{N}}Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -572,19 +504,7 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): {{N}}Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of {{N}}Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): {{N}}Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): {{N}}Array /** * Makes a copy of internal elements to targetPos from begin to end of {{N}}Array. @@ -595,7 +515,7 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): {{N}}Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } {% set TBoxed = T[0].upper() + T[1:] -%} @@ -616,41 +536,13 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi * * @returns modified {{N}}Array */ - public fill(value: {{elementCompat}}, start?: number, end?: number): this { - {%- if not N in ['Float32', 'Float64', 'BigInt64'] %} - value = this.zeroIfInfinity(value) - {%- endif %} - this.fill(value{{fromElementCompat}}, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the {{N}}Array with specified value - * - * @param value new valuy - * - * @returns modified {{N}}Array - */ - public fill(value: {{elementCompat}}, start: int, end?: number): this { + public fill(value: {{elementCompat}}, start?: int, end?: int): this { {%- if not N in ['Float32', 'Float64', 'BigInt64'] %} value = this.zeroIfInfinity(value) {%- endif %} - this.fill(value{{fromElementCompat}}, start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the {{N}}Array with specified value - * - * @param value new valuy - * - * @returns modified {{N}}Array - */ - public fill(value: {{elementCompat}}, start: number, end: int): this { - {%- if not N in ['Float32', 'Float64', 'BigInt64'] %} - value = this.zeroIfInfinity(value) - {%- endif %} - this.fill(value{{fromElementCompat}}, start.toInt(), end) + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value{{fromElementCompat}}, k, finalPos) return this } @@ -663,66 +555,15 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi * * @returns modified {{N}}Array */ - public fill(value: {{elementCompat}}, start: int, end: int): this { - {%- if N not in ['Float32', 'BigInt64'] %} - value = this.zeroIfInfinity(value) - {%- endif %} - this.fill(value{{fromElementCompat}}, start, end) - return this - } - - /** - * Fills the {{N}}Array with specified value - * - * @param value new valuy - * - * @returns modified {{N}}Array - */ - public fill(value: {{T}}, start?: number, end?: number): this { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the {{N}}Array with specified value - * - * @param value new valuy - * - * @returns modified {{N}}Array - */ - public fill(value: {{T}}, start: int, end?: number): this { - this.fill(value, start, asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the {{N}}Array with specified value - * - * @param value new valuy - * - * @returns modified {{N}}Array - */ - public fill(value: {{T}}, start: number, end: int): this { - this.fill(value, start.toInt(), end) + public fill(value: {{T}}, start?: int, end?: int): this { + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) + this.fillInternal(value, k, finalPos) return this } {%- endif %} - /** - * Fills the {{N}}Array with specified value - * - * @param value new valuy - * - * @returns modified {{N}}Array - */ - public fill(value: {{T}}, start: int, end: int): this { - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) - this.fillInternal(value, k, finalPos) - return this - } - private final native fillInternal(value: {{T}}, start: int, end: int): void /** @@ -1397,55 +1238,10 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): {{N}}Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current {{N}}Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new {{N}}Array with elements of current {{N}}Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): {{N}}Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current {{N}}Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new {{N}}Array with elements of current {{N}}Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): {{N}}Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current {{N}}Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new {{N}}Array with elements of current {{N}}Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): {{N}}Array { + public slice(begin?: int, end?: int): {{N}}Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? this.lengthInt, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -1474,46 +1270,7 @@ export final class {{N}}Array implements Iterable<{{subsetTypeValues}}>, ArrayLi * * @returns new {{N}}Array with the same underlying ArrayBuffer */ - public subarrayNN(begin?: number, end?: number): {{N}}Array { - return this.subarray(asIntOrDefault(begin, 0 as int), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a {{N}}Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new {{N}}Array with the same underlying ArrayBuffer - */ - public subarrayIN(begin?: int, end?: number): {{N}}Array { - return this.subarray(begin ?? 0, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a {{N}}Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new {{N}}Array with the same underlying ArrayBuffer - */ - public subarrayNI(begin?: number, end?: int): {{N}}Array { - return this.subarray(asIntOrDefault(begin, 0 as int), end ?? this.lengthInt) - } - - /** - * Creates a {{N}}Array with the same underlying ArrayBuffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new {{N}}Array with the same underlying ArrayBuffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): {{N}}Array { + public subarray(begin?: int, end?: int): {{N}}Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) diff --git a/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 b/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 index dfeee2b328..8c2317055a 100644 --- a/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 +++ b/static_core/plugins/ets/templates/stdlib/typedUArray.ets.j2 @@ -105,7 +105,6 @@ class {{element['name']}}ArrayIteratorEntries implements IterableIterator<{{subs export final class {{element['name']}}Array implements Iterable<{{element['subsetTypeValues']}}>, ArrayLike<{{element['subsetTypeValues']}}> { public static readonly BYTES_PER_ELEMENT: int = {{element['bytes']}} public readonly BYTES_PER_ELEMENT: int = {{element['name']}}Array.BYTES_PER_ELEMENT - public overload subarray { subarrayII, subarrayNI, subarrayIN, subarrayNN } /** Underlying Buffer */ public readonly buffer: ArrayBuffer @@ -395,17 +394,6 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse return this.values() } - /** - * Returns an instance of primitive type at passed index. - * - * @param index index to look at - * - * @returns a primitive at index - */ - public at(index: number): {{element['subsetTypeBoxed']}} | undefined { - return this.at(index.toInt()) - } - /** * Returns an instance of primitive type at passed index if index is correct. * @@ -493,53 +481,8 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public copyWithin(target: number, start: number, end?: number): {{element['name']}}Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: number, end?: number): {{element['name']}}Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: number, start: int, end?: number): {{element['name']}}Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Makes a copy of internal elements to targetPos from startPos to endPos. - * - * @param target insert index to place copied elements - * - * @param start start index to begin copy from - * - * @param end last index to end copy from, excluded - * - * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} - */ - public copyWithin(target: int, start: int, end?: number): {{element['name']}}Array { - return this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.lengthInt)) + public copyWithin(target: int, start: int, end?: int): {{element['name']}}Array { + return this.copyWithinInternal(target, start, asIntOrDefault(end, this.lengthInt)) } /** @@ -553,19 +496,7 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse * * See rules of parameters normalization on {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin | MDN} */ - public native copyWithin(target: int, start: int, end: int): {{element['name']}}Array - - /** - * Makes a copy of internal elements to targetPos from begin to end of {{element['name']}}Array. - * - * @param target insert index to place copied elements - * - * See rules of parameters normalization: - * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} - */ - public copyWithin(target: number): {{element['name']}}Array { - return this.copyWithin(target.toInt()) - } + private native copyWithinInternal(target: int, start: int, end: int): {{element['name']}}Array /** * Makes a copy of internal elements to targetPos from begin to end of {{element['name']}}Array. @@ -576,7 +507,7 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin} */ public copyWithin(target: int): {{element['name']}}Array { - return this.copyWithin(target, 0, this.lengthInt) + return this.copyWithinInternal(target, 0, this.lengthInt) } /** @@ -595,7 +526,7 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse * * @returns modified {{element['name']}}Array */ - public fill(value: {{element['subsetType']}}, start?: number, end?: number): {{element['name']}}Array { + public fill(value: {{element['subsetType']}}, start?: int, end?: int): {{element['name']}}Array { {%- if not element.get('name') in ['Uint8Clamped', 'BigUint64'] %} value = this.zeroIfInfinity(value) {%- endif %} @@ -610,93 +541,12 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse * * @returns modified {{element['name']}}Array */ - public fill(value: {{element['subsetType']}}, start: int, end?: number): {{element['name']}}Array { - {%- if not element.get('name') in ['Uint8Clamped', 'BigUint64'] %} - value = this.zeroIfInfinity(value) - {%- endif %} - this.fill({{fromElementCompat % 'value'}}, start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the {{element['name']}}Array with specified value - * - * @param value new value - * - * @returns modified {{element['name']}}Array - */ - public fill(value: {{element['subsetType']}}, start: number, end: int): {{element['name']}}Array { - {%- if not element.get('name') in ['Uint8Clamped', 'BigUint64'] %} - value = this.zeroIfInfinity(value) - {%- endif %} - this.fill({{fromElementCompat % 'value'}}, start.toInt(), end.toInt()) - return this - } - - /** - * Fills the {{element['name']}}Array with specified value - * - * @param value new value - * - * @returns modified {{element['name']}}Array - */ - public fill(value: {{element['subsetType']}}, start: int, end: int): {{element['name']}}Array { - {%- if not element.get('name') in ['Uint8Clamped', 'BigUint64'] %} - value = this.zeroIfInfinity(value) - {%- endif %} - this.fill({{fromElementCompat % 'value'}}, start.toInt(), end.toInt()) - return this - } - - /** - * Fills the {{element['name']}}Array with specified value - * - * @param value new value - * - * @returns modified {{element['name']}}Array - */ - public fill(value: {{element['primitiveType']}}, start?: number, end?: number): {{element['name']}}Array { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the {{element['name']}}Array with specified value - * - * @param value new value - * - * @returns modified {{element['name']}}Array - */ - public fill(value: {{element['primitiveType']}}, start: int, end?: number): {{element['name']}}Array { - this.fill(value, start.toInt(), asIntOrDefault(end, this.lengthInt)) - return this - } - - /** - * Fills the {{element['name']}}Array with specified value - * - * @param value new value - * - * @returns modified {{element['name']}}Array - */ - public fill(value: {{element['primitiveType']}}, start: number, end: int): {{element['name']}}Array { - this.fill(value, start.toInt(), end.toInt()) - return this - } - - /** - * Fills the {{element['name']}}Array with specified value - * - * @param value new value - * - * @returns modified {{element['name']}}Array - */ - public fill(value: {{element['primitiveType']}}, start: int, end: int): {{element['name']}}Array { + public fill(value: {{element['primitiveType']}}, start?: int, end?: int): {{element['name']}}Array { {%- if element.get('clamped', False) %} value = {{element['name']}}Array.clamp(value) {%- endif %} - const k = normalizeIndex(start, this.lengthInt) - const finalPos = normalizeIndex(end, this.lengthInt) + const k = normalizeIndex(start ?? 0, this.lengthInt) + const finalPos = normalizeIndex(end ?? this.lengthInt, this.lengthInt) this.fillInternal(value, k, finalPos) return this } @@ -1411,55 +1261,10 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse * * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice */ - public slice(begin?: number, end?: number): {{element['name']}}Array { - return this.slice(asIntOrDefault(begin, (0).toInt()), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a slice of current {{element['name']}}Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new {{element['name']}}Array with elements of current {{element['name']}}Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: number, end: int): {{element['name']}}Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current {{element['name']}}Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new {{element['name']}}Array with elements of current {{element['name']}}Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: number): {{element['name']}}Array { - return this.slice(begin.toInt(), end.toInt()) - } - - /** - * Creates a slice of current {{element['name']}}Array using range [begin, end) - * - * @param begin start index to be taken into slice - * - * @param end last index to be taken into slice - * - * @returns a new {{element['name']}}Array with elements of current {{element['name']}}Array[begin;end) where end index is excluded - * - * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice - */ - public slice(begin: int, end: int): {{element['name']}}Array { + public slice(begin?: int, end?: int): {{element['name']}}Array { const len: int = this.lengthInt - const relStart = normalizeIndex(begin, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(begin ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart if (count < 0) { count = 0 @@ -1555,46 +1360,7 @@ export final class {{element['name']}}Array implements Iterable<{{element['subse * * @returns new {{element['name']}}Array with the same underlying Buffer */ - public subarrayNN(begin?: number, end?: number): {{element['name']}}Array { - return this.subarray(asIntOrDefault(begin, 0), asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a {{element['name']}}Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new {{element['name']}}Array with the same underlying Buffer - */ - public subarrayNI(begin?: number, end?: int): {{element['name']}}Array { - return this.subarray(asIntOrDefault(begin, 0), end) - } - - /** - * Creates a {{element['name']}}Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new {{element['name']}}Array with the same underlying Buffer - */ - public subarrayIN(begin?: int, end?: number): {{element['name']}}Array { - return this.subarray(begin, asIntOrDefault(end, this.lengthInt)) - } - - /** - * Creates a {{element['name']}}Array with the same underlying Buffer - * - * @param begin start index, inclusive - * - * @param end last index, exclusive - * - * @returns new {{element['name']}}Array with the same underlying Buffer - */ - public subarrayII(begin: int | undefined = 0, end: int | undefined = this.lengthInt): {{element['name']}}Array { + public subarray(begin?: int, end?: int): {{element['name']}}Array { const len: int = this.lengthInt const relStart = normalizeIndex(begin ?? 0, len) const relEnd = normalizeIndex(end ?? this.lengthInt, len) diff --git a/static_core/plugins/ets/tests/ets_es_checked/float32array.yaml b/static_core/plugins/ets/tests/ets_es_checked/float32array.yaml index 5a513e4cbe..98b1c10dc7 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/float32array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/float32array.yaml @@ -18,8 +18,8 @@ sub: ((): Float32Array => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Float32Array(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.1" diff --git a/static_core/plugins/ets/tests/ets_es_checked/float64array.yaml b/static_core/plugins/ets/tests/ets_es_checked/float64array.yaml index 8bea4d9868..5675ece159 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/float64array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/float64array.yaml @@ -18,8 +18,8 @@ sub: ((): Float64Array => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Float64Array(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.1" diff --git a/static_core/plugins/ets/tests/ets_es_checked/int16array.yaml b/static_core/plugins/ets/tests/ets_es_checked/int16array.yaml index a9e8270ccd..8ac175ebba 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/int16array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/int16array.yaml @@ -18,8 +18,8 @@ sub: ((): Int16Array => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Int16Array(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.0" diff --git a/static_core/plugins/ets/tests/ets_es_checked/int32array.yaml b/static_core/plugins/ets/tests/ets_es_checked/int32array.yaml index 8458f4537c..fd83c2a7fd 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/int32array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/int32array.yaml @@ -18,8 +18,8 @@ sub: ((): Int32Array => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Int32Array(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.0" diff --git a/static_core/plugins/ets/tests/ets_es_checked/int8array.yaml b/static_core/plugins/ets/tests/ets_es_checked/int8array.yaml index 3d9d354743..55bc2524a8 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/int8array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/int8array.yaml @@ -18,8 +18,8 @@ sub: ((): Int8Array => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Int8Array(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.0" diff --git a/static_core/plugins/ets/tests/ets_es_checked/uint16array.yaml b/static_core/plugins/ets/tests/ets_es_checked/uint16array.yaml index 305815961d..c6cf063a61 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/uint16array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/uint16array.yaml @@ -18,8 +18,8 @@ sub: ((): Uint16Array => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Uint16Array(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.0" diff --git a/static_core/plugins/ets/tests/ets_es_checked/uint32array.yaml b/static_core/plugins/ets/tests/ets_es_checked/uint32array.yaml index 08b016fdc1..a0167fc3b3 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/uint32array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/uint32array.yaml @@ -18,8 +18,8 @@ sub: ((): Uint32Array => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Uint32Array(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.0" diff --git a/static_core/plugins/ets/tests/ets_es_checked/uint8array.yaml b/static_core/plugins/ets/tests/ets_es_checked/uint8array.yaml index 7649503523..e78e9e3e05 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/uint8array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/uint8array.yaml @@ -18,8 +18,8 @@ sub: ((): Uint8Array => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Uint8Array(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.0" diff --git a/static_core/plugins/ets/tests/ets_es_checked/uint8clampedarray.yaml b/static_core/plugins/ets/tests/ets_es_checked/uint8clampedarray.yaml index 5332871bdd..31c255b54b 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/uint8clampedarray.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/uint8clampedarray.yaml @@ -18,8 +18,8 @@ sub: ((): Uint8ClampedArray => { let b: number[] = [-Infinity, Infinity, -NaN, NaN, 0, 4, 1, 2.1, 256.0, 65536.0, -256.0, -65536.0]; let a = new Uint8ClampedArray(b.length); a.set(b); return a; })() self_type: Iterable vars: - default_inds: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100] - default_inds_undef: ["self.length", "-self.length", "self.length - 1.0", "-self.length + 1.0", 1.0, 5.0, 100.0, -1.1, 2.2, "-Infinity", "Infinity", "NaN", "0x8 as number", "-0o4 as number", 5, 100, 0, -5, -100, "undefined"] + default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100] + default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, -1, 2, 0x8, -0o4, 5, 100, 0, -5, -100, "undefined"] default_search: ["NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lambdas: - "() => 1.0" diff --git a/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typedarray_function2.j2 b/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typedarray_function2.j2 index c52d10bc8e..314a6e6cbb 100644 --- a/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typedarray_function2.j2 +++ b/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typedarray_function2.j2 @@ -291,7 +291,7 @@ function testSubarrayTwoParams(): int { } try { - target = origin.subarray(new Number(subarrayStart), undefined); + target = origin.subarray(subarrayStart, undefined); } catch(e) { console.log(e); return fail; @@ -337,7 +337,7 @@ function testSubarrayTwoParams(): int { } try { - target = origin.subarray(undefined, new Number(subarrayEnd)); + target = origin.subarray(undefined, subarrayEnd); } catch(e) { console.log(e); return fail; diff --git a/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typedarray_slicing.j2 b/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typedarray_slicing.j2 index e39595047b..c0a83dbf27 100644 --- a/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typedarray_slicing.j2 +++ b/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typedarray_slicing.j2 @@ -243,7 +243,7 @@ function testSliceTwoParams(): int { } try { - target = origin.slice(new Number(sliceStart), undefined); + target = origin.slice(sliceStart, undefined); } catch(e) { console.log(e); return fail; @@ -289,7 +289,7 @@ function testSliceTwoParams(): int { } try { - target = origin.slice(undefined, new Number(sliceEnd)); + target = origin.slice(undefined, sliceEnd); } catch(e) { console.log(e); return fail; diff --git a/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typeduarray_function2.j2 b/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typeduarray_function2.j2 index e724d62115..cb82c15909 100644 --- a/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typeduarray_function2.j2 +++ b/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typeduarray_function2.j2 @@ -311,7 +311,7 @@ function testSubarrayTwoParams(): int { } try { - target = origin.subarray(new Number(subarrayStart), undefined); + target = origin.subarray(subarrayStart, undefined); } catch(e) { console.log(e); return fail; @@ -357,7 +357,7 @@ function testSubarrayTwoParams(): int { } try { - target = origin.subarray(undefined, new Number(subarrayEnd)); + target = origin.subarray(undefined, subarrayEnd); } catch(e) { console.log(e); return fail; diff --git a/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typeduarray_slicing.j2 b/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typeduarray_slicing.j2 index 4313a021f2..9bc07b3fc6 100644 --- a/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typeduarray_slicing.j2 +++ b/static_core/plugins/ets/tests/stdlib-templates/utils/test_core_typeduarray_slicing.j2 @@ -264,7 +264,7 @@ function testSliceTwoParams(): int { } try { - target = origin.slice(new Number(sliceStart), undefined); + target = origin.slice(sliceStart, undefined); } catch(e) { console.log(e); return fail; @@ -310,7 +310,7 @@ function testSliceTwoParams(): int { } try { - target = origin.slice(undefined, new Number(sliceEnd)); + target = origin.slice(undefined, sliceEnd); } catch(e) { console.log(e); return fail; -- Gitee