1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * @tc.name:array
18 * @tc.desc:test Array
19 * @tc.type: FUNC
20 * @tc.require: issueI5NO8G
21 */
22var arr = new Array(100);
23var a = arr.slice(90, 100);
24print(a.length);
25
26var arr1 = [1, 1, 1, 1, 1, 1];
27arr1.fill(0, 2, 4);
28print(arr1);
29
30var arr2 = new Array(100);
31arr2.fill(0, 2, 4);
32var a1 = arr2.slice(0, 5);
33print(arr2.length);
34print(a1);
35
36var arr3 = [1, 2, 3, 4, 5, 6];
37arr3.pop();
38print(arr3.length);
39print(arr3);
40
41var arr4 = [1, 3, 4];
42arr4.splice(1, 0, 2);
43print(arr4.length);
44print(arr4);
45// 1, 2, 3, 4
46var arr4 = [1, 2, 3, 4];
47arr4.splice(3, 1, 3);
48print(arr4.length);
49print(arr4);
50// 1, 2, 3, 3
51
52var arr5 = [1, 2, 3, 4, 5, 6];
53arr5.shift();
54print(arr5.length);
55print(arr5);
56// 1, 2, 3, 4, 5
57
58var arr6 = [1, 2, 3, 4, 5];
59arr6.reverse();
60print(arr6);
61
62var arr7 = [];
63arr7[2] = 10;
64print(arr7.pop()); // 10
65print(arr7.pop()); // undefined
66print(arr7.pop()); // undefined
67
68var arr8 = [];
69arr8[1] = 8;
70print(arr8.shift()); // undefined
71print(arr8.shift()); // 8
72print(arr8.shift()); // undefined
73
74// Test on Array::Splice
75var arr9 = new Array(9);
76print(arr9.length); // 9
77arr9.splice(0, 9);
78print(arr9.length); // 0
79for (let i = 0; i < arr9.length; i++) {
80    print(arr9[i]);
81}
82
83var arr10 = new Array(9);
84print(arr10.length); // 9
85arr10.splice(0, 8, 1);
86print(arr10.length); // 2
87for (let i = 0; i < arr10.length; i++) {
88    print(arr10[i]); // 1, undefined
89}
90
91var arr11 = new Array(9);
92print(arr11.length); // 9
93arr11.splice(1, 8, 1);
94print(arr11.length); // 2
95for (let i = 0; i < arr11.length; i++) {
96    print(arr11[i]); // undefined, 1
97}
98
99var arr12 = new Array(9);
100print(arr12.length); // 9
101arr12.splice(0, 4, 1, 2, 3, 4, 5);
102print(arr12.length); // 10
103for (let i = 0; i < arr12.length; i++) {
104    print(arr12[i]); // 1, 2, 3, 4, 5, undefined, undefined, undefined, undefined, undefined
105}
106
107var arr13 = new Array(9);
108print(arr13.length); // 9
109arr13.splice(7, 5, 1, 2, 3);
110print(arr13.length); // 10
111for (var i = 0; i < arr13.length; i++) {
112    print(arr13[i]); // undefined, undefined, undefined, undefined, undefined, undefined, undefined, 1, 2, 3
113}
114
115var arr14 = Array.apply(null, Array(16));
116print(arr14.length);
117var arr15 = Array.apply(null, [1, 2, 3, 4, 5, 6]);
118print(arr15.length);
119
120var a = '0';
121print(Array(5).indexOf(a));
122
123const v3 = new Float32Array(7);
124try {
125    v3.filter(Float32Array)
126} catch (error) {
127    print("The NewTarget is undefined")
128}
129
130const v20 = new Array(2);
131let v21;
132try {
133    v21 = v20.pop();
134    print(v21);
135} catch (error) {
136
137}
138
139var arr21 = [1, 2, 3, 4, , 6];
140print(arr21.at(0));
141print(arr21.at(5));
142print(arr21.at(-1));
143print(arr21.at(6));
144print(arr21.at('1.9'));
145print(arr21.at(true));
146var arr22 = arr21.toReversed();
147print(arr22)
148print(arr21)
149var arr23 = [1, 2, 3, 4, 5];
150print(arr23.with(2, 6)); // [1, 2, 6, 4, 5]
151print(arr23); // [1, 2, 3, 4, 5]
152
153const months = ["Mar", "Jan", "Feb", "Dec"];
154const sortedMonths = months.toSorted();
155print(sortedMonths); // ['Dec', 'Feb', 'Jan', 'Mar']
156print(months); // ['Mar', 'Jan', 'Feb', 'Dec']
157
158const values = [1, 10, 21, 2];
159const sortedValues = values.toSorted((a, b) => {
160    return a - b
161});
162print(sortedValues); // [1, 2, 10, 21]
163print(values); // [1, 10, 21, 2]
164
165const arrs = new Array(6);
166for (let i = 0; i < 6; i++) {
167    var str = i.toString();
168    if (i != 1) {
169        arrs[i] = str;
170    }
171}
172arrs.reverse();
173print(arrs); // 5,4,3,2,,0
174
175function handleExpectedErrorCaught(prompt, e) {
176    if (e instanceof Error) {
177        print(`Expected ${e.name} caught in ${prompt}.`);
178    } else {
179        print(`Expected error message caught in ${prompt}.`);
180    }
181}
182
183function handleUnexpectedErrorCaught(prompt, e) {
184    if (e instanceof Error) {
185        print(`Unexpected ${e.name} caught in ${prompt}: ${e.message}`);
186        if (typeof e.stack !== 'undefined') {
187            print(`Stacktrace:\n${e.stack}`);
188        }
189    } else {
190        print(`Unexpected error message caught in ${prompt}: ${e}`);
191    }
192}
193
194// Test cases for reverse()
195print("======== Begin: Array.prototype.reverse() ========");
196try {
197    const arr0 = [];
198    print(`arr0.reverse() === arr0 ? ${arr0.reverse() === arr0}`); // true
199    print(`arr0.length after reverse() called = ${arr0.length}`); // 0
200
201    const arr1 = [1];
202    print(`arr1.reverse() === arr1 ? ${arr1.reverse() === arr1}`); // true
203    print(`arr1 after reverse() called = ${arr1}`); // 1
204
205    const arrWithHoles = [];
206    arrWithHoles[1] = 1;
207    arrWithHoles[4] = 4;
208    arrWithHoles[6] = undefined;
209    arrWithHoles.length = 10;
210    // arrWithHoles = [Hole, 1, Hole, Hole, 4, Hole, undefined, Hole, Hole, Hole]
211    print(`arrWithHoles before reverse() called = ${arrWithHoles}`); // ,1,,,4,,,,,
212    print(`arrWithHoles.reverse()               = ${arrWithHoles.reverse()}`); // ,,,,,4,,,1,
213    print(`arrWithHoles after reverse() called  = ${arrWithHoles}`); // ,,,,,4,,,1,
214} catch (e) {
215    handleUnexpectedErrorCaught(e);
216}
217print("======== End: Array.prototype.reverse() ========");
218
219print("======== Begin: Array.prototype.indexOf() & Array.prototype.lastIndexOf() ========");
220// Test case for indexOf() and lastIndexOf()
221try {
222    const arr = [0, 10, 20];
223    arr.length = 10;
224    arr[3] = 80;
225    arr[4] = 40;
226    arr[6] = undefined;
227    arr[7] = 10;
228    arr[8] = "80";
229    print("arr = [0, 10, 20, 80, 40, Hole, undefined, 10, \"80\", Hole]");
230    // prompt1, results1, prompt2, results2, ...
231    const resultGroups = [
232        "Group 1: 0 <= fromIndex < arr.length", [
233    arr.indexOf(40), // 4
234    arr.indexOf(40, 5), // -1
235    arr.indexOf(10), // 1
236    arr.indexOf(10, 2), // 7
237    arr.lastIndexOf(40), // 4
238    arr.lastIndexOf(40, 3), // -1
239    arr.lastIndexOf(10), // 7
240    arr.lastIndexOf(10, 6), // 1
241    ],
242        "Group 2: -arr.length <= fromIndex < 0", [
243    arr.indexOf(40, -4), // -1
244    arr.indexOf(40, -8), // 4
245    arr.indexOf(10, -4), // 7
246    arr.indexOf(10, -10), // 1
247    arr.lastIndexOf(40, -4), // 4
248    arr.lastIndexOf(40, -8), // -1
249    arr.lastIndexOf(10, -4), // 1
250    arr.lastIndexOf(10, -10), // -1
251    arr.indexOf(0, -arr.length), // 0
252    arr.indexOf(10, -arr.length), // 1
253    arr.lastIndexOf(0, -arr.length), // 0
254    arr.lastIndexOf(10, -arr.length), // -1
255    ],
256        "Group 3: fromIndex >= arr.length", [
257    arr.indexOf(0, arr.length), // -1
258    arr.indexOf(0, arr.length + 10), // -1
259    arr.indexOf(10, arr.length),
260    arr.indexOf(10, arr.length + 10),
261    arr.lastIndexOf(0, arr.length), // 0
262    arr.lastIndexOf(0, arr.length + 10), // 0
263    ],
264        "Group 4: fromIndex < -arr.length", [
265    arr.indexOf(0, -arr.length - 10), // 0
266    arr.lastIndexOf(0, -arr.length - 10) // -1
267    ],
268        "Group 5: fromIndex in [Infinity, -Infinity]", [
269    arr.indexOf(10, -Infinity), // 1
270    arr.indexOf(10, +Infinity), // -1
271    arr.lastIndexOf(10, -Infinity), // -1
272    arr.lastIndexOf(10, +Infinity) // 7
273    ],
274        "Group 6: fromIndex is NaN", [
275    arr.indexOf(0, NaN), // 0
276    arr.indexOf(10, NaN), // 1
277    arr.lastIndexOf(0, NaN), // 0
278    arr.lastIndexOf(10, NaN), // -1
279    ],
280        "Group 7: fromIndex is not of type 'number'", [
281    arr.indexOf(10, '2'), // 7
282    arr.lastIndexOf(10, '2'), // 1
283    arr.indexOf(10, { valueOf() {
284        return 3;
285    } }), // 7
286    arr.indexOf(10, { valueOf() {
287        return 3;
288    } }), // 1
289    ],
290        "Group 8: Strict equality checking", [
291    arr.indexOf("80"), // 8
292    arr.lastIndexOf(80), // 3
293    ],
294        "Group 9: Searching undefined and null", [
295    arr.indexOf(), // 6
296    arr.indexOf(undefined), // 6
297    arr.indexOf(null), // -1
298    arr.lastIndexOf(), // 6
299    arr.lastIndexOf(undefined), // 6
300    arr.lastIndexOf(null) // -1
301    ]
302    ];
303    for (let i = 0; i < resultGroups.length; i += 2) {
304        print(`${resultGroups[i]}: ${resultGroups[i + 1]}`);
305    }
306
307    print("Group 10: fromIndex with side effects:");
308    let accessCount = 0;
309    const arrProxyHandler = {
310        has(target, key) {
311            accessCount += 1;
312            return key in target;
313        }
314    };
315    // Details on why accessCount = 6 can be seen in ECMAScript specifications:
316    // https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.indexof
317    accessCount = 0;
318    const arr2 = new Proxy([10, 20, 30, 40, 50, 60], arrProxyHandler);
319    const result2 = arr2.indexOf(30, {
320        valueOf() {
321            arr2.length = 2; // Side effects to arr2
322            return 0;
323        }
324    }); // Expected: -1 (with accessCount = 6)
325    print(`  - indexOf:     result = ${result2}, accessCount = ${accessCount}`);
326    // Details on why accessCount = 6 can be seen in ECMAScript specifications:
327    // https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.lastindexof
328    accessCount = 0;
329    const arr3 = new Proxy([15, 25, 35, 45, 55, 65], arrProxyHandler);
330    const result3 = arr3.lastIndexOf(45, {
331        valueOf() {
332            arr3.length = 2; // Side effects to arr3
333            return 5;
334        }
335    }); // Expected: -1 (with accessCount = 6)
336    print(`  - lastIndexOf: result = ${result3}, accesscount = ${accessCount}`);
337
338    print("Group 11: fromIndex that triggers exceptions:");
339    for (let [prompt, fromIndex] of [["bigint", 1n], ["symbol", Symbol()]]) {
340        for (let method of [Array.prototype.indexOf, Array.prototype.lastIndexOf]) {
341            try {
342                const result = method.call(arr, 10, fromIndex);
343                print(`ERROR: Unexpected result (which is ${result}) returned by method '${method.name}': ` +
344                `Expects a TypeError thrown for fromIndex type '${prompt}'.`);
345            } catch (e) {
346                // Expects a TypeError thrown and caught here.
347                handleExpectedErrorCaught(`${method.name} when fromIndex is ${prompt}`, e);
348            }
349        }
350    }
351} catch (e) {
352    handleUnexpectedErrorCaught(e);
353}
354print("======== End: Array.prototype.indexOf() & Array.prototype.lastIndexOf() ========");
355
356// Test Array.prototype.filter when callbackFn is not callable
357try {
358    [].filter(1);
359} catch (e) {
360    print("CallbackFn is not callable");
361}
362
363var getTrap = function (t, key) {
364    if (key === "length") return { [Symbol.toPrimitive]() {
365        return 3
366    } };
367    if (key === "2") return "baz";
368    if (key === "3") return "bar";
369};
370var target1 = [];
371var obj = new Proxy(target1, { get: getTrap, has: () => true });
372print([].concat(obj));
373print(Array.prototype.concat.apply(obj))
374
375const v55 = new Float64Array();
376const v98 = [-5.335880620598348e+307, 1.0, 1.0, 2.220446049250313e-16, -1.6304390272817058e+308];
377
378function f99(a100) {
379}
380
381function f110() {
382    v98[2467] = v55;
383}
384
385Object.defineProperty(f99, Symbol.species, { configurable: true, enumerable: true, value: f110 });
386v98.constructor = f99;
387print(JSON.stringify(v98.splice(4)));
388
389var count;
390var params;
391
392class MyObserveArrray extends Array {
393    constructor(...args) {
394        super(...args);
395        print("constructor")
396        params = args;
397    }
398
399    static get [Symbol.species]() {
400        print("get [Symbol.species]")
401        count++;
402        return this;
403    }
404}
405
406count = 0;
407params = undefined;
408new MyObserveArrray().filter(() => {
409});
410print(count, 1);
411print(params, [0]);
412
413count = 0;
414params = undefined;
415new MyObserveArrray().concat(() => {
416});
417print(count, 1);
418print(params, [0]);
419
420count = 0;
421params = undefined;
422new MyObserveArrray().slice(() => {
423});
424print(count, 1);
425print(params, [0]);
426
427count = 0;
428params = undefined;
429new MyObserveArrray().splice(() => {
430});
431print(count, 1);
432print(params, [0]);
433
434new MyObserveArrray([1, 2, 3, 4]).with(0, 0);
435new MyObserveArrray([1, 2, 3, 4]).toReversed(0, 0);
436new MyObserveArrray([1, 2, 3, 4]).toSpliced(0, 0, 0);
437
438arr = new Array(1026);
439arr.fill(100);
440print(arr.with(0, "n")[0])
441
442arr = new Array(1026);
443arr.fill(100);
444print(arr.toReversed()[0])
445
446arr = new Array(1026);
447arr.fill(100);
448print(arr.toSpliced(0, 0, 0, 0)[0])
449
450var arr25 = []
451arr25[1025] = 0;
452print(arr25.includes({}, 414));
453print(arr25.includes(1025,109));
454
455var arr26 = []
456arr25[100] = 0;
457print(arr25.includes({}, 26));
458
459function fun1(obj, name, type) {
460    return typeof type === 'undefined' || typeof desc.value === type;
461}
462
463function fun2(obj, type) {
464    let properties = [];
465    let proto = Object.getPrototypeOf(obj);
466    while (proto && proto != Object.prototype) {
467        Object.getOwnPropertyNames(proto).forEach(name => {
468            if (name !== 'constructor') {
469                if (fun1(proto, name, type)) properties.push(name);
470            }
471        });
472        proto = Object.getPrototypeOf(proto);
473    }
474    return properties;
475}
476
477function fun4(seed) {
478    let objects = [Object, Error, AggregateError, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, String, BigInt, Function, Number, Boolean, Date, RegExp, Array, ArrayBuffer, DataView, Int8Array, Int16Array, Int32Array, Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array, Set, Map, WeakMap, WeakSet, Symbol, Proxy];
479    return objects[seed % objects.length];
480}
481
482function fun8(obj, seed) {
483    let properties = fun2(obj);
484}
485
486fun4(694532)[fun8(fun4(694532), 527224)];
487Object.freeze(Object.prototype);
488
489Array.prototype.length = 3000;
490print(Array.prototype.length)
491
492let unscopables1 = Array.prototype[Symbol.unscopables];
493let unscopables2 = Array.prototype[Symbol.unscopables];
494print(unscopables1 == unscopables2)
495
496arr = []
497let index = 4294967291;
498arr[index] = 0;
499arr.length = 10;
500arr.fill(10);
501print(arr)
502
503// Test case for copyWithin()
504var arr_copywithin1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
505var arr_copywithin2 = new Array();
506for (let i = 0; i < 10; i++) arr_copywithin2[i] = i;
507var arr_copywithin3 = new Array();
508for (let i = 0; i < 10; i++) {
509    if (i == 2) {
510        continue;
511    }
512    arr_copywithin3[i] = i;
513}
514var arr_copywithin4 = new Array();
515for (let i = 0; i < 10; i++) arr_copywithin4[i] = i;
516var result_copywithin1 = arr_copywithin1.copyWithin(0, 3, 7);
517print(result_copywithin1);
518var result_copywithin2 = arr_copywithin2.copyWithin(0, 3, 7);
519print(result_copywithin2);
520var arr_copywithin3 = arr_copywithin3.copyWithin(0, 0, 10);
521print(arr_copywithin3);
522//elementskind is generic but hclass == generic hclass
523var arr_copywithin4 = arr_copywithin4.copyWithin(3, 0, 6);
524print(arr_copywithin4);
525
526const ArraySize = 10;
527const QuarterSize = ArraySize / 4;
528let result;
529let arr_copywithin5 = [];
530let arr_copywithin6 = [];
531arr_copywithin6.proto = arr_copywithin4;
532for (let i = 0; i < ArraySize; ++i) arr_copywithin5[i] = i;
533for (let i = 0; i < ArraySize; ++i) arr_copywithin6[i] = i;
534
535for (let i = 0; i < ArraySize; i++) {
536    //elementskind is not generic
537    result = arr_copywithin5.copyWithin(0, QuarterSize * 2, QuarterSize * 3);
538}
539print(result);
540
541for (let i = 0; i < ArraySize; i++) {
542    //elementskind is generic but hclass != generic hclass
543    result = arr_copywithin6.copyWithin(0, QuarterSize * 2, QuarterSize * 3);
544}
545print(result);
546
547// Test case for every()
548var arr_every1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
549var arr_every2 = new Array();
550
551function testEvery(element, index, array) {
552    if (index == 0) {
553        array.length = 6;
554    }
555    return element < 6;
556}
557
558function testEvery4(element, index, array) {
559    array.pop();
560    array.pop();
561    array.pop();
562    return element < 6;
563}
564
565for (let i = 0; i < 10; i++) arr_every2[i] = i;
566var arr_every3 = new Array();
567for (let i = 0; i < 10; i++) {
568    if (i == 2) {
569        continue;
570    }
571    arr_every3[i] = i;
572}
573var arr_every4 = new Array();
574for (let i = 0; i < 10; i++) arr_every4[i] = i;
575var result_every1 = arr_every1.every(testEvery);
576print(result_every1);
577var result_every2 = arr_every2.every(testEvery);
578print(result_every2);
579var result_every3 = arr_every3.every(testEvery);
580print(result_every3);
581var result_every4 = arr_every4.every(testEvery4);
582print(result_every4);
583
584// Test case for reduceRight()
585var arr_reduceRight1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
586var arr_reduceRight2 = new Array();
587
588function testReduceRight(accumulator, element, index, array) {
589    if (index == 0) {
590        array.length = 6;
591    }
592    return accumulator + element;
593}
594
595function testReduceRight4(accumulator, element, index, array) {
596    array.pop();
597    array.pop();
598    return accumulator + element;
599}
600
601for (let i = 0; i < 10; i++) arr_reduceRight2[i] = i;
602var arr_reduceRight3 = new Array();
603for (let i = 0; i < 10; i++) {
604    if (i < 9) {
605        continue;
606    }
607    arr_reduceRight3[i] = i;
608}
609var arr_reduceRight4 = new Array();
610for (let i = 0; i < 10; i++) arr_reduceRight4[i] = i;
611var result_reduceRight1 = arr_reduceRight1.reduceRight(testReduceRight, 100);
612print(result_reduceRight1);
613var result_reduceRight2 = arr_reduceRight2.reduceRight(testReduceRight, 100);
614print(result_reduceRight2);
615var result_reduceRight3 = arr_reduceRight3.reduceRight(testReduceRight, 100);
616print(result_reduceRight3);
617var result_reduceRight4 = arr_reduceRight4.reduceRight(testReduceRight4, 100);
618print(result_reduceRight4);
619
620// Test case for some()
621var arr_some1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
622var arr_some2 = new Array();
623
624function testSome(element, index, array) {
625    if (index == 0) {
626        array.length = 6;
627    }
628    return element > 8;
629}
630
631for (let i = 0; i < 10; i++) arr_some2[i] = i;
632var arr_some3 = new Array();
633for (let i = 0; i < 10; i++) {
634    if (i < 9) {
635        continue;
636    }
637    arr_some3[i] = i;
638}
639var result_some1 = arr_some1.some(testSome);
640print(result_some1);
641var result_some2 = arr_some2.some(testSome);
642print(result_some2);
643var result_some3 = arr_some3.some(testSome);
644print(result_some3);
645
646// Test case for unshift()
647var arr_unshift1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
648var arr_unshift2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
649
650var result_unshift1 = arr_unshift1.unshift(1, 2, 3, 4, 5);
651print(result_unshift1);
652var result_unshift2 = arr_unshift2.unshift(1, 2, 3);
653print(result_unshift2);
654
655class C3 {
656    constructor(a5) {
657        try {
658            a5(this, this, ..."895053461", ..."p");
659        } catch (e) {
660        }
661    }
662
663    a;
664
665    valueOf(a9) {
666        const v10 = a9?.[this];
667        -718821.501160539 !== a9;
668        const t6 = "895053461";
669        t6[a9] = "895053461";
670        return v10;
671    }
672}
673
674const v12 = new C3("p");
675new C3(v12);
676new C3(C3);
677print(new C3(C3));
678
679// Test case for toSorted()
680var arr_toSorted1 = ["Mar", "Jan", "Feb", "Dec"];
681var arr_toSorted2 = new Array();
682arr_toSorted2[0] = "Mar";
683arr_toSorted2[1] = "Jan";
684arr_toSorted2[2] = "Feb";
685arr_toSorted2[3] = "Dec";
686var result_toSorted1 = arr_toSorted1.toSorted();
687print(result_toSorted1);
688var result_toSorted2 = arr_toSorted2.toSorted();
689print(result_toSorted2);
690
691const v0 = [0, 1];
692const mapEd = v0.map(() => {
693    v0["pop"]();
694});
695print(new Uint16Array(v0).length);
696
697try {
698    const v2 = new ArrayBuffer(103);
699
700    function F3(a5, a6) {
701        if (!new.target) {
702            throw 'must be called with new';
703        }
704
705        function f7(a8, a9, a10) {
706            return v2;
707        }
708
709        const v13 = new BigUint64Array(35);
710        const o14 = {
711            ...v13,
712        };
713        Object.defineProperty(o14, 4, { set: f7 });
714    }
715
716    new F3();
717    new F3();
718    v2();
719} catch (err) {
720    print(err.name);
721}
722
723try {
724    const v3 = new ArrayBuffer(45);
725    const v0 = new Boolean;
726
727    function F4(a6, a7) {
728        if (!new.target) {
729            throw 'must be called with new';
730        }
731
732        function f8(a9, a10, a11) {
733            return F4;
734        }
735
736        const v14 = new BigUint64Array(15);
737        const o20 = {
738            [v0](a16, a17, a18, a19) {
739                return a6;
740            },
741            ...v14,
742        };
743        Object.defineProperty(o20, 4, { set: f8 });
744    }
745
746    new F4(v0, 101);
747    new F4();
748    v3.transfer();
749} catch (err) {
750    print(err.name);
751}
752
753try {
754
755    function F6(a8, a9, a10) {
756        if (!new.target) {
757            throw 'must be called with new';
758        }
759        const v14 = new Date(-10, 16);
760        v14.toDateString();
761    }
762
763    const v16 = new F6(11);
764    new F6(2064);
765
766    function f18() {
767        return v16;
768    }
769
770    new BigUint64Array();
771    const v23 = [-42, 4, 4];
772    const o24 = {};
773    const v25 = [5.0, -5.12, 1e-15, -0.05, 5.0, 2.22e-38, -10.0, 10.0, 5.0, -5.0];
774
775    function f26() {
776        return v25;
777    }
778
779    class C28 extends Date {
780        constructor(a30, a31) {
781            super();
782        }
783    }
784
785    new Int8Array();
786    new Int8Array();
787    v23.filter(Array);
788    new ArrayBuffer(26);
789    const v44 = new Uint8Array();
790    v44.toString();
791    const o46 = {};
792    for (let i49 = -51, i50 = 10; i49 < i50; i50--) {
793        o46[i50] >>= i50;
794    }
795    /c/iusg;
796    const v58 = new Int16Array();
797    v58.forEach();
798} catch (err) {
799    print(err.name);
800}
801
802try {
803    const v3 = new ArrayBuffer(19);
804
805    function F4(a6, a7) {
806        if (!new.target) {
807            throw 'must be called with new';
808        }
809        const v10 = new BigUint64Array(34);
810        const o11 = {
811            ...v10,
812        };
813        Object.defineProperty(o11, 4, { set: a6 });
814    }
815
816    const v12 = new F4();
817    new F4(v12, v3);
818} catch (err) {
819    print(err.name);
820}
821
822try {
823    const v3 = new ArrayBuffer(10);
824
825    function F4(a6, a7) {
826        if (!new.target) {
827            throw 'must be called with new';
828        }
829
830        function f8(a9, a10, a11) {
831            return a11;
832        }
833
834        const v14 = new BigUint64Array(34);
835        const o15 = {
836            ...v14,
837        };
838        Object.defineProperty(o15, 4, { set: f8 });
839    }
840
841    const v16 = new F4();
842    new F4(v16, v3);
843    Int32Array();
844} catch (err) {
845    print(err.name);
846}
847
848try {
849    const v2 = new ArrayBuffer(10);
850
851    function F3(a5, a6) {
852        if (!new.target) {
853            throw 'must be called with new';
854        }
855
856        function f7(a8, a9, a10) {
857            return a9;
858        }
859
860        const v13 = new BigUint64Array(35);
861        const o14 = {
862            ...v13,
863        };
864        Object.defineProperty(o14, 4, { set: f7 });
865    }
866
867    new F3(ArrayBuffer, v2);
868    new F3(10, F3);
869    v2.transfer();
870} catch (err) {
871    print(err.name);
872}
873
874try {
875    const v1 = new Uint16Array();
876    for (let i4 = 0, i5 = 10; i5; i5--) {
877    }
878    undefined instanceof v1.values();
879} catch (error) {
880    print(error.name);
881}
882
883/*
884 * @tc.name:ArrayConstructor
885 * @tc.desc:test Array
886 * @tc.type: FUNC
887 */
888const originalArrays = [
889    [1, 2, 3],
890    ["apple", "banana", "orange"],
891    [true, false, true],
892    [{ name: "John" }, { name: "Doe" }],
893    [NaN, NaN, NaN],
894    [Infinity, -Infinity],
895    [RegExp("pattern1"), RegExp("pattern2")],
896    [new Map(), new Map()],
897    [new Set(), new Set()],
898    [Array.from([1, 2, 3]), Array.from([4, 5, 6])],
899    ["ark_unicodeValue �", "ark_unicodeValue �"],
900];
901
902for (let i = 0; i < originalArrays.length; i++) {
903    print(originalArrays[i]);
904}
905
906try {
907    const arr1 = [1, 2, 3];
908    print(arr1[10]);
909    print("Exception usage, but does not throw an error");
910} catch (error) {
911    print("Caught an error: " + error);
912}
913
914try {
915} catch (error) {
916    print("Caught an error: ", error);
917}
918
919try {
920    const arr2 = new Array(-1);
921} catch (error) {
922    print("Caught an error: ", error);
923}
924
925/*
926 * @tc.name:from
927 * @tc.desc:test Array
928 * @tc.type: FUNC
929 */
930const newArray = Array.from(originalArrays);
931newArray.forEach(array => {
932    print(array);
933});
934
935try {
936    Array.from([1, 2, 3], "not a function");
937} catch (error) {
938    print("Caught an error: ", error);
939}
940
941try {
942    Array.from([1, 2, 3], () => { throw new Error("Something went wrong"); });
943} catch (error) {
944    print("Caught an error: ", error);
945}
946
947try {
948    Array.from(123);
949    Array.from({});
950    Array.from([1, 2, 3], () => {}, 123);
951    print("Exception usage, but does not throw an error");
952} catch (error) {
953    print("Caught an error: " + error);
954}
955
956/*
957 * @tc.name:isArray
958 * @tc.desc:test Array
959 * @tc.type: FUNC
960 */
961originalArrays.forEach((array, index) => {
962    print(Array.isArray(array));
963});
964
965try {
966    print(Array.isArray());
967    print(Array.isArray(123));
968    print(Array.isArray("not an array"));
969    print(Array.isArray(null));
970    print(Array.isArray(undefined));
971} catch (error) {
972    print("Caught an error: ", error);
973}
974
975/*
976 * @tc.name:Of
977 * @tc.desc:test Array
978 * @tc.type: FUNC
979 */
980const ArrayOf = Array.of(...originalArrays);
981print(ArrayOf[1]);
982
983try {
984    const arr1 = Array.of(undefined);
985    const arr2 = Array.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
986    print(arr1);
987    print(arr2);
988} catch (error) {
989    print("Caught an error: ", error);
990}
991
992/*
993 * @tc.name:At
994 * @tc.desc:test Array
995 * @tc.type: FUNC
996 */
997print(originalArrays.at(1));
998print(originalArrays.at(3));
999print(originalArrays.at(-1));
1000print(originalArrays.at(-2));
1001
1002try {
1003    print(originalArrays.at());
1004    print(originalArrays.at(100));
1005    print(originalArrays.at(null));
1006    print(originalArrays.at(undefined));
1007    print(originalArrays.at(new Map()));
1008} catch (error) {
1009    print("Caught an error: ", error);
1010}
1011
1012/*
1013 * @tc.name:concat
1014 * @tc.desc:test Array
1015 * @tc.type: FUNC
1016 */
1017const array1 = [1, "two", true];
1018const array2 = [null, undefined, { key: "value" }];
1019const array3 = [];
1020
1021const concatenatedArray = array1.concat(array2, array3);
1022print("Concatenated Array:", concatenatedArray);
1023
1024const nestedArray = [[1, 2], ["a", "b"], [true, false]];
1025const nestedConcatenatedArray = array1.concat(nestedArray, array2);
1026print("Nested Concatenated Array:", nestedConcatenatedArray);
1027
1028const mixedConcatenatedArray = array1.concat(4, "five", { prop: "value" });
1029print("Mixed Concatenated Array:", mixedConcatenatedArray);
1030
1031const spreadConcatenatedArray = [...array1, ...array2, ...array3];
1032print("Spread Concatenated Array:", spreadConcatenatedArray);
1033
1034/*
1035 * @tc.name:CopyWithin,Entries
1036 * @tc.desc:test Array
1037 * @tc.type: FUNC
1038 */
1039const copiedArray1 = originalArrays[0].slice().copyWithin(0, 2);
1040const copiedArray2 = originalArrays[1].slice().copyWithin(1, 0, 2);
1041const copiedArray3 = originalArrays[2].slice().copyWithin(1, -2);
1042const copiedArray4 = originalArrays[3].slice().copyWithin(-1);
1043const copiedArray5 = originalArrays[4].slice().copyWithin(0);
1044
1045print("Original Arrays:", originalArrays);
1046print("Copied Array 1:", copiedArray1);
1047print("Copied Array 2:", copiedArray2);
1048print("Copied Array 3:", copiedArray3);
1049print("Copied Array 4:", copiedArray4);
1050print("Copied Array 5:", copiedArray5);
1051
1052for (const [index, value] of originalArrays.entries()) {
1053    print(`Index: ${index}`);
1054    print(`Value: ${value}`);
1055}
1056
1057/*
1058 * @tc.name:Every
1059 * @tc.desc:test Array
1060 * @tc.type: FUNC
1061 */
1062const numbers1 = [2, 4, 6, 8, 10];
1063const allEven = numbers1.every(num => num % 2 === 0);
1064print(allEven);
1065
1066const numbers2 = [1, 2, 3, 4, 5];
1067const allEven2 = numbers2.every(num => num % 2 === 0);
1068print(allEven2);
1069
1070const emptyArray1 = [];
1071const allEmpty = emptyArray1.every(num => num % 2 === 0);
1072print(allEmpty);
1073
1074const emptyArray2 = [];
1075const allEmpty2 = emptyArray2.every(() => true);
1076print(allEmpty2);
1077
1078const mixedArray = [2, 4, "hello", 8, 10];
1079const allNumbers = mixedArray.every(num => typeof num === "number");
1080print(allNumbers);
1081
1082const emptyArray3 = [];
1083const allNonNegative = emptyArray3.every(num => num >= 0);
1084print(allNonNegative);
1085
1086try {
1087    const arr = [1, 2, 3];
1088    const result = arr.every("not a function");
1089} catch (error) {
1090    print("Caught an error: ", error);
1091}
1092
1093try {
1094    const arr = [1, 2, 3];
1095    const result = arr.every(num => num < undefinedVariable);
1096} catch (error) {
1097    print("Caught an error: ", error);
1098}
1099
1100/*
1101 * @tc.name:Fill
1102 * @tc.desc:test Array
1103 * @tc.type: FUNC
1104 */
1105{
1106    const array1 = [1, 2, 3, 4, 5];
1107    print(array1.fill(0));
1108
1109    const array2 = [1, 2, 3, 4, 5];
1110    print(array2.fill(0, 2));
1111
1112    const array3 = [1, 2, 3, 4, 5];
1113    print(array3.fill(0, 1, 3));
1114
1115    const array4 = new Array(5);
1116    print(array4.fill(0));
1117
1118    const array5 = Array.from({ length: 5 }, (_, index) => index + 1);
1119    print(array5.fill(0, 2));
1120
1121    const array6 = Array.from({ length: 5 }, (_, index) => index + 1);
1122    print(array6.fill(0, 1, 3));
1123
1124    const array7 = Array(5).fill("hello");
1125    print(array7);
1126
1127    const array8 = [1, 2, 3];
1128    print(array8.fill(0, -2));
1129
1130    const array9 = [1, 2, 3];
1131    print(array9.fill(0, -2, -1));
1132}
1133
1134try {
1135    const arr = [1, 2, 3];
1136    arr.fill(0, 1.5);
1137} catch (error) {
1138    print("Caught an error: ", error);
1139}
1140
1141try {
1142    const arr = [1, 2, 3];
1143    arr.fill(0, NaN);
1144} catch (error) {
1145    print("Caught an error: ", error);
1146}
1147
1148/*
1149 * @tc.name:Filter
1150 * @tc.desc:test Array
1151 * @tc.type: FUNC
1152 */
1153{
1154    const numbers = [1, 2, 3, 4, 5];
1155
1156    const evenNumbers = numbers.filter(num => num % 2 === 0);
1157    print(evenNumbers);
1158
1159    const greaterThanTwo = numbers.filter(num => num > 2);
1160    print(greaterThanTwo);
1161
1162    const lessThanTen = numbers.filter(num => num < 10);
1163    print(lessThanTen);
1164
1165    const divisibleByThree = numbers.filter(num => num % 3 === 0);
1166    print(divisibleByThree);
1167
1168    const words = ["apple", "banana", "pear", "orange"];
1169    const longWords = words.filter(word => word.length >= 5);
1170    print(longWords);
1171
1172    const persons = [
1173        { name: "Alice", age: 25 },
1174        { name: "Bob", age: 17 },
1175        { name: "Charlie", age: 30 }
1176    ];
1177    const adults = persons.filter(person => person.age > 18);
1178    print(adults);
1179}
1180
1181try {
1182    const arr = [1, 2, 3];
1183    const result = arr.filter("not a function");
1184} catch (error) {
1185    print("Caught an error: ", error);
1186}
1187
1188try {
1189    const obj = { a: 1, b: 2 };
1190    const result = obj.filter(() => true);
1191} catch (error) {
1192    print("Caught an error: ", error);
1193}
1194
1195/*
1196 * @tc.name:Find
1197 * @tc.desc:test Array
1198 * @tc.type: FUNC
1199 */
1200{
1201    const array = [6, 7, 8, 9, 10, NaN, undefined, null, "", false, {name: "John"}, [1, 2, 3]];
1202    print(array.find(item => item === 5));
1203    print(array.find(item => item === 11));
1204    print(array.find(item => item > 5));
1205    print(array.find(item => item < 0));
1206    print(array.find(item => typeof item === 'string'));
1207    print(array.find(item => typeof item === 'object'));
1208    print(array.find(item => Array.isArray(item)));
1209    print(array.find(item => item));
1210    print(array.find(item => item === null));
1211    print(array.find(item => item === undefined));
1212    print(array.find(item => isNaN(item)));
1213    print(array.find(item => item === false));
1214}
1215
1216try {
1217    const array = [1, 2, 3, 4, 5];
1218    print(array.find());
1219} catch (error) {
1220    print("Caught an error: ", error);
1221}
1222
1223try {
1224    const array = [1, 2, 3, 4, 5];
1225    print(array.find("not a function"));
1226} catch (error) {
1227    print("Caught an error: ", error);
1228}
1229
1230try {
1231    let array = null;
1232    print(array.find(item => item === 1));
1233} catch (error) {
1234    print("Caught an error: ", error);
1235}
1236
1237try {
1238    array = undefined;
1239    print(array.find(item => item === 1));
1240} catch (error) {
1241    print("Caught an error: ", error);
1242}
1243
1244/*
1245 * @tc.name:FindIndex
1246 * @tc.desc:test Array
1247 * @tc.type: FUNC
1248 */
1249{
1250    const array = [6, 7, 8, 9, 10, NaN, undefined, null, "", false, {name: "John"}, [1, 2, 3]];
1251    print(array.findIndex(item => item === 5));
1252    print(array.findIndex(item => item === 11));
1253    print(array.findIndex(item => item > 5));
1254    print(array.findIndex(item => item < 0));
1255    print(array.findIndex(item => typeof item === 'string'));
1256    print(array.findIndex(item => typeof item === 'object'));
1257    print(array.findIndex(item => Array.isArray(item)));
1258    print(array.findIndex(item => item));
1259    print(array.findIndex(item => item === null));
1260    print(array.findIndex(item => item === undefined));
1261    print(array.findIndex(item => isNaN(item)));
1262    print(array.findIndex(item => item === false));
1263}
1264
1265try {
1266    const array = [1, 2, 3, 4, 5];
1267    print(array.findIndex());
1268} catch (error) {
1269    print("Caught an error: ", error);
1270}
1271
1272try {
1273    const array = [1, 2, 3, 4, 5];
1274    print(array.findIndex("not a function"));
1275} catch (error) {
1276    print("Caught an error: ", error);
1277}
1278
1279try {
1280    let array = null;
1281    print(array.findIndex(item => item === 1));
1282} catch (error) {
1283    print("Caught an error: ", error);
1284}
1285
1286try {
1287    array = undefined;
1288    print(array.findIndex(item => item === 1));
1289} catch (error) {
1290    print("Caught an error: ", error);
1291}
1292
1293/*
1294 * @tc.name:FindLast
1295 * @tc.desc:test Array
1296 * @tc.type: FUNC
1297 */
1298{
1299    const array = [6, 7, 8, 9, 10, NaN, undefined, null, "", false, {name: "John"}, [1, 2, 3]];
1300    print(array.findLast(item => item === 5));
1301    print(array.findLast(item => item === 11));
1302    print(array.findLast(item => item > 5));
1303    print(array.findLast(item => item < 0));
1304    print(array.findLast(item => typeof item === 'string'));
1305    print(array.findLast(item => typeof item === 'object'));
1306    print(array.findLast(item => Array.isArray(item)));
1307    print(array.findLast(item => item));
1308    print(array.findLast(item => item === null));
1309    print(array.findLast(item => item === undefined));
1310    print(array.findLast(item => isNaN(item)));
1311    print(array.findLast(item => item === false));
1312}
1313
1314try {
1315    const array = [1, 2, 3, 4, 5];
1316    print(array.findLast());
1317} catch (error) {
1318    print("Caught an error: ", error);
1319}
1320
1321try {
1322    const array = [1, 2, 3, 4, 5];
1323    print(array.findLast("not a function"));
1324} catch (error) {
1325    print("Caught an error: ", error);
1326}
1327
1328try {
1329    let array = null;
1330    print(array.findLast(item => item === 1));
1331} catch (error) {
1332    print("Caught an error: ", error);
1333}
1334
1335try {
1336    array = undefined;
1337    print(array.findLast(item => item === 1));
1338} catch (error) {
1339    print("Caught an error: ", error);
1340}
1341
1342/*
1343 * @tc.name:FindLastIndex
1344 * @tc.desc:test Array
1345 * @tc.type: FUNC
1346 */
1347{
1348    const array = [6, 7, 8, 9, 10, NaN, undefined, null, "", false, {name: "John"}, [1, 2, 3]];
1349    print(array.findLastIndex(item => item === 5));
1350    print(array.findLastIndex(item => item === 11));
1351    print(array.findLastIndex(item => item > 5));
1352    print(array.findLastIndex(item => item < 0));
1353    print(array.findLastIndex(item => typeof item === 'string'));
1354    print(array.findLastIndex(item => typeof item === 'object'));
1355    print(array.findLastIndex(item => Array.isArray(item)));
1356    print(array.findLastIndex(item => item));
1357    print(array.findLastIndex(item => item === null));
1358    print(array.findLastIndex(item => item === undefined));
1359    print(array.findLastIndex(item => isNaN(item)));
1360    print(array.findLastIndex(item => item === false));
1361}
1362
1363try {
1364    const array = [1, 2, 3, 4, 5];
1365    print(array.findLastIndex());
1366} catch (error) {
1367    print("Caught an error: ", error);
1368}
1369
1370try {
1371    const array = [1, 2, 3, 4, 5];
1372    print(array.findLastIndex("not a function"));
1373} catch (error) {
1374    print("Caught an error: ", error);
1375}
1376
1377try {
1378    let array = null;
1379    print(array.findLastIndex(item => item === 1));
1380} catch (error) {
1381    print("Caught an error: ", error);
1382}
1383
1384try {
1385    array = undefined;
1386    print(array.findLastIndex(item => item === 1));
1387} catch (error) {
1388    print("Caught an error: ", error);
1389}
1390
1391/*
1392 * @tc.name:Flat
1393 * @tc.desc:test Array
1394 * @tc.type: FUNC
1395 */
1396{
1397    const array = [1, 2, [3, 4, [5, 6]], [], [[7], 8], 9, [10]];
1398
1399    print(array.flat());
1400    print(array.flat(2));
1401
1402    const deeplyNestedArray = [1, [2, [3, [4, [5]]]]];
1403    print(deeplyNestedArray.flat(Infinity));
1404
1405    const emptyArray = [1, [2, [], [3, []]]];
1406    print(emptyArray.flat());
1407
1408    const sparseArray = [1, 2, , 3, 4, [5, , 6]];
1409    print(sparseArray.flat());
1410
1411    const irregularArray = [1, [2, 3, [4, [5]]]];
1412    print(irregularArray.flat());
1413
1414    const arrayWithNonArrays = [1, 'string', {name: 'John'}, null, undefined];
1415    print(arrayWithNonArrays.flat());
1416
1417    const arrayWithNaNAndInfinity = [1, [NaN, Infinity], [2, [3, NaN]]];
1418    print(arrayWithNaNAndInfinity.flat());
1419}
1420
1421try {
1422    const array = [1, 2, [3, 4]];
1423    print(array.flat('string'));
1424} catch (error) {
1425    print("Caught an error: ", error);
1426}
1427
1428try {
1429    const array = [1, 2, [3, 4]];
1430    print(array.flat(-1));
1431} catch (error) {
1432    print("Caught an error: ", error);
1433}
1434
1435/*
1436 * @tc.name:FlatMap
1437 * @tc.desc:test Array
1438 * @tc.type: FUNC
1439 */
1440{
1441    const array = [1, 2, 3];
1442    print(array.flatMap(x => [x, x * 2]));
1443    print(array.flatMap(x => []));
1444    print(array.flatMap(x => x * 2));
1445    print(array.flatMap((x, index) => [x, index]));
1446    const sparseArray = [1, , 2, , 3];
1447    print(sparseArray.flatMap(x => [x]));
1448    const nestedArray = [[1, 2], [3, 4], [5, 6]];
1449    print(nestedArray.flatMap(arr => arr));
1450    const arrayWithEmptyArrays = [1, [], [2, 3], [], 4];
1451    print(arrayWithEmptyArrays.flatMap(x => x));
1452    print(array.flatMap(x => x % 2 === 0 ? [x, x * 2] : x));
1453}
1454
1455/*
1456 * @tc.name:ForEach
1457 * @tc.desc:test Array
1458 * @tc.type: FUNC
1459 */
1460originalArrays.forEach(array => {
1461    array.forEach(item => {
1462        print(item);
1463    });
1464});
1465
1466try {
1467    const array = [1, 2, 3];
1468    array.forEach('not a function');
1469} catch (error) {
1470    print("Caught an error: ", error);
1471}
1472
1473/*
1474 * @tc.name:Includes
1475 * @tc.desc:test Array
1476 * @tc.type: FUNC
1477 */
1478const testCases = [
1479    { array: [1, 2, 3, 4, 5], target: 3 },
1480    { array: [1, 2, 3, 4, 5], target: 6 },
1481    { array: [NaN, 2, 3], target: NaN },
1482    { array: [undefined, 2, 3], target: undefined },
1483    { array: ["apple", "banana", "orange"], target: "banana" },
1484    { array: ["apple", "banana", "orange"], target: "grape" },
1485    { array: [], target: 1 },
1486    { array: [true, false, true], target: true },
1487    { array: [true, false, true], target: false },
1488    { array: [Infinity, -Infinity], target: Infinity },
1489    { array: [Infinity, -Infinity], target: -Infinity },
1490    { array: [new Map(), new Map()], target: new Map() },
1491    { array: [new Set(), new Set()], target: new Set() },
1492];
1493
1494testCases.forEach(({ array, target }) => {
1495    const result = array.includes(target);
1496    print(`Array: [${array.join(', ')}], Target: ${target}, Result: ${result}`);
1497});
1498
1499/*
1500 * @tc.name:IndexOf
1501 * @tc.desc:test Array
1502 * @tc.type: FUNC
1503 */
1504{
1505    let arr = [1, 2, 3, 4, 5];
1506    print(arr.indexOf(3));
1507    print(arr.indexOf(1));
1508    print(arr.indexOf(5));
1509    print([].indexOf(1));
1510    let arr2 = ["apple", "banana", "cherry"];
1511    print(arr2.indexOf("banana"))
1512    let arr3 = [1, 2, 2, 3, 4, 2];
1513    print(arr3.indexOf(2));
1514    print(arr.indexOf(10));
1515    let arr4 = [{id: 1}, {id: 2}, {id: 3}];
1516    print(arr4.indexOf({id: 2}));
1517    print(arr4.findIndex(item => item.id === 2));
1518    print("not an array".indexOf(1));
1519}
1520
1521/*
1522 * @tc.name:Join
1523 * @tc.desc:test Array
1524 * @tc.type: FUNC
1525 */
1526{
1527    let arr = ["apple", "banana", "cherry"];
1528    print(arr.join());
1529    print(arr.join(", "));
1530    let emptyArr = [];
1531    print(emptyArr.join());
1532    let singleElementArr = ["apple"];
1533    print(singleElementArr.join());
1534    let mixedArr = ["apple", 1, {name: "John"}];
1535    print(mixedArr.join());
1536    let customSeparatorArr = ["apple", "banana", "cherry"];
1537    print(customSeparatorArr.join(" + "));
1538}
1539
1540/*
1541 * @tc.name:Keys
1542 * @tc.desc:test Array
1543 * @tc.type: FUNC
1544 */
1545{
1546    let arr = ["apple", "banana", "cherry"];
1547    let keysIter = arr.keys();
1548    for (let key of keysIter) {
1549        print(key);
1550    }
1551
1552    let emptyArr = [];
1553    let emptyKeysIter = emptyArr.keys();
1554    print(emptyKeysIter.next().done);
1555
1556    let singleElementArr = ["apple"];
1557    let singleElementKeysIter = singleElementArr.keys();
1558    print(singleElementKeysIter.next().value);
1559    print(singleElementKeysIter.next().done);
1560
1561    let multiDimArr = [["apple", "banana"], ["cherry", "date"]];
1562    let multiDimKeysIter = multiDimArr.keys();
1563    for (let key of multiDimKeysIter) {
1564        print(key);
1565    }
1566
1567    let sparseArr = [1, , 3];
1568    let sparseKeysIter = sparseArr.keys();
1569    for (let key of sparseKeysIter) {
1570        print(key);
1571    }
1572}
1573
1574/*
1575 * @tc.name:LastIndexOf
1576 * @tc.desc:test Array
1577 * @tc.type: FUNC
1578 */
1579{
1580    let arr = [1, 2, 3, 4, 2, 5];
1581    print(arr.lastIndexOf(2));
1582
1583    print(arr.lastIndexOf(1));
1584    print(arr.lastIndexOf(5));
1585    print(arr.lastIndexOf(6));
1586
1587    let emptyArr = [];
1588    print(emptyArr.lastIndexOf(1));
1589
1590    let arrWithNaN = [1, 2, NaN, 4, NaN];
1591    print(arrWithNaN.lastIndexOf(NaN));
1592
1593    let arrWithUndefined = [1, 2, undefined, 4];
1594    print(arrWithUndefined.lastIndexOf(undefined));
1595}
1596
1597/*
1598 * @tc.name:Map
1599 * @tc.desc:test Array
1600 * @tc.type: FUNC
1601 */
1602{
1603    let arr = [1, 2, 3, 4, 5];
1604    let mappedArr = arr.map(num => num * 2);
1605    print(mappedArr);
1606
1607    let emptyArr = [];
1608    let mappedEmptyArr = emptyArr.map(item => item * 2);
1609    print(mappedEmptyArr);
1610
1611    let arrWithNaN = [1, 2, NaN, 4, NaN];
1612    let mappedArrWithNaN = arrWithNaN.map(num => num * 2);
1613    print(mappedArrWithNaN);
1614
1615    let sparseArr = [1, , 3];
1616    let mappedSparseArr = sparseArr.map(num => num * 2);
1617    print(mappedSparseArr);
1618
1619    let objArr = [{id: 1}, {id: 2}, {id: 3}];
1620    let mappedObjArr = objArr.map(obj => obj.id);
1621    print(mappedObjArr);
1622
1623    let multiDimArr = [[1, 2], [3, 4], [5, 6]];
1624    let mappedMultiDimArr = multiDimArr.map(innerArr => innerArr.map(num => num * 2));
1625    print(mappedMultiDimArr);
1626}
1627
1628/*
1629 * @tc.name:Pop
1630 * @tc.desc:test Array
1631 * @tc.type: FUNC
1632 */
1633{
1634    let arr = [1, 2, 3, 4, 5];
1635    let poppedElement = arr.pop();
1636    print(poppedElement);
1637    print(arr);
1638
1639    let emptyArr = [];
1640    let poppedEmptyElement = emptyArr.pop();
1641    print(poppedEmptyElement);
1642    print(emptyArr);
1643
1644    let singleElementArr = [1];
1645    let poppedSingleElement = singleElementArr.pop();
1646    print(poppedSingleElement);
1647    print(singleElementArr);
1648
1649    let anotherSingleElementArr = ["apple"];
1650    let poppedAnotherSingleElement = anotherSingleElementArr.pop();
1651    print(poppedAnotherSingleElement);
1652}
1653
1654/*
1655 * @tc.name:Push
1656 * @tc.desc:test Array
1657 * @tc.type: FUNC
1658 */
1659{
1660    let arr = [1, 2, 3];
1661    arr.push(4);
1662    print(arr);
1663
1664    arr.push(5, 6);
1665    print(arr);
1666
1667    let emptyArr = [];
1668    emptyArr.push(1);
1669    print(emptyArr);
1670
1671    let objArr = [{ id: 1 }];
1672    objArr.push({ id: 2 });
1673    print(objArr);
1674
1675    let nestedArr = [1, 2];
1676    nestedArr.push([3, 4]);
1677    print(nestedArr);
1678
1679    let arrWithUndefined = [1, 2, 3];
1680    arrWithUndefined.push(undefined);
1681    print(arrWithUndefined);
1682
1683    let singleElementArr = [1];
1684    singleElementArr.push(2);
1685    print(singleElementArr);
1686}
1687
1688/*
1689 * @tc.name:Reduce
1690 * @tc.desc:test Array
1691 * @tc.type: FUNC
1692 */
1693{
1694    let arr = [1, 2, 3, 4, 5];
1695    let sum = arr.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
1696    print(sum);
1697
1698    let emptyArr = [];
1699    let sumOfEmptyArr = emptyArr.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
1700    print(sumOfEmptyArr);
1701
1702    let singleArr = [1];
1703    let sumOfSingleArr = singleArr.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
1704    print(sumOfSingleArr);
1705
1706    let arrNaN = [1, 2, NaN, 4];
1707    let sumOfArrNaN = arrNaN.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
1708    print(sumOfArrNaN);
1709}
1710
1711/*
1712 * @tc.name:ReduceRight
1713 * @tc.desc:test Array
1714 * @tc.type: FUNC
1715 */
1716{
1717    let array1 = ["a", "b", "c", "d", "e"];
1718    let result1 = array1.reduceRight((acc, curr) => acc + curr);
1719    print(result1);
1720
1721    let array2 = [];
1722    let result2 = array2.reduceRight((acc, curr) => acc + curr, "initialValue");
1723    print(result2);
1724
1725    let array3 = ["a"];
1726    let result3 = array3.reduceRight((acc, curr) => acc + curr);
1727    print(result3);
1728
1729    let array4 = ["a", "b", undefined, "d"];
1730    let result4 = array4.reduceRight((acc, curr) => acc + curr);
1731    print(result4);
1732}
1733
1734/*
1735 * @tc.name:Reverse
1736 * @tc.desc:test Array
1737 * @tc.type: FUNC
1738 */
1739{
1740    let array1 = ["a", "b", "c", "d", "e"];
1741    array1.reverse();
1742    print(array1);
1743
1744    let emptyArray = [];
1745    emptyArray.reverse();
1746    print(emptyArray);
1747
1748    let singleElementArray = ["a"];
1749    singleElementArray.reverse();
1750    print(singleElementArray);
1751
1752    let arrayWithUndefined = ["a", "b", undefined, "d"];
1753    arrayWithUndefined.reverse();
1754    print(arrayWithUndefined);
1755}
1756
1757/*
1758 * @tc.name:Shift
1759 * @tc.desc:test Array
1760 * @tc.type: FUNC
1761 */
1762{
1763    let array1 = ["a", "b", "c", "d", "e"];
1764    let shiftedElement1 = array1.shift();
1765    print(shiftedElement1);
1766    print(array1);
1767
1768    let emptyArray = [];
1769    let shiftedElement2 = emptyArray.shift();
1770    print(shiftedElement2);
1771    print(emptyArray);
1772
1773    let singleElementArray = ["a"];
1774    let shiftedElement3 = singleElementArray.shift();
1775    print(shiftedElement3);
1776    print(singleElementArray);
1777
1778    let arrayWithUndefined = ["a", undefined, "b", "c"];
1779    let shiftedElement4 = arrayWithUndefined.shift();
1780    print(shiftedElement4);
1781    print(arrayWithUndefined);
1782}
1783
1784/*
1785 * @tc.name:Slice
1786 * @tc.desc:test Array
1787 * @tc.type: FUNC
1788 */
1789{
1790    let array1 = ["a", "b", "c", "d", "e"];
1791    let slicedArray1 = array1.slice(1, 3);
1792    print(slicedArray1);
1793
1794    let emptyArray = [];
1795    let slicedEmptyArray = emptyArray.slice(1, 3);
1796    print(slicedEmptyArray);
1797
1798    let singleElementArray = ["a"];
1799    let slicedSingleElementArray = singleElementArray.slice(0, 1);
1800    print(slicedSingleElementArray);
1801
1802    let arrayWithUndefined = ["a", undefined, "b", "c"];
1803    let slicedArrayWithUndefined = arrayWithUndefined.slice(1, 3);
1804    print(slicedArrayWithUndefined);
1805}
1806
1807/*
1808 * @tc.name:Some
1809 * @tc.desc:test Array
1810 * @tc.type: FUNC
1811 */
1812{
1813    let array1 = [1, 2, 3, 4, 5];
1814    let isSomeEven = array1.some(num => num % 2 === 0);
1815    print(isSomeEven);
1816
1817    let array2 = [1, 3, 5, 7, 9];
1818    let isSomeEven2 = array2.some(num => num % 2 === 0);
1819    print(isSomeEven2);
1820
1821    let emptyArray = [];
1822    let isSomeEmpty = emptyArray.some(num => num > 0);
1823    print(isSomeEmpty);
1824
1825    let singleElementArray = [1];
1826    let isSomeSingleElement = singleElementArray.some(num => num > 0);
1827    print(isSomeSingleElement);
1828
1829    let arrayWithUndefined = [1, undefined, 3, 5];
1830    let isSomeUndefined = arrayWithUndefined.some(num => num === undefined);
1831    print(isSomeUndefined);
1832}
1833
1834/*
1835 * @tc.name:Sort
1836 * @tc.desc:test Array
1837 * @tc.type: FUNC
1838 */
1839{
1840    let array1 = [3, 1, 4, 1, 5, 9, 2, 6, 5];
1841    array1.sort();
1842    print(array1);
1843
1844    let emptyArray = [];
1845    emptyArray.sort();
1846    print(emptyArray);
1847
1848    let singleElementArray = [1];
1849    singleElementArray.sort();
1850    print(singleElementArray);
1851
1852    let arrayWithUndefined = [1, undefined, 3, 5];
1853    arrayWithUndefined.sort();
1854    print(arrayWithUndefined);
1855
1856    let arrayWithStrings = ["banana", "apple", "cherry"];
1857    arrayWithStrings.sort();
1858    print(arrayWithStrings);
1859}
1860
1861/*
1862 * @tc.name:Splice
1863 * @tc.desc:test Array
1864 * @tc.type: FUNC
1865 */
1866{
1867    let array1 = ["a", "b", "c", "d", "e"];
1868    let removedElements1 = array1.splice(2, 2, "x", "y");
1869    print(removedElements1);
1870    print(array1);
1871
1872    let emptyArray = [];
1873    let removedElements2 = emptyArray.splice(0, 0, "x", "y");
1874    print(removedElements2);
1875    print(emptyArray);
1876
1877    let singleElementArray = ["a"];
1878    let removedElements3 = singleElementArray.splice(0, 1, "x", "y");
1879    print(removedElements3);
1880    print(singleElementArray);
1881
1882    let arrayWithUndefined = [1, undefined, 3, 5];
1883    let removedElements4 = arrayWithUndefined.splice(1, 2);
1884    print(removedElements4);
1885    print(arrayWithUndefined);
1886}
1887
1888/*
1889 * @tc.name:toString
1890 * @tc.desc:test Array
1891 * @tc.type: FUNC
1892 */
1893{
1894    let array = ["apple", "banana", "cherry"];
1895    let string = array.toString();
1896    print(string);
1897
1898    let numbers = [1, 2, 3, 4, 5];
1899    let string2 = numbers.toString();
1900    print(string2);
1901
1902    let mixed = [1, "two", true];
1903    let string3 = mixed.toString();
1904    print(string3);
1905}
1906
1907/*
1908 * @tc.name:Unshift
1909 * @tc.desc:test Array
1910 * @tc.type: FUNC
1911 */
1912{
1913    let array1 = ["a", "b", "c"];
1914    let newLength1 = array1.unshift("x", "y");
1915    print(newLength1);
1916    print(array1);
1917
1918    let emptyArray = [];
1919    let newLength2 = emptyArray.unshift("x", "y");
1920    print(newLength2);
1921    print(emptyArray);
1922
1923    let singleElementArray = ["a"];
1924    let newLength3 = singleElementArray.unshift("x");
1925    print(newLength3);
1926    print(singleElementArray);
1927
1928    let arrayWithUndefined = [1, 2, undefined];
1929    let newLength4 = arrayWithUndefined.unshift("x");
1930    print(newLength4);
1931    print(arrayWithUndefined);
1932
1933    let arrayWithHole = [1, 2, ,4];
1934    let newLength5 = arrayWithHole.unshift(5, 6, 7);
1935    print(newLength5);
1936    print(arrayWithHole);
1937
1938    let arrayWithHole1 = [1, 2, ,4];
1939    let newLength6 = arrayWithHole1.unshift(5, 6, 7, 8);
1940    print(newLength6);
1941    print(arrayWithHole1);
1942}
1943
1944/*
1945 * @tc.name:ToReversed ToSorted ToSpliced With
1946 * @tc.desc:test Array
1947 * @tc.type: FUNC
1948 */
1949{
1950    let array1 = ["a", "b", "c", "d", "e"];
1951    print(array1.toReversed());
1952
1953    let emptyArray = [];
1954    print(emptyArray.toReversed());
1955
1956    let singleElementArray = ["a"];
1957    print(singleElementArray.toReversed());
1958
1959    let arrayWithUndefined = ["a", "b", undefined, "d"];
1960    print(arrayWithUndefined.toReversed());
1961}
1962
1963{
1964    let array1 = [3, 1, 4, 1, 5, 9, 2, 6, 5];
1965    print(array1.toSorted());
1966
1967    let emptyArray = [];
1968    print(emptyArray.toSorted());
1969
1970    let singleElementArray = [1];
1971    print(singleElementArray.toSorted());
1972
1973    let arrayWithUndefined = [1, undefined, 3, 5];
1974    print(arrayWithUndefined.toSorted());
1975
1976    let arrayWithStrings = ["banana", "apple", "cherry"];
1977    print(arrayWithStrings.toSorted());
1978}
1979
1980{
1981    let array1 = ["a", "b", "c", "d", "e"];
1982    let removedElements1 = array1.toSpliced(2, 2, "x", "y");
1983    print(removedElements1);
1984    print(array1);
1985
1986    let emptyArray = [];
1987    let removedElements2 = emptyArray.toSpliced(0, 0, "x", "y");
1988    print(removedElements2);
1989    print(emptyArray);
1990
1991    let singleElementArray = ["a"];
1992    let removedElements3 = singleElementArray.toSpliced(0, 1, "x", "y");
1993    print(removedElements3);
1994    print(singleElementArray);
1995
1996    let arrayWithUndefined = [1, undefined, 3, 5];
1997    let removedElements4 = arrayWithUndefined.toSpliced(1, 2);
1998    print(removedElements4);
1999    print(arrayWithUndefined);
2000}
2001
2002/*
2003 * @tc.name:IsArray
2004 * @tc.desc:test Array
2005 * @tc.type: FUNC
2006 */
2007{
2008    // print true
2009    print(Array.isArray([]));
2010    print(Array.isArray([1]));
2011    print(Array.isArray(new Array()));
2012    print(Array.isArray(new Array("a", "b", "c", "d")));
2013    print(Array.isArray(new Array(3)));
2014    print(Array.isArray(Array.prototype));
2015
2016    // print false
2017    print(Array.isArray());
2018    print(Array.isArray({}));
2019    print(Array.isArray(null));
2020    print(Array.isArray(undefined));
2021    print(Array.isArray(17));
2022    print(Array.isArray("Array"));
2023    print(Array.isArray(true));
2024    print(Array.isArray(false));
2025    print(Array.isArray(new Uint8Array(32)));
2026    print(Array.isArray({ __proto__: Array.prototype }));
2027}
2028
2029var arr_push = [];
2030Object.defineProperty(arr_push, "length", { writable : false});
2031try {
2032    arr_push.push(3);
2033} catch (e) {
2034    print(e instanceof TypeError);
2035}