• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    class D extends C {
56        constructo() {
57            delete super.a;
58        }
59    }
60    d = new D();
61} catch (err) {
62    print("PASS");
63}
64
65class A {
66    a = 10;
67}
68class B extends A {
69    constructor() {
70        let a = "a";
71        super[a]  = 1;
72    }
73}
74var par = new A;
75print(par.a);
76
77for (let i = 0; i < 2; i++) {
78    class Cls{
79        foo() { }
80    }
81    if (i == 0) {
82        Cls.prototype.foo.x = 1;
83    }
84    print(Cls.prototype.foo.x);
85}