• 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
16class A {
17    constructor() {
18        this.b = 1;
19    }
20
21    test() {
22        return "call";
23    }
24}
25let x = {
26    b: 1
27};
28
29// callthis0
30try {
31    let a = new A();
32    a.b();
33} catch (e) {
34    print(e.message);
35    print(e.stack);
36}
37try {
38    let a = new A();
39    a.test()();
40} catch (e) {
41    print(e.message);
42    print(e.stack);
43}
44try {
45    x.b();
46} catch (e) {
47    print(e.message);
48    print(e.stack);
49}
50
51// call this1
52try {
53    let b = new A();
54    b.b(1);
55} catch (e) {
56    print(e.message);
57    print(e.stack);
58}
59try {
60    let b = new A();
61    b.test()(1);
62} catch (e) {
63    print(e.message);
64    print(e.stack);
65}
66try {
67    x.b(1);
68} catch (e) {
69    print(e.message);
70    print(e.stack);
71}
72
73// call this2
74try {
75    let b = new A();
76    b.b(1, "a");
77} catch (e) {
78    print(e.message);
79    print(e.stack);
80}
81try {
82    let b = new A();
83    b.test()(1, "a");
84} catch (e) {
85    print(e.message);
86    print(e.stack);
87}
88try {
89    x.b(1, "a");
90} catch (e) {
91    print(e.message);
92    print(e.stack);
93}
94
95// call this3
96try {
97    let b = new A();b.b(1, "a", 2);
98} catch (e) {
99    print(e.message);
100    print(e.stack);
101}
102try {
103    let b = new A();b.test()(1, "a", 2);
104} catch (e) {
105    print(e.message);
106    print(e.stack);
107}
108try {
109    x.b(1, "a", 2);
110} catch (e) {
111    print(e.message);
112    print(e.stack);
113}
114
115
116// call range
117try {
118    let b = new A(); b.b(1, "a", 2, 3);
119} catch (e) {
120    print(e.message);
121    print(e.stack);
122}
123try {
124    let b = new A(); b.test()(1, "a", 2, 3);
125} catch (e) {
126    print(e.message);
127    print(e.stack);
128}
129try {
130    x.b(1, "a", 2, 3);
131} catch (e) {
132    print(e.message);
133    print(e.stack);
134}
135
136// wide callthis
137try {
138    let b = new A();
139    b.b(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
140        11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
141        21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
142        31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
143        41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
144        51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
145        61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
146        71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
147        81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
148        91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
149        101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
150        111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
151        121, 122, 123, 124, 125, 126, 127, 128);
152} catch (e) {
153    print(e.message);
154    print(e.stack);
155}
156try {
157    let b = new A();
158    b.test()(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
159        11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
160        21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
161        31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
162        41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
163        51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
164        61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
165        71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
166        81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
167        91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
168        101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
169        111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
170        121, 122, 123, 124, 125, 126, 127, 128);
171} catch (e) {
172    print(e.message);
173    print(e.stack);
174}
175try {
176    x.b(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
177        11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
178        21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
179        31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
180        41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
181        51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
182        61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
183        71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
184        81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
185        91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
186        101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
187        111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
188        121, 122, 123, 124, 125, 126, 127, 128);
189} catch (e) {
190    print(e.message);
191    print(e.stack);
192}
193