1/*
2 * Copyright (c) 2023 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
16let arr = [1, 2, 3, 4, 5, 6, 7, 8];
17arr.splice(0, 1, 9)
18print(arr)
19arr.splice(10, 1)
20print(arr)
21arr = [1, 2, 3, 4, 5, 6, 7, 8];
22arr.splice(8, 0, 1, 1)
23print(arr)
24arr.splice(0, 8, 1, 1)
25print(arr)
26arr = [1, 2, 3, 4, 5, 6, 7, 8];
27arr.splice(1, 8)
28print(arr)
29arr = new Array(100)
30arr.splice(0, 20)
31print(arr.length)
32
33var array = new Array(10);
34var spliced = array.splice(1, 1);
35for (let i = 0; i < array.length; ++i) {
36    print(i in array)
37}
38var array1 = new Array(10);
39var spliced1 = array1.splice(1, 1, "a", "b");
40for (let i = 0; i < array1.length; ++i) {
41    print(i in array1)
42}
43
44array = [];
45spliced = undefined;
46for (var i = 0; i < 1; i++) {
47    let bad_start = { valueOf: function () { array.push(2 * i); return -1; } };
48    let bad_count = { valueOf: function () { array.push(2 * i + 1); return 1; } };
49    spliced = array.splice(bad_start, bad_count);
50    print("array.length", array.length);
51}
52for (let i = 0; i < 2; i++) {
53    let array = [1, 2, 3, 4];
54    print("array:", array);
55    if (i == 0) {
56        let spliced = array.splice(1, 3, 'one', 'two', 'three');
57    }
58}
59
60let a = 0;
61class C3 extends Array {
62    constructor(a5, a6, a7, a8) {
63        a++;
64        super(-9223372036854775808, Set);
65        if (a == 1) {
66            this.splice(Array);
67        }
68        return "n"
69    }
70}
71try { new C3(C3, Array, Array, C3); } catch (err) {print(err)};