diff --git a/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml b/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml index 4a281a2a665ff68dbf7425d5f6ae1ebdbba79254..259b5b765621d569c0169505a8f656d348133f29 100644 --- a/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml +++ b/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml @@ -1595,15 +1595,15 @@ intrinsics: args: [ std.core.Object, i32] impl: ark::ets::intrinsics::EtsEscompatArrayInternalLastIndexOf - - name: EscompatArrayFill + - name: EscompatArrayFillImpl space: ets class_name: escompat.Array - method_name: fill + method_name: fillImpl static: false signature: ret: escompat.Array args: [ std.core.Object, i32, i32 ] - impl: ark::ets::intrinsics::EtsEscompatArrayFill + impl: ark::ets::intrinsics::EtsEscompatArrayFillImpl - name: EscompatArrayGetUnsafe space: ets diff --git a/static_core/plugins/ets/runtime/interop_js/js_refconvert_builtin.cpp b/static_core/plugins/ets/runtime/interop_js/js_refconvert_builtin.cpp index 4bffa875531272cc583d60b38865f20216d9637d..775d3db87010932549c7870d923f283b335168ad 100644 --- a/static_core/plugins/ets/runtime/interop_js/js_refconvert_builtin.cpp +++ b/static_core/plugins/ets/runtime/interop_js/js_refconvert_builtin.cpp @@ -203,20 +203,8 @@ private: { static const ets_proxy::EtsClassWrapper::OverloadsMap W_ARRAY_OVERLOADS = { {utf::CStringAsMutf8(""), {":V", 1, ""}}, - {utf::CStringAsMutf8("$_get"), {"I:Lstd/core/Object;", 2, "$_get"}}, - {utf::CStringAsMutf8("$_set"), {"ILstd/core/Object;:V", 3, "$_set"}}, - {utf::CStringAsMutf8("at"), {"I:Lstd/core/Object;", 2, "at"}}, - {utf::CStringAsMutf8("copyWithin"), {"III:Lescompat/Array;", 4, "copyWithin"}}, - {utf::CStringAsMutf8("fill"), - {"Lstd/core/Object;Lstd/core/Double;Lstd/core/Double;:Lescompat/Array;", 4, "fill"}}, - {utf::CStringAsMutf8("indexOf"), {"Lstd/core/Object;Lstd/core/Int;:I", 3, "indexOf"}}, - {utf::CStringAsMutf8("lastIndexOf"), {"Lstd/core/Object;Lstd/core/Int;:I", 3, "lastIndexOf"}}, - {utf::CStringAsMutf8("slice"), {"II:Lescompat/Array;", 3, "slice"}}, - {utf::CStringAsMutf8("splice"), {"I:Lescompat/Array;", 2, "splice"}}, - {utf::CStringAsMutf8("splice"), {"IILescompat/Array;:Lescompat/Array;", 3, "splice"}}, {utf::CStringAsMutf8("toSpliced"), {"II[Lstd/core/Object;:Lescompat/Array;", 3, "toSpliced"}}, - {utf::CStringAsMutf8("with"), {"DLstd/core/Object;:Lescompat/Array;", 3, "with"}}, - {utf::CStringAsMutf8("push"), {"Lescompat/Array;:D", 1, "pushArray"}}}; + {utf::CStringAsMutf8("push"), {"Lescompat/Array;:I", 1, "pushArray"}}}; wArray_ = RegisterClass(descriptors::ARRAY, "Array", &W_ARRAY_OVERLOADS); wArray_->GetOverloadNameMapping()["pushOne"] = "push"; diff --git a/static_core/plugins/ets/runtime/intrinsics/escompat_Array.cpp b/static_core/plugins/ets/runtime/intrinsics/escompat_Array.cpp index f02eba73067cbb552e21d263926367319453cada..3fe8e0c830be3f547b6d75bac060b50348c28f39 100644 --- a/static_core/plugins/ets/runtime/intrinsics/escompat_Array.cpp +++ b/static_core/plugins/ets/runtime/intrinsics/escompat_Array.cpp @@ -458,7 +458,8 @@ static uint32_t NormalizeIndex(int32_t idx, int64_t len) return idx > len ? len : idx; } -extern "C" EtsEscompatArray *EtsEscompatArrayFill(EtsEscompatArray *array, EtsObject *value, int32_t start, int32_t end) +extern "C" EtsEscompatArray *EtsEscompatArrayFillImpl(EtsEscompatArray *array, EtsObject *value, int32_t start, + int32_t end) { ASSERT(array != nullptr); EtsCoroutine *coro = EtsCoroutine::GetCurrent(); diff --git a/static_core/plugins/ets/stdlib/escompat/Array.ets b/static_core/plugins/ets/stdlib/escompat/Array.ets index aef109230b0f76baaa20b6f1ff1b49925f15e241..6f3db3f2b95e7bf7d8666fb3532411de4c81ddcc 100644 --- a/static_core/plugins/ets/stdlib/escompat/Array.ets +++ b/static_core/plugins/ets/stdlib/escompat/Array.ets @@ -648,7 +648,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns new length */ - public pushArray(...val: T[]): number { + public pushArray(...val: T[]): int { this.ensureUnusedCapacity(val.length.toInt()) for (let i = 0; i < val.length; i++) { this.buffer[this.actualLength + i] = val[i] @@ -666,7 +666,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns new length */ - public pushOne(val: T): number { + public pushOne(val: T): int { this.ensureUnusedCapacity(1) this.buffer[this.actualLength] = val this.actualLength += 1 @@ -679,7 +679,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns new length */ - public pushECMA(...val: T[]): number { + public pushECMA(...val: T[]): int { this.ensureUnusedCapacity(val.length.toInt()) for (let i = 0; i < val.length; i++) { this.buffer[this.actualLength + i] = val[i] @@ -708,21 +708,10 @@ export class Array implements ReadonlyArray, Iterable { * * @returns an Array with deleted elements */ - public splice(start: number, delete: Number | undefined, ...items: T[]): Array { - return this.splice(start.toInt(), asIntOrDefault(delete, 0), ...items) - } - - /** - * Changes the contents of an array by removing or replacing existing elements - * and/or adding new elements in place. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns an Array with deleted elements - */ - public splice(start: int, delete: int, ...items: T[]): Array { + public splice(start: int, delete: int | undefined, ...items: T[]): Array { + if (delete === undefined) { + delete = 0 + } start = normalizeIndex(start, this.actualLength) if (delete < 0) { delete = 0 @@ -762,18 +751,6 @@ export class Array implements ReadonlyArray, Iterable { return ret } - /** - * Changes the contents of an array by removing or replacing existing elements - * and/or adding new elements in place. - * - * @param start index - * - * @returns an Array with deleted elements from start to the last element of the current instance - */ - public splice(start: number): Array { - return this.splice(start.toInt()) - } - /** * Changes the contents of an array by removing or replacing existing elements * and/or adding new elements in place. @@ -825,7 +802,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns new length of the Array */ - public unshift(...values: T[]): number { + public unshift(...values: T[]): int { if (this.buffer.length <= values.actualLength + this.actualLength) { let buffer: FixedArray = new Any[this.buffer.length * 2 + values.actualLength] this.unshiftInternal(buffer, values) @@ -1000,22 +977,7 @@ export class Array implements ReadonlyArray, Iterable { * @returns The element in the array matching the given index. * Returns undefined if `index` < `-length()` or `index` >= `length()`. */ - public override at(index: number): T | undefined { - return this.at(index.toInt()) - } - - /** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ - public at(index: int): T | undefined { + public override at(index: int): T | undefined { let len = this.actualLength; let k: int; if (index >= 0) { @@ -1042,26 +1004,10 @@ export class Array implements ReadonlyArray, Iterable { * * @returns this array after transformation */ - public copyWithin(target: number, start: number, end?: Number): this { - this.copyWithin(target.toInt(), start.toInt(), asIntOrDefault(end, this.actualLength)); - return this; - } - - /** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ - public copyWithin(target: int, start: int, end: int): this { + public copyWithin(target: int, start: int, end?: int): this { target = normalizeIndex(target, this.actualLength) start = normalizeIndex(start, this.actualLength) - end = normalizeIndex(end, this.actualLength) + end = normalizeIndex(end ?? this.actualLength, this.actualLength) if (end <= start) { return this; @@ -1123,23 +1069,12 @@ export class Array implements ReadonlyArray, Iterable { * * @returns this array after transformation */ - public fill(value: T, start?: Number, end?: Number): this { - this.fill(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.actualLength)); + public fill(value: T, start?: int, end?: int): this { + this.fillImpl(value, asIntOrDefault(start, 0), asIntOrDefault(end, this.actualLength)); return this; } - /** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ - public native fill(value: T, start: int, end: int): this; + private native fillImpl(value: T, start: int, end: int): this; /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -1169,7 +1104,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns found element index or -1 otherwise */ - public override findIndex(predicate: (value: T, index: int, array: Array) => boolean): number { + public override findIndex(predicate: (value: T, index: int, array: Array) => boolean): int { for (let i = 0; i < this.actualLength; i++) { if (predicate(this.$_get_unsafe(i), i, this)) { return i; @@ -1242,7 +1177,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns index of first element satisfying to predicate, -1 if no such element */ - public override findLastIndex(predicate: (element: T, index: int, array: Array) => boolean): number { + public override findLastIndex(predicate: (element: T, index: int, array: Array) => boolean): int { for (let i = this.actualLength - 1; i >= 0; i--) { if (predicate(this.$_get_unsafe(i), i, this)) { return i @@ -1328,25 +1263,10 @@ export class Array implements ReadonlyArray, Iterable { * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ - public override slice(start?: Number, end?: Number): Array { - const len: int = this.actualLength; - return this.slice(asIntOrDefault(start, 0), asIntOrDefault(end, len)) - } - - /** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ - public slice(start: int, end: int): Array { + public slice(start?: int, end?: int): Array { const len: int = this.actualLength; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -1550,25 +1470,11 @@ export class Array implements ReadonlyArray, Iterable { * * @returns a new Array with some elements removed and/or replaced at a given index. */ - public toSpliced(start?: Number, delete?: Number): Array { + public toSpliced(start?: int, delete?: int): Array { const len = this.actualLength; return this.toSpliced(asIntOrDefault(start, len), asIntOrDefault(delete, len)) } - /** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ - public toSpliced(start: number, delete: number, ...items: FixedArray): Array { - const len = this.actualLength; - return this.toSpliced(start.toInt(), delete.toInt(), ...items) - } - /** * Copying version of the splice() method. * @@ -1623,7 +1529,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns true if val is in Array */ - public override includes(val: T, fromIndex?: Number): boolean { + public override includes(val: T, fromIndex?: int): boolean { const len = this.actualLength; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); if (val instanceof String) { @@ -1721,20 +1627,6 @@ export class Array implements ReadonlyArray, Iterable { return new Array(FROM_BUFFER, arr) } - /** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ - public with(index: number, value: T): Array { - return this.with(index.toInt(), value) - } - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. diff --git a/static_core/plugins/ets/stdlib/escompat/ConcatArray.ets b/static_core/plugins/ets/stdlib/escompat/ConcatArray.ets index 48a4889e6b0e21b3566fc9af4531c3f2ca6dd0e1..1dbabbf571e7c191d7658b12eae69829e8012ed1 100644 --- a/static_core/plugins/ets/stdlib/escompat/ConcatArray.ets +++ b/static_core/plugins/ets/stdlib/escompat/ConcatArray.ets @@ -16,9 +16,9 @@ package escompat; export interface ConcatArray extends ArrayLike { - at(index: number): T | undefined; + at(index: int): T | undefined; join(separator?: String): string; - slice(start?: Number, end?: Number): Array; + slice(start?: int, end?: int): Array; } diff --git a/static_core/plugins/ets/stdlib/escompat/ReadonlyArray.ets b/static_core/plugins/ets/stdlib/escompat/ReadonlyArray.ets index 155fb8ef24273ec2f273bb96de26929b07d19484..680869b303fc5700798589576e1f269403ab4d33 100644 --- a/static_core/plugins/ets/stdlib/escompat/ReadonlyArray.ets +++ b/static_core/plugins/ets/stdlib/escompat/ReadonlyArray.ets @@ -31,9 +31,9 @@ export interface ReadonlyArray extends ConcatArray { findLast(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): T | undefined; - findIndex(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): number; + findIndex(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): int; - findLastIndex(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): number; + findLastIndex(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): int; // NOTE(ivan-tyulyandin): TBD, FlatArray is non-subset type // flat( @@ -51,7 +51,7 @@ export interface ReadonlyArray extends ConcatArray { join(separator?: string): string; - includes(searchElement: T, fromIndex?: number): boolean; + includes(searchElement: T, fromIndex?: int): boolean; indexOf(searchElement: T, fromIndex?: int): int; @@ -69,7 +69,7 @@ export interface ReadonlyArray extends ConcatArray { reduceRight(reducer: (previousValue: U, currentValue: T, currentIndex: int, array: ReadonlyArray) => U, initialValue: U): U; - slice(start?: number, end?: number): Array; + slice(start?: int, end?: int): Array; some(predicate: (value: T, index: int, array: ReadonlyArray) => boolean): boolean; diff --git a/static_core/plugins/ets/stdlib/std/core/BuiltinArray.ets b/static_core/plugins/ets/stdlib/std/core/BuiltinArray.ets index 7fd159f004d9193ba2c2d50a2a68c77ab974af67..9955d1927255ceb045e7b60a51151c8bc917c1ff 100644 --- a/static_core/plugins/ets/stdlib/std/core/BuiltinArray.ets +++ b/static_core/plugins/ets/stdlib/std/core/BuiltinArray.ets @@ -80,21 +80,6 @@ function cloneArray(self: FixedArray): FixedArray { return ret; } -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -export function at(self: FixedArray, index: number): Boolean | undefined { - return at(self, index.toInt()) -} - /** * Takes an integer value and returns the item at that index, * allowing for positive and negative integers. Negative integers count back @@ -133,26 +118,10 @@ export function at(self: FixedArray, index: int): Boolean | undefined { * * @returns this array after transformation */ -export function copyWithin(self: FixedArray, target: number, start: number, end?: Number): FixedArray { - copyWithin(self, target.toInt(), start.toInt(), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -export function copyWithin(self: FixedArray, target: int, start: int, end: int): FixedArray { +export function copyWithin(self: FixedArray, target: int, start: int, end?: int): FixedArray { target = normalizeIndex(target, self.length) start = normalizeIndex(start, self.length) - end = normalizeIndex(end, self.length) + end = normalizeIndex(end ?? self.length, self.length) if (end <= start) { return self; @@ -214,25 +183,9 @@ export function copyWithin(self: FixedArray, target: int): FixedArray, value: boolean, start?: Number, end?: Number): FixedArray { - fill(self, value, asIntOrDefault(start, 0), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -export function fill(self: FixedArray, value: boolean, start: int, end: int): FixedArray { - start = normalizeIndex(start, self.length); - end = normalizeIndex(end, self.length) +export function fill(self: FixedArray, value: boolean, start?: int, end?: int): FixedArray { + start = normalizeIndex(start ?? 0, self.length); + end = normalizeIndex(end ?? self.length, self.length) for (let i = start; i < end; i++) { self[i] = value; @@ -269,7 +222,7 @@ export function find(self: FixedArray, predicate: (value: boolean, inde * * @returns found element index or -1 otherwise */ -export function findIndex(self: FixedArray, predicate: (value: boolean, index: int, array: FixedArray) => boolean): number { +export function findIndex(self: FixedArray, predicate: (value: boolean, index: int, array: FixedArray) => boolean): int { for (let i = 0; i < self.length; i++) { if (predicate(self[i], i, self)) { return i; @@ -341,7 +294,7 @@ export function some(self: FixedArray, predicate: (value: boolean, inde * * @returns index of first element satisfying to predicate, -1 if no such element */ -export function findLastIndex(self: FixedArray, predicate: (element: boolean, index: int, array: FixedArray) => boolean): number { +export function findLastIndex(self: FixedArray, predicate: (element: boolean, index: int, array: FixedArray) => boolean): int { for (let i = self.length - 1; i >= 0; i--) { if (predicate(self[i], i, self)) { return i @@ -427,25 +380,10 @@ export function forEach(self: FixedArray, callbackfn: (value: boolean, * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -export function slice(self: FixedArray, start?: Number, end?: Number): FixedArray { +export function slice(self: FixedArray, start?: int, end?: int): FixedArray { const len: int = self.length; - return slice(self, asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -export function slice(self: FixedArray, start: int, end: int): FixedArray { - const len: int = self.length; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -587,25 +525,11 @@ export function toLocaleString(self: FixedArray): string { * * @returns a new Array with some elements removed and/or replaced at a given index. */ -export function toSpliced(self: FixedArray, start?: Number, delete?: Number): FixedArray { +export function toSpliced(self: FixedArray, start?: int, delete?: int): FixedArray { const len = self.length; return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) } -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -export function toSpliced(self: FixedArray, start: number, delete: number, ...items: FixedArray): FixedArray { - const len = self.length; - return toSpliced(self, start.toInt(), delete.toInt(), ...items) -} - /** * Copying version of the splice() method. * @@ -660,7 +584,7 @@ export function toSpliced(self: FixedArray, start: int): FixedArray, val: boolean, fromIndex?: Number): boolean { +export function includes(self: FixedArray, val: boolean, fromIndex?: int): boolean { const len = self.length; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); for (let i = fi; i < len; i++) { @@ -748,20 +672,6 @@ export function toReversed(self: FixedArray): FixedArray { return arr } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -export function with(self: FixedArray, index: number, value: boolean): FixedArray { - return with(self, index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. @@ -1006,21 +916,6 @@ function cloneArray(self: FixedArray): FixedArray { return ret; } -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -export function at(self: FixedArray, index: number): Byte | undefined { - return at(self, index.toInt()) -} - /** * Takes an integer value and returns the item at that index, * allowing for positive and negative integers. Negative integers count back @@ -1059,26 +954,10 @@ export function at(self: FixedArray, index: int): Byte | undefined { * * @returns this array after transformation */ -export function copyWithin(self: FixedArray, target: number, start: number, end?: Number): FixedArray { - copyWithin(self, target.toInt(), start.toInt(), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -export function copyWithin(self: FixedArray, target: int, start: int, end: int): FixedArray { +export function copyWithin(self: FixedArray, target: int, start: int, end?: int): FixedArray { target = normalizeIndex(target, self.length) start = normalizeIndex(start, self.length) - end = normalizeIndex(end, self.length) + end = normalizeIndex(end ?? self.length, self.length) if (end <= start) { return self; @@ -1140,25 +1019,9 @@ export function copyWithin(self: FixedArray, target: int): FixedArray, value: byte, start?: Number, end?: Number): FixedArray { - fill(self, value, asIntOrDefault(start, 0), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -export function fill(self: FixedArray, value: byte, start: int, end: int): FixedArray { - start = normalizeIndex(start, self.length); - end = normalizeIndex(end, self.length) +export function fill(self: FixedArray, value: byte, start?: int, end?: int): FixedArray { + start = normalizeIndex(start ?? 0, self.length); + end = normalizeIndex(end ?? self.length, self.length) for (let i = start; i < end; i++) { self[i] = value; @@ -1195,7 +1058,7 @@ export function find(self: FixedArray, predicate: (value: byte, index: int * * @returns found element index or -1 otherwise */ -export function findIndex(self: FixedArray, predicate: (value: byte, index: int, array: FixedArray) => boolean): number { +export function findIndex(self: FixedArray, predicate: (value: byte, index: int, array: FixedArray) => boolean): int { for (let i = 0; i < self.length; i++) { if (predicate(self[i], i, self)) { return i; @@ -1267,7 +1130,7 @@ export function some(self: FixedArray, predicate: (value: byte, index: int * * @returns index of first element satisfying to predicate, -1 if no such element */ -export function findLastIndex(self: FixedArray, predicate: (element: byte, index: int, array: FixedArray) => boolean): number { +export function findLastIndex(self: FixedArray, predicate: (element: byte, index: int, array: FixedArray) => boolean): int { for (let i = self.length - 1; i >= 0; i--) { if (predicate(self[i], i, self)) { return i @@ -1353,25 +1216,10 @@ export function forEach(self: FixedArray, callbackfn: (value: byte, index: * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -export function slice(self: FixedArray, start?: Number, end?: Number): FixedArray { +export function slice(self: FixedArray, start?: int, end?: int): FixedArray { const len: int = self.length; - return slice(self, asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -export function slice(self: FixedArray, start: int, end: int): FixedArray { - const len: int = self.length; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -1513,25 +1361,11 @@ export function toLocaleString(self: FixedArray): string { * * @returns a new Array with some elements removed and/or replaced at a given index. */ -export function toSpliced(self: FixedArray, start?: Number, delete?: Number): FixedArray { +export function toSpliced(self: FixedArray, start?: int, delete?: int): FixedArray { const len = self.length; return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) } -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -export function toSpliced(self: FixedArray, start: number, delete: number, ...items: FixedArray): FixedArray { - const len = self.length; - return toSpliced(self, start.toInt(), delete.toInt(), ...items) -} - /** * Copying version of the splice() method. * @@ -1586,7 +1420,7 @@ export function toSpliced(self: FixedArray, start: int): FixedArray * * @returns true if val is in Array */ -export function includes(self: FixedArray, val: byte, fromIndex?: Number): boolean { +export function includes(self: FixedArray, val: byte, fromIndex?: int): boolean { const len = self.length; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); for (let i = fi; i < len; i++) { @@ -1674,20 +1508,6 @@ export function toReversed(self: FixedArray): FixedArray { return arr } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -export function with(self: FixedArray, index: number, value: byte): FixedArray { - return with(self, index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. @@ -1932,21 +1752,6 @@ function cloneArray(self: FixedArray): FixedArray { return ret; } -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -export function at(self: FixedArray, index: number): Short | undefined { - return at(self, index.toInt()) -} - /** * Takes an integer value and returns the item at that index, * allowing for positive and negative integers. Negative integers count back @@ -1985,26 +1790,10 @@ export function at(self: FixedArray, index: int): Short | undefined { * * @returns this array after transformation */ -export function copyWithin(self: FixedArray, target: number, start: number, end?: Number): FixedArray { - copyWithin(self, target.toInt(), start.toInt(), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -export function copyWithin(self: FixedArray, target: int, start: int, end: int): FixedArray { +export function copyWithin(self: FixedArray, target: int, start: int, end?: int): FixedArray { target = normalizeIndex(target, self.length) start = normalizeIndex(start, self.length) - end = normalizeIndex(end, self.length) + end = normalizeIndex(end ?? self.length, self.length) if (end <= start) { return self; @@ -2066,25 +1855,9 @@ export function copyWithin(self: FixedArray, target: int): FixedArray, value: short, start?: Number, end?: Number): FixedArray { - fill(self, value, asIntOrDefault(start, 0), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -export function fill(self: FixedArray, value: short, start: int, end: int): FixedArray { - start = normalizeIndex(start, self.length); - end = normalizeIndex(end, self.length) +export function fill(self: FixedArray, value: short, start?: int, end?: int): FixedArray { + start = normalizeIndex(start ?? 0, self.length); + end = normalizeIndex(end ?? self.length, self.length) for (let i = start; i < end; i++) { self[i] = value; @@ -2121,7 +1894,7 @@ export function find(self: FixedArray, predicate: (value: short, index: i * * @returns found element index or -1 otherwise */ -export function findIndex(self: FixedArray, predicate: (value: short, index: int, array: FixedArray) => boolean): number { +export function findIndex(self: FixedArray, predicate: (value: short, index: int, array: FixedArray) => boolean): int { for (let i = 0; i < self.length; i++) { if (predicate(self[i], i, self)) { return i; @@ -2193,7 +1966,7 @@ export function some(self: FixedArray, predicate: (value: short, index: i * * @returns index of first element satisfying to predicate, -1 if no such element */ -export function findLastIndex(self: FixedArray, predicate: (element: short, index: int, array: FixedArray) => boolean): number { +export function findLastIndex(self: FixedArray, predicate: (element: short, index: int, array: FixedArray) => boolean): int { for (let i = self.length - 1; i >= 0; i--) { if (predicate(self[i], i, self)) { return i @@ -2279,25 +2052,10 @@ export function forEach(self: FixedArray, callbackfn: (value: short, inde * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -export function slice(self: FixedArray, start?: Number, end?: Number): FixedArray { +export function slice(self: FixedArray, start?: int, end?: int): FixedArray { const len: int = self.length; - return slice(self, asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -export function slice(self: FixedArray, start: int, end: int): FixedArray { - const len: int = self.length; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -2439,25 +2197,11 @@ export function toLocaleString(self: FixedArray): string { * * @returns a new Array with some elements removed and/or replaced at a given index. */ -export function toSpliced(self: FixedArray, start?: Number, delete?: Number): FixedArray { +export function toSpliced(self: FixedArray, start?: int, delete?: int): FixedArray { const len = self.length; return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) } -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -export function toSpliced(self: FixedArray, start: number, delete: number, ...items: FixedArray): FixedArray { - const len = self.length; - return toSpliced(self, start.toInt(), delete.toInt(), ...items) -} - /** * Copying version of the splice() method. * @@ -2512,7 +2256,7 @@ export function toSpliced(self: FixedArray, start: int): FixedArray, val: short, fromIndex?: Number): boolean { +export function includes(self: FixedArray, val: short, fromIndex?: int): boolean { const len = self.length; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); for (let i = fi; i < len; i++) { @@ -2600,20 +2344,6 @@ export function toReversed(self: FixedArray): FixedArray { return arr } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -export function with(self: FixedArray, index: number, value: short): FixedArray { - return with(self, index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. @@ -2858,21 +2588,6 @@ function cloneArray(self: FixedArray): FixedArray { return ret; } -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -export function at(self: FixedArray, index: number): Int | undefined { - return at(self, index.toInt()) -} - /** * Takes an integer value and returns the item at that index, * allowing for positive and negative integers. Negative integers count back @@ -2911,26 +2626,10 @@ export function at(self: FixedArray, index: int): Int | undefined { * * @returns this array after transformation */ -export function copyWithin(self: FixedArray, target: number, start: number, end?: Number): FixedArray { - copyWithin(self, target.toInt(), start.toInt(), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -export function copyWithin(self: FixedArray, target: int, start: int, end: int): FixedArray { +export function copyWithin(self: FixedArray, target: int, start: int, end?: int): FixedArray { target = normalizeIndex(target, self.length) start = normalizeIndex(start, self.length) - end = normalizeIndex(end, self.length) + end = normalizeIndex(end ?? self.length, self.length) if (end <= start) { return self; @@ -2992,25 +2691,9 @@ export function copyWithin(self: FixedArray, target: int): FixedArray * * @returns this array after transformation */ -export function fill(self: FixedArray, value: int, start?: Number, end?: Number): FixedArray { - fill(self, value, asIntOrDefault(start, 0), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -export function fill(self: FixedArray, value: int, start: int, end: int): FixedArray { - start = normalizeIndex(start, self.length); - end = normalizeIndex(end, self.length) +export function fill(self: FixedArray, value: int, start?: int, end?: int): FixedArray { + start = normalizeIndex(start ?? 0, self.length); + end = normalizeIndex(end ?? self.length, self.length) for (let i = start; i < end; i++) { self[i] = value; @@ -3047,7 +2730,7 @@ export function find(self: FixedArray, predicate: (value: int, index: int, * * @returns found element index or -1 otherwise */ -export function findIndex(self: FixedArray, predicate: (value: int, index: int, array: FixedArray) => boolean): number { +export function findIndex(self: FixedArray, predicate: (value: int, index: int, array: FixedArray) => boolean): int { for (let i = 0; i < self.length; i++) { if (predicate(self[i], i, self)) { return i; @@ -3119,7 +2802,7 @@ export function some(self: FixedArray, predicate: (value: int, index: int, * * @returns index of first element satisfying to predicate, -1 if no such element */ -export function findLastIndex(self: FixedArray, predicate: (element: int, index: int, array: FixedArray) => boolean): number { +export function findLastIndex(self: FixedArray, predicate: (element: int, index: int, array: FixedArray) => boolean): int { for (let i = self.length - 1; i >= 0; i--) { if (predicate(self[i], i, self)) { return i @@ -3205,25 +2888,10 @@ export function forEach(self: FixedArray, callbackfn: (value: int, index: i * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -export function slice(self: FixedArray, start?: Number, end?: Number): FixedArray { - const len: int = self.length; - return slice(self, asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -export function slice(self: FixedArray, start: int, end: int): FixedArray { +export function slice(self: FixedArray, start?: int, end?: int): FixedArray { const len: int = self.length; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -3365,25 +3033,11 @@ export function toLocaleString(self: FixedArray): string { * * @returns a new Array with some elements removed and/or replaced at a given index. */ -export function toSpliced(self: FixedArray, start?: Number, delete?: Number): FixedArray { +export function toSpliced(self: FixedArray, start?: int, delete?: int): FixedArray { const len = self.length; return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) } -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -export function toSpliced(self: FixedArray, start: number, delete: number, ...items: FixedArray): FixedArray { - const len = self.length; - return toSpliced(self, start.toInt(), delete.toInt(), ...items) -} - /** * Copying version of the splice() method. * @@ -3438,7 +3092,7 @@ export function toSpliced(self: FixedArray, start: int): FixedArray { * * @returns true if val is in Array */ -export function includes(self: FixedArray, val: int, fromIndex?: Number): boolean { +export function includes(self: FixedArray, val: int, fromIndex?: int): boolean { const len = self.length; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); for (let i = fi; i < len; i++) { @@ -3526,20 +3180,6 @@ export function toReversed(self: FixedArray): FixedArray { return arr } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -export function with(self: FixedArray, index: number, value: int): FixedArray { - return with(self, index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. @@ -3784,21 +3424,6 @@ function cloneArray(self: FixedArray): FixedArray { return ret; } -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -export function at(self: FixedArray, index: number): Long | undefined { - return at(self, index.toInt()) -} - /** * Takes an integer value and returns the item at that index, * allowing for positive and negative integers. Negative integers count back @@ -3837,26 +3462,10 @@ export function at(self: FixedArray, index: int): Long | undefined { * * @returns this array after transformation */ -export function copyWithin(self: FixedArray, target: number, start: number, end?: Number): FixedArray { - copyWithin(self, target.toInt(), start.toInt(), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -export function copyWithin(self: FixedArray, target: int, start: int, end: int): FixedArray { +export function copyWithin(self: FixedArray, target: int, start: int, end?: int): FixedArray { target = normalizeIndex(target, self.length) start = normalizeIndex(start, self.length) - end = normalizeIndex(end, self.length) + end = normalizeIndex(end ?? self.length, self.length) if (end <= start) { return self; @@ -3918,25 +3527,9 @@ export function copyWithin(self: FixedArray, target: int): FixedArray, value: long, start?: Number, end?: Number): FixedArray { - fill(self, value, asIntOrDefault(start, 0), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -export function fill(self: FixedArray, value: long, start: int, end: int): FixedArray { - start = normalizeIndex(start, self.length); - end = normalizeIndex(end, self.length) +export function fill(self: FixedArray, value: long, start?: int, end?: int): FixedArray { + start = normalizeIndex(start ?? 0, self.length); + end = normalizeIndex(end ?? self.length, self.length) for (let i = start; i < end; i++) { self[i] = value; @@ -3973,7 +3566,7 @@ export function find(self: FixedArray, predicate: (value: long, index: int * * @returns found element index or -1 otherwise */ -export function findIndex(self: FixedArray, predicate: (value: long, index: int, array: FixedArray) => boolean): number { +export function findIndex(self: FixedArray, predicate: (value: long, index: int, array: FixedArray) => boolean): int { for (let i = 0; i < self.length; i++) { if (predicate(self[i], i, self)) { return i; @@ -4045,7 +3638,7 @@ export function some(self: FixedArray, predicate: (value: long, index: int * * @returns index of first element satisfying to predicate, -1 if no such element */ -export function findLastIndex(self: FixedArray, predicate: (element: long, index: int, array: FixedArray) => boolean): number { +export function findLastIndex(self: FixedArray, predicate: (element: long, index: int, array: FixedArray) => boolean): int { for (let i = self.length - 1; i >= 0; i--) { if (predicate(self[i], i, self)) { return i @@ -4131,25 +3724,10 @@ export function forEach(self: FixedArray, callbackfn: (value: long, index: * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -export function slice(self: FixedArray, start?: Number, end?: Number): FixedArray { - const len: int = self.length; - return slice(self, asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -export function slice(self: FixedArray, start: int, end: int): FixedArray { +export function slice(self: FixedArray, start?: int, end?: int): FixedArray { const len: int = self.length; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -4271,29 +3849,15 @@ export function toLocaleString(self: FixedArray): string { const sb = new StringBuilder() const len = self.length; for (let i = 0; i < len; i++) { - if (i != 0) { - sb.append(",") - } - let x = self[i] as Any; - if ((null !== x) && (undefined !== x)) { - sb.append((x! as object).toLocaleString()) // #26217 - } - } - return sb.toString() -} - -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -export function toSpliced(self: FixedArray, start?: Number, delete?: Number): FixedArray { - const len = self.length; - return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) + if (i != 0) { + sb.append(",") + } + let x = self[i] as Any; + if ((null !== x) && (undefined !== x)) { + sb.append((x! as object).toLocaleString()) // #26217 + } + } + return sb.toString() } /** @@ -4305,9 +3869,9 @@ export function toSpliced(self: FixedArray, start?: Number, delete?: Numbe * * @returns a new Array with some elements removed and/or replaced at a given index. */ -export function toSpliced(self: FixedArray, start: number, delete: number, ...items: FixedArray): FixedArray { +export function toSpliced(self: FixedArray, start?: int, delete?: int): FixedArray { const len = self.length; - return toSpliced(self, start.toInt(), delete.toInt(), ...items) + return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) } /** @@ -4364,7 +3928,7 @@ export function toSpliced(self: FixedArray, start: int): FixedArray * * @returns true if val is in Array */ -export function includes(self: FixedArray, val: long, fromIndex?: Number): boolean { +export function includes(self: FixedArray, val: long, fromIndex?: int): boolean { const len = self.length; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); for (let i = fi; i < len; i++) { @@ -4452,20 +4016,6 @@ export function toReversed(self: FixedArray): FixedArray { return arr } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -export function with(self: FixedArray, index: number, value: long): FixedArray { - return with(self, index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. @@ -4710,21 +4260,6 @@ function cloneArray(self: FixedArray): FixedArray { return ret; } -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -export function at(self: FixedArray, index: number): Float | undefined { - return at(self, index.toInt()) -} - /** * Takes an integer value and returns the item at that index, * allowing for positive and negative integers. Negative integers count back @@ -4763,26 +4298,10 @@ export function at(self: FixedArray, index: int): Float | undefined { * * @returns this array after transformation */ -export function copyWithin(self: FixedArray, target: number, start: number, end?: Number): FixedArray { - copyWithin(self, target.toInt(), start.toInt(), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -export function copyWithin(self: FixedArray, target: int, start: int, end: int): FixedArray { +export function copyWithin(self: FixedArray, target: int, start: int, end?: int): FixedArray { target = normalizeIndex(target, self.length) start = normalizeIndex(start, self.length) - end = normalizeIndex(end, self.length) + end = normalizeIndex(end ?? self.length, self.length) if (end <= start) { return self; @@ -4844,25 +4363,9 @@ export function copyWithin(self: FixedArray, target: int): FixedArray, value: float, start?: Number, end?: Number): FixedArray { - fill(self, value, asIntOrDefault(start, 0), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -export function fill(self: FixedArray, value: float, start: int, end: int): FixedArray { - start = normalizeIndex(start, self.length); - end = normalizeIndex(end, self.length) +export function fill(self: FixedArray, value: float, start?: int, end?: int): FixedArray { + start = normalizeIndex(start ?? 0, self.length); + end = normalizeIndex(end ?? self.length, self.length) for (let i = start; i < end; i++) { self[i] = value; @@ -4899,7 +4402,7 @@ export function find(self: FixedArray, predicate: (value: float, index: i * * @returns found element index or -1 otherwise */ -export function findIndex(self: FixedArray, predicate: (value: float, index: int, array: FixedArray) => boolean): number { +export function findIndex(self: FixedArray, predicate: (value: float, index: int, array: FixedArray) => boolean): int { for (let i = 0; i < self.length; i++) { if (predicate(self[i], i, self)) { return i; @@ -4971,7 +4474,7 @@ export function some(self: FixedArray, predicate: (value: float, index: i * * @returns index of first element satisfying to predicate, -1 if no such element */ -export function findLastIndex(self: FixedArray, predicate: (element: float, index: int, array: FixedArray) => boolean): number { +export function findLastIndex(self: FixedArray, predicate: (element: float, index: int, array: FixedArray) => boolean): int { for (let i = self.length - 1; i >= 0; i--) { if (predicate(self[i], i, self)) { return i @@ -5057,25 +4560,10 @@ export function forEach(self: FixedArray, callbackfn: (value: float, inde * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -export function slice(self: FixedArray, start?: Number, end?: Number): FixedArray { - const len: int = self.length; - return slice(self, asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -export function slice(self: FixedArray, start: int, end: int): FixedArray { +export function slice(self: FixedArray, start?: int, end?: int): FixedArray { const len: int = self.length; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -5217,25 +4705,11 @@ export function toLocaleString(self: FixedArray): string { * * @returns a new Array with some elements removed and/or replaced at a given index. */ -export function toSpliced(self: FixedArray, start?: Number, delete?: Number): FixedArray { +export function toSpliced(self: FixedArray, start?: int, delete?: int): FixedArray { const len = self.length; return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) } -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -export function toSpliced(self: FixedArray, start: number, delete: number, ...items: FixedArray): FixedArray { - const len = self.length; - return toSpliced(self, start.toInt(), delete.toInt(), ...items) -} - /** * Copying version of the splice() method. * @@ -5290,7 +4764,7 @@ export function toSpliced(self: FixedArray, start: int): FixedArray, val: float, fromIndex?: Number): boolean { +export function includes(self: FixedArray, val: float, fromIndex?: int): boolean { const len = self.length; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); if (isNaN(val)) { @@ -5386,20 +4860,6 @@ export function toReversed(self: FixedArray): FixedArray { return arr } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -export function with(self: FixedArray, index: number, value: float): FixedArray { - return with(self, index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. @@ -5644,21 +5104,6 @@ function cloneArray(self: FixedArray): FixedArray { return ret; } -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -export function at(self: FixedArray, index: number): Double | undefined { - return at(self, index.toInt()) -} - /** * Takes an integer value and returns the item at that index, * allowing for positive and negative integers. Negative integers count back @@ -5697,26 +5142,10 @@ export function at(self: FixedArray, index: int): Double | undefined { * * @returns this array after transformation */ -export function copyWithin(self: FixedArray, target: number, start: number, end?: Number): FixedArray { - copyWithin(self, target.toInt(), start.toInt(), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -export function copyWithin(self: FixedArray, target: int, start: int, end: int): FixedArray { +export function copyWithin(self: FixedArray, target: int, start: int, end?: int): FixedArray { target = normalizeIndex(target, self.length) start = normalizeIndex(start, self.length) - end = normalizeIndex(end, self.length) + end = normalizeIndex(end ?? self.length, self.length) if (end <= start) { return self; @@ -5778,25 +5207,9 @@ export function copyWithin(self: FixedArray, target: int): FixedArray, value: double, start?: Number, end?: Number): FixedArray { - fill(self, value, asIntOrDefault(start, 0), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -export function fill(self: FixedArray, value: double, start: int, end: int): FixedArray { - start = normalizeIndex(start, self.length); - end = normalizeIndex(end, self.length) +export function fill(self: FixedArray, value: double, start?: int, end?: int): FixedArray { + start = normalizeIndex(start ?? 0, self.length); + end = normalizeIndex(end ?? self.length, self.length) for (let i = start; i < end; i++) { self[i] = value; @@ -5833,7 +5246,7 @@ export function find(self: FixedArray, predicate: (value: double, index: * * @returns found element index or -1 otherwise */ -export function findIndex(self: FixedArray, predicate: (value: double, index: int, array: FixedArray) => boolean): number { +export function findIndex(self: FixedArray, predicate: (value: double, index: int, array: FixedArray) => boolean): int { for (let i = 0; i < self.length; i++) { if (predicate(self[i], i, self)) { return i; @@ -5905,7 +5318,7 @@ export function some(self: FixedArray, predicate: (value: double, index: * * @returns index of first element satisfying to predicate, -1 if no such element */ -export function findLastIndex(self: FixedArray, predicate: (element: double, index: int, array: FixedArray) => boolean): number { +export function findLastIndex(self: FixedArray, predicate: (element: double, index: int, array: FixedArray) => boolean): int { for (let i = self.length - 1; i >= 0; i--) { if (predicate(self[i], i, self)) { return i @@ -5991,25 +5404,10 @@ export function forEach(self: FixedArray, callbackfn: (value: double, in * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -export function slice(self: FixedArray, start?: Number, end?: Number): FixedArray { - const len: int = self.length; - return slice(self, asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -export function slice(self: FixedArray, start: int, end: int): FixedArray { +export function slice(self: FixedArray, start?: int, end?: int): FixedArray { const len: int = self.length; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -6151,25 +5549,11 @@ export function toLocaleString(self: FixedArray): string { * * @returns a new Array with some elements removed and/or replaced at a given index. */ -export function toSpliced(self: FixedArray, start?: Number, delete?: Number): FixedArray { +export function toSpliced(self: FixedArray, start?: int, delete?: int): FixedArray { const len = self.length; return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) } -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -export function toSpliced(self: FixedArray, start: number, delete: number, ...items: FixedArray): FixedArray { - const len = self.length; - return toSpliced(self, start.toInt(), delete.toInt(), ...items) -} - /** * Copying version of the splice() method. * @@ -6224,7 +5608,7 @@ export function toSpliced(self: FixedArray, start: int): FixedArray, val: double, fromIndex?: Number): boolean { +export function includes(self: FixedArray, val: double, fromIndex?: int): boolean { const len = self.length; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); if (isNaN(val)) { @@ -6320,20 +5704,6 @@ export function toReversed(self: FixedArray): FixedArray { return arr } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -export function with(self: FixedArray, index: number, value: double): FixedArray { - return with(self, index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. @@ -6578,21 +5948,6 @@ function cloneArray(self: FixedArray): FixedArray { return ret; } -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -export function at(self: FixedArray, index: number): Char | undefined { - return at(self, index.toInt()) -} - /** * Takes an integer value and returns the item at that index, * allowing for positive and negative integers. Negative integers count back @@ -6631,26 +5986,10 @@ export function at(self: FixedArray, index: int): Char | undefined { * * @returns this array after transformation */ -export function copyWithin(self: FixedArray, target: number, start: number, end?: Number): FixedArray { - copyWithin(self, target.toInt(), start.toInt(), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -export function copyWithin(self: FixedArray, target: int, start: int, end: int): FixedArray { +export function copyWithin(self: FixedArray, target: int, start: int, end?: int): FixedArray { target = normalizeIndex(target, self.length) start = normalizeIndex(start, self.length) - end = normalizeIndex(end, self.length) + end = normalizeIndex(end ?? self.length, self.length) if (end <= start) { return self; @@ -6712,25 +6051,9 @@ export function copyWithin(self: FixedArray, target: int): FixedArray, value: char, start?: Number, end?: Number): FixedArray { - fill(self, value, asIntOrDefault(start, 0), asIntOrDefault(end, self.length)); - return self; -} - -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -export function fill(self: FixedArray, value: char, start: int, end: int): FixedArray { - start = normalizeIndex(start, self.length); - end = normalizeIndex(end, self.length) +export function fill(self: FixedArray, value: char, start?: int, end?: int): FixedArray { + start = normalizeIndex(start ?? 0, self.length); + end = normalizeIndex(end ?? self.length, self.length) for (let i = start; i < end; i++) { self[i] = value; @@ -6767,7 +6090,7 @@ export function find(self: FixedArray, predicate: (value: char, index: int * * @returns found element index or -1 otherwise */ -export function findIndex(self: FixedArray, predicate: (value: char, index: int, array: FixedArray) => boolean): number { +export function findIndex(self: FixedArray, predicate: (value: char, index: int, array: FixedArray) => boolean): int { for (let i = 0; i < self.length; i++) { if (predicate(self[i], i, self)) { return i; @@ -6839,7 +6162,7 @@ export function some(self: FixedArray, predicate: (value: char, index: int * * @returns index of first element satisfying to predicate, -1 if no such element */ -export function findLastIndex(self: FixedArray, predicate: (element: char, index: int, array: FixedArray) => boolean): number { +export function findLastIndex(self: FixedArray, predicate: (element: char, index: int, array: FixedArray) => boolean): int { for (let i = self.length - 1; i >= 0; i--) { if (predicate(self[i], i, self)) { return i @@ -6925,25 +6248,10 @@ export function forEach(self: FixedArray, callbackfn: (value: char, index: * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -export function slice(self: FixedArray, start?: Number, end?: Number): FixedArray { - const len: int = self.length; - return slice(self, asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -export function slice(self: FixedArray, start: int, end: int): FixedArray { +export function slice(self: FixedArray, start?: int, end?: int): FixedArray { const len: int = self.length; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -7085,25 +6393,11 @@ export function toLocaleString(self: FixedArray): string { * * @returns a new Array with some elements removed and/or replaced at a given index. */ -export function toSpliced(self: FixedArray, start?: Number, delete?: Number): FixedArray { +export function toSpliced(self: FixedArray, start?: int, delete?: int): FixedArray { const len = self.length; return toSpliced(self, asIntOrDefault(start, len), asIntOrDefault(delete, len)) } -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -export function toSpliced(self: FixedArray, start: number, delete: number, ...items: FixedArray): FixedArray { - const len = self.length; - return toSpliced(self, start.toInt(), delete.toInt(), ...items) -} - /** * Copying version of the splice() method. * @@ -7158,7 +6452,7 @@ export function toSpliced(self: FixedArray, start: int): FixedArray * * @returns true if val is in Array */ -export function includes(self: FixedArray, val: char, fromIndex?: Number): boolean { +export function includes(self: FixedArray, val: char, fromIndex?: int): boolean { const len = self.length; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); for (let i = fi; i < len; i++) { @@ -7246,20 +6540,6 @@ export function toReversed(self: FixedArray): FixedArray { return arr } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -export function with(self: FixedArray, index: number, value: char): FixedArray { - return with(self, index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. diff --git a/static_core/plugins/ets/stdlib/std/core/Proxy.ets b/static_core/plugins/ets/stdlib/std/core/Proxy.ets index 10bb69dbdaef9bfce6657caef006e17ce4af2d07..bb97450e6e15803e44b381507ea1cb5ef022400a 100644 --- a/static_core/plugins/ets/stdlib/std/core/Proxy.ets +++ b/static_core/plugins/ets/stdlib/std/core/Proxy.ets @@ -783,19 +783,14 @@ abstract class ArrayProxy extends Array { private static readonly CONCAT_METHOD: Method = ArrayProxy.getArrayMethod("concat", Type.of([] as FixedArray>)) private static readonly UNSHIFT_METHOD: Method = ArrayProxy.getArrayMethod("unshift", Type.of(new Array())) private static readonly SHIFT_METHOD: Method = ArrayProxy.getArrayMethod("shift") - private static readonly SPLICE_METHOD_NUM: Method = ArrayProxy.getArrayMethod("splice", Type.of(1 as number)) private static readonly SPLICE_METHOD_INT: Method = ArrayProxy.getArrayMethod("splice", Type.of(1 as int)) - private static readonly TO_SPLICED_METHOD_NUM_NUM: Method = ArrayProxy.getArrayMethod("toSpliced", Type.of(Number(1)), Type.of(Number(1))) - private static readonly TO_SPLICED_METHOD_NUM_NUM_ARR: Method = ArrayProxy.getArrayMethod("toSpliced", Type.of(1 as number), Type.of(1 as number), Type.of([] as FixedArray)) + private static readonly TO_SPLICED_METHOD_INT_INT: Method = ArrayProxy.getArrayMethod("toSpliced", Type.of(1), Type.of(1)) private static readonly TO_SPLICED_METHOD_INT_INT_ARR: Method = ArrayProxy.getArrayMethod("toSpliced", Type.of(1 as int), Type.of(1 as int), Type.of([] as FixedArray)) private static readonly TO_SPLICED_METHOD_INT: Method = ArrayProxy.getArrayMethod("toSpliced", Type.of(1)) private static readonly SPLICE_METHOD_INT_INT_ARR: Method = ArrayProxy.getArrayMethod("splice", Type.of(1 as int), Type.of(1 as int), Type.of(new Array(0))) - private static readonly SPLICE_METHOD_NUM_OBJ_ARR: Method = - ArrayProxy.getArrayMethod("splice", Type.of(1.0 + 0), Type.of(new Number(0)), Type.of(new Array(0))) - constructor(target: Array, handler: ArrayProxyHandler) { this.target = target this.handler = handler @@ -864,39 +859,29 @@ abstract class ArrayProxy extends Array { throw new AssertionError("Array.concat() unexpected result type: " + Type.of(result)) } - override pushArray(...items: Array): number { + override pushArray(...items: Array): int { const result = this.handler.invoke(this.target, ArrayProxy.PUSH_METHOD, [items]) - if (result instanceof Number) { + if (result instanceof Int) { return result } throw new AssertionError("Array.push() unexpected result type: " + Type.of(result)) } - override pushOne(item: T): number { + override pushOne(item: T): int { const result = this.handler.invoke(this.target, ArrayProxy.PUSH_SINGLE_METHOD, [item]) - if (result instanceof Number) { + if (result instanceof Int) { return result } throw new AssertionError("Array.push() single push unexpected result type: " + Type.of(result)) } - override pushECMA(...items: Array): number { + override pushECMA(...items: Array): int { return this.target.pushECMA(...items) } - override splice(start: number, deleteCount: Number | undefined, ...items: T[]): Array { - const handler = this.handler - const result = handler.invoke(this.target, ArrayProxy.SPLICE_METHOD_NUM_OBJ_ARR, [start, deleteCount, items]) - if (result instanceof Array) { - return result as Array - } - - throw new AssertionError("Array.splice(int, int, T[]) unexpected result type: " + Type.of(result)) - } - - override splice(start: int, deleteCount: int, ...items: T[]): Array { + override splice(start: int, deleteCount: int | undefined, ...items: T[]): Array { const handler = this.handler const result = handler.invoke(this.target, ArrayProxy.SPLICE_METHOD_INT_INT_ARR, [start, deleteCount, items]) if (result instanceof Array) { @@ -906,15 +891,6 @@ abstract class ArrayProxy extends Array { throw new AssertionError("Array.splice(int, int, T[]) unexpected result type: " + Type.of(result)) } - override splice(start: number): Array { - const result = this.handler.invoke(this.target, ArrayProxy.SPLICE_METHOD_NUM, [start]) - if (result instanceof Array) { - return result as Array - } - - throw new AssertionError("Array.splice(number) unexpected result type: " + Type.of(result)) - } - override splice(start: int): Array { const result = this.handler.invoke(this.target, ArrayProxy.SPLICE_METHOD_INT, [start]) if (result instanceof Array) { @@ -924,8 +900,8 @@ abstract class ArrayProxy extends Array { throw new AssertionError("Array.splice(int) unexpected result type: " + Type.of(result)) } - override toSpliced(start?: Number, deleteCount?: Number): Array { - const result = this.handler.invoke(this.target, ArrayProxy.TO_SPLICED_METHOD_NUM_NUM, [start, deleteCount]) + override toSpliced(start?: int, deleteCount?: int): Array { + const result = this.handler.invoke(this.target, ArrayProxy.TO_SPLICED_METHOD_INT_INT, [start, deleteCount]) if (result instanceof Array) { return result as Array } @@ -933,15 +909,6 @@ abstract class ArrayProxy extends Array { throw new AssertionError("Array.toSpliced(Number, Number) unexpected result type: " + Type.of(result)) } - override toSpliced(start: number, deleteCount: number, ...items: FixedArray): Array { - const result = this.handler.invoke(this.target, ArrayProxy.TO_SPLICED_METHOD_NUM_NUM_ARR, [start, deleteCount, items]) - if (result instanceof Array) { - return result as Array - } - - throw new AssertionError("Array.toSpliced(number, number, FixedArray) unexpected result type: " + Type.of(result)) - } - override toSpliced(start: int, deleteCount: int, ...items: FixedArray): Array { const result = this.handler.invoke(this.target, ArrayProxy.TO_SPLICED_METHOD_INT_INT_ARR, [start, deleteCount, items]) if (result instanceof Array) { @@ -960,9 +927,9 @@ abstract class ArrayProxy extends Array { throw new AssertionError("Array.toSpliced(int) unexpected result type: " + Type.of(result)) } - override unshift(...items: T[]): number { + override unshift(...items: T[]): int { const result = this.handler.invoke(this.target, ArrayProxy.UNSHIFT_METHOD, [items]) - if (result instanceof Number) { + if (result instanceof Int) { return result } diff --git a/static_core/plugins/ets/stdlib/std/core/ReadonlyArrayProxy.ets b/static_core/plugins/ets/stdlib/std/core/ReadonlyArrayProxy.ets index c01a42719433ec253e60208fd193d350e1d4a9a0..97856c34bc92e45c87251f10407cbe0382ce0049 100644 --- a/static_core/plugins/ets/stdlib/std/core/ReadonlyArrayProxy.ets +++ b/static_core/plugins/ets/stdlib/std/core/ReadonlyArrayProxy.ets @@ -70,11 +70,11 @@ class ReadonlyArrayProxy implements ReadonlyArray { return this.target.findLast(predicate) } - override findIndex(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): number { + override findIndex(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): int { return this.target.findIndex(predicate) } - override findLastIndex(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): number { + override findLastIndex(predicate: (value: T, index: int, obj: ReadonlyArray) => boolean): int { return this.target.findLastIndex(predicate) } @@ -86,7 +86,7 @@ class ReadonlyArrayProxy implements ReadonlyArray { return this.target.join(separator) } - override includes(searchElement: T, fromIndex?: number): boolean { + override includes(searchElement: T, fromIndex?: int): boolean { return this.target.includes(searchElement, fromIndex) } @@ -122,7 +122,7 @@ class ReadonlyArrayProxy implements ReadonlyArray { return this.target.reduceRight(reducer, initialValue) } - override slice(start?: number, end?: number): Array { + override slice(start?: int, end?: int): Array { return this.target.slice(start, end) } @@ -142,7 +142,7 @@ class ReadonlyArrayProxy implements ReadonlyArray { return this.target.values() } - override at(index: number): T | undefined { + override at(index: int): T | undefined { return this.target.at(index) } diff --git a/static_core/plugins/ets/templates/stdlib/Array_common.erb b/static_core/plugins/ets/templates/stdlib/Array_common.erb index 16b8d60c6fd9c1c43e420f408fb60d41d5924eed..f73b73d3c9ca861980175e20dd5b561dc9c052ce 100644 --- a/static_core/plugins/ets/templates/stdlib/Array_common.erb +++ b/static_core/plugins/ets/templates/stdlib/Array_common.erb @@ -24,22 +24,7 @@ * @returns The element in the array matching the given index. * Returns undefined if `index` < `-length()` or `index` >= `length()`. */ -<%= access_public %> <%= override %> at<%= this_generic %>(<%= this_arg %>index: number): <%= el_type_boxed %> | undefined { - return <%= this_call.('at') %>index.toInt()) -} - -/** - * Takes an integer value and returns the item at that index, - * allowing for positive and negative integers. Negative integers count back - * from the last item in the array. - * - * @param index Zero-based index of the array element to be returned. - * Negative index counts back from the end of the array — if `index` < 0, index + `array.length()` is accessed. - * - * @returns The element in the array matching the given index. - * Returns undefined if `index` < `-length()` or `index` >= `length()`. - */ -<%= access_public %> at<%= this_generic %>(<%= this_arg %>index: int): <%= el_type_boxed %> | undefined { +<%= access_public %> <%= override %> at<%= this_generic %>(<%= this_arg %>index: int): <%= el_type_boxed %> | undefined { let len = <%= this_len_int %>; let k: int; if (index >= 0) { @@ -66,26 +51,10 @@ * * @returns this array after transformation */ -<%= access_public %> copyWithin<%= this_generic %>(<%= this_arg %>target: number, start: number, end?: Number): <%= this_return_type %> { - <%= this_call.('copyWithin') %>target.toInt(), start.toInt(), asIntOrDefault(end, <%= this_len_int %>)); - return <%= this %>; -} - -/** - * Makes a shallow copy of the Array part to another location in the same Array and returns it without modifying its length. - * - * @param target index at which to copy the sequence - * - * @param start index at which to start copying elements from - * - * @param end index at which to end copying elements from - * - * @returns this array after transformation - */ -<%= access_public %> copyWithin<%= this_generic %>(<%= this_arg %>target: int, start: int, end: int): <%= this_return_type %> { +<%= access_public %> copyWithin<%= this_generic %>(<%= this_arg %>target: int, start: int, end?: int): <%= this_return_type %> { target = normalizeIndex(target, <%= this_len_int %>) start = normalizeIndex(start, <%= this_len_int %>) - end = normalizeIndex(end, <%= this_len_int %>) + end = normalizeIndex(end ?? <%= this_len_int %>, <%= this_len_int %>) if (end <= start) { return <%= this %>; @@ -136,22 +105,6 @@ return <%= this %>; } -/** - * Changes all elements in the Array to a static value, from a start index to an end index - * - * @param value to fill the array with - * - * @param start index at which to start filling - * - * @param end index at which to end filling, but not including - * - * @returns this array after transformation - */ -<%= access_public %> fill<%= this_generic %>(<%= this_arg %>value: <%= el_type %>, start?: Number, end?: Number): <%= this_return_type %> { - <%= this_call.('fill') %>value, asIntOrDefault(start, 0), asIntOrDefault(end, <%= this_len_int %>)); - return <%= this %>; -} - /** * Changes all elements in the Array to a static value, from a start index to an end index * @@ -164,9 +117,9 @@ * @returns this array after transformation */ % if function_type != 'has_native' -<%= access_public %> fill<%= this_generic %>(<%= this_arg %>value: <%= el_type %>, start: int, end: int): <%= this_return_type %> { - start = normalizeIndex(start, <%= this_len_int %>); - end = normalizeIndex(end, <%= this_len_int %>) +<%= access_public %> fill<%= this_generic %>(<%= this_arg %>value: <%= el_type %>, start?: int, end?: int): <%= this_return_type %> { + start = normalizeIndex(start ?? 0, <%= this_len_int %>); + end = normalizeIndex(end ?? <%= this_len_int %>, <%= this_len_int %>) for (let i = start; i < end; i++) { <%= set_unsafe.(this, 'i', 'value') %>; @@ -176,7 +129,12 @@ } % else -<%= access_public %> native fill<%= this_generic %>(<%= this_arg %>value: <%= el_type %>, start: int, end: int): <%= this_return_type %>; +<%= access_public %> fill<%= this_generic %>(<%= this_arg %>value: <%= el_type %>, start?: int, end?: int): <%= this_return_type %> { + <%= this_call.('fillImpl') %>value, asIntOrDefault(start, 0), asIntOrDefault(end, <%= this_len_int %>)); + return <%= this %>; +} + +<%= access_private %> native fillImpl<%= this_generic %>(<%= this_arg %>value: <%= el_type %>, start: int, end: int): <%= this_return_type %>; % end % TemplateData::get_lambda_data.each { |lambda_args_params| @@ -209,7 +167,7 @@ * * @returns found element index or -1 otherwise */ -<%= access_public %> <%= override %> findIndex<%= this_generic %>(<%= this_arg %>predicate: (value: <%= el_type %><%= lambda_params %>) => boolean): number { +<%= access_public %> <%= override %> findIndex<%= this_generic %>(<%= this_arg %>predicate: (value: <%= el_type %><%= lambda_params %>) => boolean): int { for (let i = 0; i < <%= this_len_int %>; i++) { if (predicate(<%= get_unsafe.(this, 'i') %><%= lambda_args %>)) { return i; @@ -283,7 +241,7 @@ * * @returns index of first element satisfying to predicate, -1 if no such element */ -<%= access_public %> <%= override %> findLastIndex<%= this_generic %>(<%= this_arg %>predicate: (element: <%= el_type %><%= lambda_params %>) => boolean): number { +<%= access_public %> <%= override %> findLastIndex<%= this_generic %>(<%= this_arg %>predicate: (element: <%= el_type %><%= lambda_params %>) => boolean): int { for (let i = <%= this_len_int %> - 1; i >= 0; i--) { if (predicate(<%= get_unsafe.(this, 'i') %><%= lambda_args %>)) { return i @@ -371,25 +329,10 @@ * * @returns `Array` instance, constructed from extracted elements of `this` instance. */ -<%= access_public %> <%= override %> slice<%= this_generic %>(<%= this_arg %>start?: Number, end?: Number): <%= this_type %> { - const len: int = <%= this_len_int %>; - return <%= this_call.('slice') %>asIntOrDefault(start, 0), asIntOrDefault(end, len)) -} - -/** - * Creates a new `Array` object and populates it with elements of `this` instance of `Array` class - * selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that array. - * - * @param start zero-based index at which to start extraction - * - * @param end zero-based index at which to end extraction. `slice()` extracts up to but not including end. - * - * @returns `Array` instance, constructed from extracted elements of `this` instance. - */ -<%= access_public %> slice<%= this_generic %>(<%= this_arg %>start: int, end: int): <%= this_type %> { +<%= access_public %> slice<%= this_generic %>(<%= this_arg %>start?: int, end?: int): <%= this_type %> { const len: int = <%= this_len_int %>; - const relStart = normalizeIndex(start, len) - const relEnd = normalizeIndex(end, len) + const relStart = normalizeIndex(start ?? 0, len) + const relEnd = normalizeIndex(end ?? len, len) let count = relEnd - relStart; if (count < 0) { @@ -641,25 +584,11 @@ private joinObject(sep?: String): string { * * @returns a new Array with some elements removed and/or replaced at a given index. */ -<%= access_public %> toSpliced<%= this_generic %>(<%= this_arg %>start?: Number, delete?: Number): <%= this_type %> { +<%= access_public %> toSpliced<%= this_generic %>(<%= this_arg %>start?: int, delete?: int): <%= this_type %> { const len = <%= this_len_int %>; return <%= this_call.('toSpliced') %>asIntOrDefault(start, len), asIntOrDefault(delete, len)) } -/** - * Copying version of the splice() method. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns a new Array with some elements removed and/or replaced at a given index. - */ -<%= access_public %> toSpliced<%= this_generic %>(<%= this_arg %>start: number, delete: number, ...items: FixedArray<<%= el_type %>>): <%= this_type %> { - const len = <%= this_len_int %>; - return <%= this_call.('toSpliced') %>start.toInt(), delete.toInt(), ...items) -} - /** * Copying version of the splice() method. * @@ -714,7 +643,7 @@ private joinObject(sep?: String): string { * * @returns true if val is in Array */ -<%= access_public %> <%= override %> includes<%= this_generic %>(<%= this_arg %>val: <%= el_type %>, fromIndex?: Number): boolean { +<%= access_public %> <%= override %> includes<%= this_generic %>(<%= this_arg %>val: <%= el_type %>, fromIndex?: int): boolean { const len = <%= this_len_int %>; const fi = normalizeIndex(asIntOrDefault(fromIndex, 0), len); % if ['float', 'double', 'number'].include?(el_type) @@ -867,20 +796,6 @@ private joinObject(sep?: String): string { return <%= from_buffer.('arr') %> } -/** - * Copying version of using the bracket notation to change the value of a given index. - * It returns a new Array with the element at the given index replaced with the given value. - * - * @param index to replace - * - * @param value new value - * - * @returns a new Array with the element at the given index replaced with the given value - */ -<%= access_public %> with<%= this_generic %>(<%= this_arg %>index: number, value: <%= el_type %>): <%= this_type %> { - return <%= this_call.('with') %>index.toInt(), value) -} - /** * Copying version of using the bracket notation to change the value of a given index. * It returns a new Array with the element at the given index replaced with the given value. diff --git a/static_core/plugins/ets/templates/stdlib/Array_escompat.erb b/static_core/plugins/ets/templates/stdlib/Array_escompat.erb index 31be6ff0001f6c3bfba1b3bf7d28c379ddae633b..21aa3a603f3e14623ecc400314f5b2e0cc3a3f77 100644 --- a/static_core/plugins/ets/templates/stdlib/Array_escompat.erb +++ b/static_core/plugins/ets/templates/stdlib/Array_escompat.erb @@ -627,7 +627,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns new length */ - public pushArray(...val: T[]): number { + public pushArray(...val: T[]): int { this.ensureUnusedCapacity(val.length.toInt()) for (let i = 0; i < val.length; i++) { this.buffer[this.actualLength + i] = val[i] @@ -645,7 +645,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns new length */ - public pushOne(val: T): number { + public pushOne(val: T): int { this.ensureUnusedCapacity(1) this.buffer[this.actualLength] = val this.actualLength += 1 @@ -658,7 +658,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns new length */ - public pushECMA(...val: T[]): number { + public pushECMA(...val: T[]): int { this.ensureUnusedCapacity(val.length.toInt()) for (let i = 0; i < val.length; i++) { this.buffer[this.actualLength + i] = val[i] @@ -687,21 +687,10 @@ export class Array implements ReadonlyArray, Iterable { * * @returns an Array with deleted elements */ - public splice(start: number, delete: Number | undefined, ...items: T[]): Array { - return this.splice(start.toInt(), asIntOrDefault(delete, 0), ...items) - } - - /** - * Changes the contents of an array by removing or replacing existing elements - * and/or adding new elements in place. - * - * @param start index - * - * @param delete number of items after start index - * - * @returns an Array with deleted elements - */ - public splice(start: int, delete: int, ...items: T[]): Array { + public splice(start: int, delete: int | undefined, ...items: T[]): Array { + if (delete === undefined) { + delete = 0 + } start = normalizeIndex(start, this.actualLength) if (delete < 0) { delete = 0 @@ -741,18 +730,6 @@ export class Array implements ReadonlyArray, Iterable { return ret } - /** - * Changes the contents of an array by removing or replacing existing elements - * and/or adding new elements in place. - * - * @param start index - * - * @returns an Array with deleted elements from start to the last element of the current instance - */ - public splice(start: number): Array { - return this.splice(start.toInt()) - } - /** * Changes the contents of an array by removing or replacing existing elements * and/or adding new elements in place. @@ -804,7 +781,7 @@ export class Array implements ReadonlyArray, Iterable { * * @returns new length of the Array */ - public unshift(...values: T[]): number { + public unshift(...values: T[]): int { if (this.buffer.length <= values.actualLength + this.actualLength) { let buffer: FixedArray = new Any[this.buffer.length * 2 + values.actualLength] this.unshiftInternal(buffer, values) diff --git a/static_core/plugins/ets/tests/checked/escompat_array_fill.ets b/static_core/plugins/ets/tests/checked/escompat_array_fill.ets index 9eb7eac7ff7ba513c4c939d1863adc8678c77d5d..ee15993c5355c08dc19cd17afb997dcc569affa8 100644 --- a/static_core/plugins/ets/tests/checked/escompat_array_fill.ets +++ b/static_core/plugins/ets/tests/checked/escompat_array_fill.ets @@ -113,7 +113,7 @@ class MyArray extends Array { this.counter = 0; } - public override fill(value: T, start: int, end: int): this { + public override fill(value: T, start?: int, end?: int): this { this.counter += 1; super.fill(value, start, end); return this; diff --git a/static_core/plugins/ets/tests/ets_es_checked/array.yaml b/static_core/plugins/ets/tests/ets_es_checked/array.yaml index bcb4072cbaee9affd81b233efd58b17be730930b..40b1d52027cce1b8e59833c868b0fa03d9bed88f 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/array.yaml @@ -20,7 +20,6 @@ sub: self_type: Array vars: default_inds: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, 5, 100, -1, 2, "0x8", "-0o4"] - default_inds_number: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1.1, 5.0, 100.0, -1.1, 2.0, "Infinity", "-Infinity", "NaN", "0x8 as number", "-0o4 as number"] default_inds_undef: ["self.length", "-self.length", "self.length - 1", "-self.length + 1", 1, 5, 100, -1, 2, "0x8", "-0o4", "undefined"] default_search: ["NaN", "-NaN", "Infinity", "-Infinity", 0.0, "-0.0", 100, 1] reduce_lamdbas: @@ -86,8 +85,8 @@ sub: - method: "splice" ret_type: Array params: - - paramOf(*default_inds_number) - - paramOf(*default_inds_number) + - paramOf(*default_inds) + - paramOf(*default_inds) mandatory: 1 rest: - combinationRest 31, 34, 45 @@ -198,7 +197,7 @@ sub: - method: includes params: - paramOf("null", "undefined", '""', '"123"', 123, "NaN") - - paramOf(0.0, 1.0, 2.0, 3.0) + - paramOf(0, 1, 2, 3) mandatory: 1 - method: indexOf params: diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListTest.ets index 387699482b14aa92a5ec540caaf4b7033614400e..4df4bc5f44babc82ca27c4ea04e5468e23ff61b5 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListTest.ets @@ -46,13 +46,13 @@ function testLinkedListBasicCRUD() { list.removeByIndex(9); - testArray.splice(9.0, 1.0); + testArray.splice(9, 1); for (let i: int = 0; i < testArray.length; i++) { arktest.assertEQ(list.get(i), testArray[i]); } const removeRes = list.remove(8); - testArray.splice(8.0, 1.0); + testArray.splice(8, 1); for (let i: int = 0; i < testArray.length; i++) { arktest.assertEQ(list.get(i), testArray[i]); } @@ -61,7 +61,7 @@ function testLinkedListBasicCRUD() { arktest.assertEQ(list.getLast(), 7); list.insert(3, 999); - testArray.splice(3.0, 0.0, 999); + testArray.splice(3, 0, 999); for (let i: int = 0; i < testArray.length; i++) { arktest.assertEQ(list.get(i), testArray[i]); } diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListTests.ets index 7f8b092152e5f18d707df142021352b4e2fb912f..abd487863fbb11d100182e52137c5ca979a112ea 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListTests.ets @@ -106,13 +106,13 @@ function testBasicOperationsAndMethods() { arktest.assertEQ(list.getIndexOf(5), 5); list.removeByIndex(10); - testArray.splice(10.0, 1.0); + testArray.splice(10, 1); for (let i: int = 0; i < testArray.length; i++) { arktest.assertEQ(list[i], testArray[i]); } list.remove(9); - testArray.splice(9.0, 1.0); + testArray.splice(9, 1); for (let i: int = 0; i < testArray.length; i++) { arktest.assertEQ(list[i], testArray[i]); testArray[i] = testArray[i] * 2; @@ -128,7 +128,7 @@ function testBasicOperationsAndMethods() { arktest.assertEQ(list.getFirst(), 0); arktest.assertEQ(list.getLast(), 16); list.insert(999, 3); - testArray.splice(3.0, 0.0, 999); + testArray.splice(3, 0, 999); for (let i: int = 0; i < testArray.length; i++) { arktest.assertEQ(list[i], testArray[i]); } diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/PlainArray/PlainArrayTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/PlainArray/PlainArrayTest.ets index 74c03bff709b93f1ce0969e9ef06ee8293fad90a..0a1033014a79a73edadd1eb2d31125bde061f657 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/PlainArray/PlainArrayTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/PlainArray/PlainArrayTest.ets @@ -59,11 +59,11 @@ function testPlainArrayBasicOperations() { } const removeRes = plainArray.remove(3); - testArray.splice(3.0, 1.0); + testArray.splice(3, 1); arktest.assertEQ(removeRes, "3"); plainArray.removeAt(2); - testArray.splice(2.0, 1.0); + testArray.splice(2, 1); for (let i: int = 0; i < testArray.length; i++) { arktest.assertEQ(plainArray.getValueAt(i), testArray[i]); diff --git a/static_core/plugins/ets/tests/interop_js/tests/array/ts_to_ets/test_sts_array.ets b/static_core/plugins/ets/tests/interop_js/tests/array/ts_to_ets/test_sts_array.ets index 2d630844c0342ae09f941cda150240bed715e915..af734a165c92ad6e8046d5fb0fe3c240f1e44ad0 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/array/ts_to_ets/test_sts_array.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/array/ts_to_ets/test_sts_array.ets @@ -120,7 +120,7 @@ function testConcat(): boolean { } function testCopyWithin(): boolean { - return arrayCopyWithin1.copyWithin(1).toString() === "1,1,2,3" && arrayCopyWithin2.copyWithin(0, 2).toString() === "3,4,3,4" && arrayCopyWithin3.copyWithin(0.0, 1, 3).toString() === "2,3,3,4" + return arrayCopyWithin1.copyWithin(1).toString() === "1,1,2,3" && arrayCopyWithin2.copyWithin(0, 2).toString() === "3,4,3,4" && arrayCopyWithin3.copyWithin(0, 1, 3).toString() === "2,3,3,4" } function testEntries(): boolean { @@ -132,7 +132,7 @@ return !array.every(funcPredicate1) && array.every(funcPredicate2) } function testFill(): boolean { - return arrayFill.fill(8.0, 1.0, 3.0).toString() === "1,8,8,4" + return arrayFill.fill(8.0, 1, 3).toString() === "1,8,8,4" } function testFilter(): boolean { @@ -248,7 +248,7 @@ function testSort(): boolean { } function testSplice(): boolean { - return arraySplice1.splice(1).toString() === "2,3,4" && arraySplice3.splice(1.0, 1, 2).toString() === "2" && arraySplice4.splice(1.0, 2, 6, 7).toString() === "2,3" + return arraySplice1.splice(1).toString() === "2,3,4" && arraySplice3.splice(1, 1, 2).toString() === "2" && arraySplice4.splice(1, 2, 6, 7).toString() === "2,3" } function testToLocaleString(): boolean { @@ -282,6 +282,6 @@ function testValues(): boolean { } function testWith(): boolean { - let a = array.with(1.0, 8.0) + let a = array.with(1, 8.0) return a.toString() === "1,8,3,4" } diff --git a/static_core/plugins/ets/tests/interop_js/tests/escompat/escompat.ets b/static_core/plugins/ets/tests/interop_js/tests/escompat/escompat.ets index 28e170f03f6c1f4b9504329a83a3ab25cb722e71..5fc42aee21e24cc757514ca5d3734bea7ed8d1f1 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/escompat/escompat.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/escompat/escompat.ets @@ -44,7 +44,7 @@ function Array_TestJSSample(arr: Array): void { arktest.assertEQ((arr.at(0)! as FooClass).name, "zero"); arktest.assertEQ(arr.at(1)!.toString(), "{Foo named one}"); - let idx: number = 0; + let idx = 0; arktest.assertEQ((arr.at(idx)! as FooClass).name, "zero"); arr.push(new FooClass("two")); diff --git a/static_core/plugins/ets/tests/interop_js/tests/test_any/test_any_static.ets b/static_core/plugins/ets/tests/interop_js/tests/test_any/test_any_static.ets index 581b705d254e6bd43c2b1dfdb49612cd28d2d191..6e96aaae287288e749dc904aa5cf3d01dbaf452f 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/test_any/test_any_static.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/test_any/test_any_static.ets @@ -108,14 +108,14 @@ function testCallWithUndefined() { function testArray(): void { let arr1: Array = arrNum.with(1, 8); - let arr2: Array = arrNum.with(1.0, 8.0); + let arr2: Array = arrNum.with(1, 8.0); arktest.assertEQ(arr1.toString(), '1,8,3,4'); arktest.assertEQ(arr2.toString(), '1,8,3,4'); } function testArrayFill(): void { let arr1: Array = arrFill.fill(8, 1, 3); - let arr2: Array = arrFill.fill(8.0, 1.0, 3.0); + let arr2: Array = arrFill.fill(8.0, 1, 3); arktest.assertEQ(arr1.toString(), '1,8,8,4'); arktest.assertEQ(arr2.toString(), '1,8,8,4'); } diff --git a/static_core/plugins/ets/tests/stdlib-templates/escompat/escompat_Array_misc.ets b/static_core/plugins/ets/tests/stdlib-templates/escompat/escompat_Array_misc.ets index d880e6b3d2a2670e7f8f74dfe0b577e076f64252..2202ee9a70a2e65f43a9ca4fc37c3c7935d53637 100644 --- a/static_core/plugins/ets/tests/stdlib-templates/escompat/escompat_Array_misc.ets +++ b/static_core/plugins/ets/tests/stdlib-templates/escompat/escompat_Array_misc.ets @@ -112,7 +112,7 @@ function testJoin1(): int { function testSlice0(): int { const src = Array.from(source2) - let sliceStart: number = 0 + let sliceStart = 0 let sliceEnd = src.length let length = sliceEnd - sliceStart @@ -135,7 +135,7 @@ function testSlice0(): int { function testSlice1(): int { let src = new Array(source2) - let sliceStart: number = 0 + let sliceStart = 0 let sliceEnd = src.length let length = sliceEnd - sliceStart @@ -158,7 +158,7 @@ function testSlice1(): int { function testSlice2(): int { let src = new Array(source2) - let sliceStart: number = 0 + let sliceStart = 0 let sliceEnd = src.length let length = sliceEnd - sliceStart