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:class
18 * @tc.desc:test class
19 * @tc.type: FUNC
20 * @tc.require: issueI5NO8G
21 */
22class Parent {
23    constructor(x) {
24        this.x = x;
25    }
26
27    static toString() {
28        return 'parent';
29    }
30}
31
32class Child extends Parent {
33    constructor(x, y) {
34        super(x);
35        this.y = y;
36    }
37
38    value() {
39        return this.x * this.y;
40    }
41
42    static toString() {
43        return super.toString() + ' child';
44    }
45}
46
47var c = new Child(2, 3);
48print(c.value());
49print(Child.toString());
50
51try {
52    class C {
53        a = 1;
54    }
55
56    class D extends C {
57        constructo() {
58            delete super.a;
59        }
60    }
61
62    d = new D();
63} catch (err) {
64    print("PASS");
65}
66
67class A {
68    a = 10;
69}
70
71class B extends A {
72    constructor() {
73        let a = "a";
74        super[a] = 1;
75    }
76}
77
78var par = new A;
79print(par.a);
80
81for (let i = 0; i < 2; i++) {
82    class Cls {
83        foo() {
84        }
85    }
86
87    if (i == 0) {
88        Cls.prototype.foo.x = 1;
89    }
90    print(Cls.prototype.foo.x);
91}
92
93class Class2022 {
94    public = 12;
95    #private = 34;
96    static static_public = 56;
97    static #static_private = 78;
98
99    static test(obj) {
100        print(obj.public);
101        print(obj.#private);
102        print(obj.static_public);
103        print(obj.#static_private);
104    }
105}
106
107var class2022 = new Class2022();
108try {
109    Class2022.test(class2022);
110} catch (err) {
111    print(err.name);
112}
113try {
114    Class2022.test(new Proxy(class2022, {}));
115} catch (err) {
116    print(err.name);
117}
118
119function foo() {
120
121}
122
123class Class2024 {
124    static #g;
125    a = [1, 2, 3];
126    #c = foo;
127}
128
129var class2024 = new Class2024();
130print("test successful!");
131
132class StaticTest {
133    static set a(a) {
134        print(a);
135    }
136
137    static a = 1; // expect no print
138    static length = 1; // expect no TypeError
139}
140
141let o = {
142    toString() {
143        class C {
144            #p(a, b) {
145            }
146        }
147    }
148}
149let o1 = {
150    [o](a, b) {
151    }
152}
153print("test privateproperty class sucecess")
154
155// TypeError
156try {
157    const v13 = new ArrayBuffer(16);
158
159    function F14(a16, a17) {
160        if (!new.target) {
161            throw 'must be called with new';
162        }
163
164        function f18(a19, a20, a21) {
165        }
166
167        const v23 = `-2`;
168
169        async function f25(a26, a27, a28, a29) {
170            return v23;
171        }
172
173        f25();
174        const v33 = new BigUint64Array(31);
175        const o34 = {
176            ...v33,
177            ...v33,
178        };
179        Object.defineProperty(o34, 4, { set: f18 });
180    }
181
182    const v35 = new F14(ArrayBuffer);
183    const t33 = 64n;
184    new t33(v35, v13);
185} catch (err) {
186    print(err.name);
187}
188
189// TypeError
190try {
191    class C0 {
192        constructor(a2) {
193            const v5 = new ArrayBuffer(10);
194
195            function F6(a8, a9) {
196                if (!new.target) {
197                    throw 'must be called with new';
198                }
199                const v12 = new BigUint64Array(32);
200                const o13 = {
201                    ...v12,
202                };
203                Object.defineProperty(o13, 4, { set: F6 });
204            }
205
206            new F6(ArrayBuffer, v5);
207            new a2();
208        }
209    }
210
211    new C0(C0);
212} catch (err) {
213    print(err.name);
214}
215
216// TypeError
217try {
218    const v1 = new WeakSet();
219
220    function f2() {
221        return v1;
222    }
223
224    new SharedArrayBuffer(24);
225    const o8 = {};
226    for (let i11 = -57, i12 = 10; i11 < i12; i12--) {
227        o8[i12] >>= i12;
228    }
229
230    class C20 extends f2 {
231    }
232
233    new C20(83.14, 4.14, -7.50);
234    C20(54.1);
235    BigUint64Array();
236} catch (err) {
237    print(err.name);
238}
239