• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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// static_initializer
17class A {
18	static a = 1;
19}
20print(A.a);
21
22// instance_initializer
23class B {
24    b = "b"
25}
26let b = new B()
27print(b.b);
28
29// getter, setter, static
30class C {
31    get getv() {
32        return this.elt;
33    }
34
35    set setv(num) {
36        this.elt = num;
37    }
38
39    static sgetv() {
40        return this.elt;
41    }
42
43    static ssetv(num) {
44        this.elt = num;
45    }
46
47    elt = 1;
48}
49let c = new C;
50c.setv = 0x5aa5;
51print(c.getv);
52C.ssetv(0xa55a);
53print(C.sgetv());
54
55// #~D^1>#
56var empty = Object.create(null);
57empty.x = "c";
58var D, value;
59for (D = class { get ['x' in empty]() {return 'via get';}};;) {
60    value = D.prototype.false;
61    break;
62}
63
64for (D = class { set ['x' in empty](param) {value = param;}};;) {
65    D.prototype.false = 'via set';
66    break;
67}
68print(D.prototype.false);
69
70// #~E>@1~@2>#instance_initializer
71class E {
72    #outer = 'test';
73
74    B_withoutPrivateField = class {
75      method(o) {
76        return o.#outer;
77      }
78    }
79
80    B_withPrivateField = class {
81      #inner = 42;
82      method(o) {
83        return this.#inner;
84      }
85    }
86}
87let e = new(E);
88let e1 = new(e.B_withoutPrivateField);
89let e2 = new(e.B_withPrivateField);
90print(e1.method(e));
91print(e2.method(e2));
92