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..173f2c0eb11b1f7da9352553e4ccbad34460d310 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 @@ -212,11 +212,9 @@ private: {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/sdk/api/@ohos.util.stream.ets b/static_core/plugins/ets/sdk/api/@ohos.util.stream.ets index c67dbc62e46dd329d8ea05ae16aa6b6d47bb7a4c..b04f1c9742a1b63e7f98b48a1da231ac6cd645bc 100755 --- a/static_core/plugins/ets/sdk/api/@ohos.util.stream.ets +++ b/static_core/plugins/ets/sdk/api/@ohos.util.stream.ets @@ -232,7 +232,7 @@ export namespace stream { off(event: string, callback: Function): void { if (this.handlers.has(event)) { const funcList = this.handlers.get(event); - const pos = funcList!.findIndex((element) => element === callback); + const pos = funcList!.findIndex((element) => element === callback).toInt(); if (pos !== -1) { funcList!.splice(pos, 1); } diff --git a/static_core/plugins/ets/stdlib/escompat/Array.ets b/static_core/plugins/ets/stdlib/escompat/Array.ets index aef109230b0f76baaa20b6f1ff1b49925f15e241..25fafc452564811feb30a11418b0526d2eab7a11 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) diff --git a/static_core/plugins/ets/stdlib/std/core/Proxy.ets b/static_core/plugins/ets/stdlib/std/core/Proxy.ets index 10bb69dbdaef9bfce6657caef006e17ce4af2d07..399fed43ba03e5a6304c578d604e61fc9da490e6 100644 --- a/static_core/plugins/ets/stdlib/std/core/Proxy.ets +++ b/static_core/plugins/ets/stdlib/std/core/Proxy.ets @@ -783,7 +783,6 @@ 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)) @@ -793,9 +792,6 @@ abstract class ArrayProxy extends Array { 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 +860,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 +892,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) { @@ -960,9 +937,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/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/ets_es_checked/array.yaml b/static_core/plugins/ets/tests/ets_es_checked/array.yaml index bcb4072cbaee9affd81b233efd58b17be730930b..b947326370841bd44137de5ebdfe1894f32ecc71 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 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..665d91930abccdb7e818e5325a90ab0ec1ff327b 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 @@ -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 {