• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021-2024 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
16import {
17	evaluateNumber,
18	ExampleClass,
19	ClassWithEmptyConstructor,
20	evaluateObject,
21	MyNamespace,
22	evaluateArray,
23} from 'module';
24
25//! CHECKER      jscallEmpty JIT
26//! RUN          force_jit: true, entry: "jscallEmpty", options: "--compiler-regex=ETSGLOBAL::jscallEmpty"
27//! METHOD       "jscallEmpty"
28//! PASS_AFTER   "IrBuilder"
29//! INST_NOT     /CallStatic.*jscall::invoke/
30
31function jscallEmpty(): int {
32	evaluateNumber();
33	return 0;
34}
35
36//! CHECKER      jsnewEmpty JIT
37//! RUN          force_jit: true, entry: "jsnewEmpty", options: "--compiler-regex=ETSGLOBAL::jsnewEmpty"
38//! METHOD       "jsnewEmpty"
39//! PASS_AFTER   "IrBuilder"
40//! INST_NOT     /CallStatic.*jsnew::invoke/
41//! INST_NOT     "Intrinsic.JSRuntimeGetPropertyJSValue"
42//! INST_NOT     "Intrinsic.JSRuntimeGetPropertyInt"
43//! INST_NOT     /JSRuntime.*Value/ # no casts from JSValue to primitive
44//! INST_COUNT   "Intrinsic.JSRuntimeGetPropertyDouble", 2
45//! INST_COUNT   /i32.*Cast f64/, 2
46
47function jsnewEmpty(): int {
48	let resObj = new ClassWithEmptyConstructor();
49	let resGetV0 = resObj.v0 as int;
50	let resGetV1 = resObj.v1 as int;
51	if (resGetV0 == 42 && resGetV1 == 42) {
52		return 0;
53	} else {
54		return 1;
55	}
56}
57
58//! CHECKER      jscallStaticMethodEmpty JIT
59//! RUN          force_jit: true, entry: "jscallStaticMethodEmpty", options: "--compiler-regex=ETSGLOBAL::jscallStaticMethodEmpty"
60//! METHOD       "jscallStaticMethodEmpty"
61//! PASS_AFTER   "IrBuilder"
62//! INST_NOT     /CallStatic.*jscall::invoke/
63
64function jscallStaticMethodEmpty(): int {
65	ExampleClass.emptyMethod();
66	return 0;
67}
68
69//! CHECKER      jscallObject JIT
70//! RUN          force_jit: true, entry: "jscallObject", options: "--compiler-regex=ETSGLOBAL::jscallObject"
71//! METHOD       "jscallObject"
72//! PASS_AFTER   "IrBuilder"
73//! INST_NOT     /CallStatic.*jsnew::invoke/
74//! INST_NOT     /CallStatic.*jscall::invoke/
75//! INST         "Intrinsic.JSRuntimeGetPropertyDouble"
76//! INST_NEXT    /i32.*Cast f64/
77//! INST_NEXT    "Intrinsic.JSRuntimeGetPropertyDouble"
78//! INST_NEXT    /i32.*Cast f64/
79
80function jscallObject(): int {
81	let resObj = new ExampleClass(42, 42);
82	let res = evaluateObject(resObj);
83	let resGetV0 = res.v0 as int;
84	let resGetV1 = res.v1 as int;
85	if (resGetV0 == 84 && resGetV1 == 84) {
86		return 0;
87	} else {
88		return 1;
89	}
90}
91
92//! CHECKER      jsnewObject JIT
93//! RUN          force_jit: true, entry: "jsnewObject", options: "--compiler-regex=ETSGLOBAL::jsnewObject"
94//! METHOD       "jsnewObject"
95//! PASS_AFTER   "IrBuilder"
96//! INST_NOT     /CallStatic.*jsnew::invoke/
97//! INST_COUNT   "Intrinsic.JSRuntimeGetPropertyJSValue", 2
98//! INST_COUNT   "Intrinsic.JSRuntimeGetPropertyDouble", 4
99
100function jsnewObject(): int {
101	let resObj = new ExampleClass(42, 42);
102	let res = new ExampleClass(resObj, resObj);
103	let resGetV0 = res.v0;
104	let resGetV1 = res.v1;
105	if ((resGetV0.v0 as int) == 42 && (resGetV0.v1 as int) == 42 && (resGetV1.v0 as int) == 42 && (resGetV1.v1 as int) == 42) {
106		return 0;
107	} else {
108		return 1;
109	}
110}
111
112//! CHECKER      jsnewSetPropertyObject JIT
113//! RUN          force_jit: true, entry: "jsnewSetPropertyObject", options: "--compiler-regex=ETSGLOBAL::jsnewSetPropertyObject"
114//! METHOD       "jsnewSetPropertyObject"
115//! PASS_AFTER   "IrBuilder"
116//! INST_NOT     /CallStatic.*jsnew::invoke/
117//! INST_COUNT   "Intrinsic.JSRuntimeSetPropertyJSValue", 2
118//! INST_COUNT   "Intrinsic.JSRuntimeGetPropertyJSValue", 2
119//! INST_COUNT   "Intrinsic.JSRuntimeGetPropertyDouble", 4
120
121function jsnewSetPropertyObject(): int {
122	let resObj = new ClassWithEmptyConstructor();
123	let res = new ClassWithEmptyConstructor();
124	resObj.v0 = res;
125	resObj.v1 = res;
126	let resGetV0 = resObj.v0;
127	let resGetV1 = resObj.v1;
128	if ((resGetV0.v0 as int) == 42 && (resGetV0.v1 as int) == 42 && (resGetV1.v0 as int) == 42 && (resGetV1.v1 as int) == 42) {
129		return 0;
130	} else {
131		return 1;
132	}
133}
134
135//! CHECKER      jscallMethodObject JIT
136//! RUN          force_jit: true, entry: "jscallMethodObject", options: "--compiler-regex=ETSGLOBAL::jscallMethodObject"
137//! METHOD       "jscallMethodObject"
138//! PASS_AFTER   "IrBuilder"
139//! INST_NOT     /CallStatic.*jsnew::invoke/
140//! INST_NOT     /CallStatic.*jscall::invoke/
141//! INST_COUNT   "Intrinsic.JSRuntimeGetPropertyDouble", 2
142
143function jscallMethodObject(): int {
144	let resObj = new ExampleClass(42, 42);
145	let res = evaluateObject(resObj);
146	let resGetV0 = res.v0 as int;
147	let resGetV1 = res.v1 as int;
148	if (resGetV0 == 84 && resGetV1 == 84) {
149		return 0;
150	} else {
151		return 1;
152	}
153}
154
155//! CHECKER      jscallMethodSimple JIT
156//! RUN          force_jit: true, entry: "jscallMethodSimple", options: "--compiler-regex=ETSGLOBAL::jscallMethodSimple"
157//! METHOD       "jscallMethodSimple"
158//! PASS_AFTER   "IrBuilder"
159//! INST_NOT     /CallStatic.*jsnew::invoke/
160//! INST_NOT     /CallStatic.*jscall::invoke/
161
162function jscallMethodSimple(): int {
163	let resObj = new ExampleClass(42, 42);
164	let res = resObj.instanceEvaluateNumber() as int;
165	if (res == 84) {
166		return 0;
167	} else {
168		return 1;
169	}
170}
171
172//! CHECKER      jscallString JIT
173//! RUN          force_jit: true, entry: "jscallString", options: "--compiler-regex=ETSGLOBAL::jscallString"
174//! METHOD       "jscallString"
175//! PASS_AFTER   "IrBuilder"
176//! INST_NOT     /CallStatic.*jsnew::invoke/
177//! INST_NOT     /CallStatic.*jscall::invoke/
178//! INST         "Intrinsic.JSRuntimeGetValueString"
179//! INST_NEXT    "Intrinsic.StdCoreStringEquals"
180
181function jscallString(): int {
182	let v0: String = 'hello';
183	let v1: String = 'world';
184	let res = evaluateNumber(v0, v1) as String;
185	if (res == 'helloworld') {
186		return 0;
187	} else {
188		return 1;
189	}
190}
191
192//! CHECKER      jsnewString JIT
193//! RUN          force_jit: true, entry: "jsnewString", options: "--compiler-regex=ETSGLOBAL::jsnewString"
194//! METHOD       "jsnewString"
195//! PASS_AFTER   "IrBuilder"
196//! INST_NOT     /CallStatic.*jscall::invoke/
197//! INST_NOT     /CallStatic.*jsnew::invoke/
198//! INST_COUNT   "Intrinsic.JSRuntimeGetPropertyString", 2
199//! INST_NOT     "Intrinsic.JSRuntimeGetPropertyJSValue"
200//! INST_NOT     "Intrinsic.JSRuntimeGetValueString"
201
202function jsnewString(): int {
203	let v0: String = 'hello';
204	let v1: String = 'world';
205	let resObj = new ExampleClass(v0, v1);
206	let resGetV0 = resObj.v0 as String;
207	let resGetV1 = resObj.v1 as String;
208	if (resGetV0 == v0 && resGetV1 == v1) {
209		return 0;
210	} else {
211		return 1;
212	}
213}
214
215//! DISABLED_CHECKER      jsnewSetPropertyString JIT
216//! RUN          force_jit: true, entry: "jsnewSetPropertyString", options: "--compiler-regex=ETSGLOBAL::jsnewSetPropertyString"
217//! METHOD       "jsnewSetPropertyString"
218//! PASS_AFTER   "IrBuilder"
219//! INST_NOT     /CallStatic.*jscall::invoke/
220//! INST_NOT     /CallStatic.*jsnew::invoke/
221//! INST_NOT     "Intrinsic.JSRuntimeSetPropertyJSValue"
222//! INST_COUNT   "Intrinsic.JSRuntimeNewJSValueString", 2
223//! INST_COUNT   "Intrinsic.JSRuntimeSetPropertyString", 2
224//! INST_COUNT   "Intrinsic.JSRuntimeGetPropertyString", 2
225//! INST_NOT     "Intrinsic.JSRuntimeGetPropertyJSValue"
226//! INST_NOT     "Intrinsic.JSRuntimeGetValueString"
227//! PASS_AFTER   "Cleanup"
228//! INST_NOT     "Intrinsic.JSRuntimeNewJSValueString"
229
230function jsnewSetPropertyString(): int {
231	let v0: String = 'hello';
232	let v1: String = 'world';
233	let resObj = new ClassWithEmptyConstructor();
234	resObj.v0 = v0;
235	resObj.v1 = v1;
236	let resGetV0 = resObj.v0 as String;
237	let resGetV1 = resObj.v1 as String;
238	if (resGetV0 == v0 && resGetV1 == v1) {
239		return 0;
240	} else {
241		return 1;
242	}
243}
244
245//! CHECKER      jscallStaticMethodString JIT
246//! RUN          force_jit: true, entry: "jscallStaticMethodString", options: "--compiler-regex=ETSGLOBAL::jscallStaticMethodString"
247//! METHOD       "jscallStaticMethodString"
248//! PASS_AFTER   "IrBuilder"
249//! INST_NOT     /CallStatic.*jsnew::invoke/
250//! INST_NOT     "Intrinsic.JSRuntimeNewJSValueString"
251//! INST_NOT     /CallStatic.*jscall::invoke/
252//! INST    "Intrinsic.JSRuntimeGetValueString"
253
254function jscallStaticMethodString(): int {
255	let v0: String = 'hello';
256	let v1: String = 'world';
257	let res = ExampleClass.evaluateNumber(v0, v1) as String;
258	if (res == 'helloworld') {
259		return 0;
260	} else {
261		return 1;
262	}
263}
264
265function jscallArray(): int {
266	let v0: int[] = new int[10];
267	for (let i = 0; i < 10; ++i) {
268		v0[i] = i * i;
269	}
270
271	let res = evaluateArray(v0, 10);
272	for (let i = 0; i < 10; ++i) {
273		if ((res[i] as int) != 2 * i * i) {
274			return 1;
275		}
276	}
277
278	return 0;
279}
280
281function jsnewArray(): int {
282	let v0: int[] = new int[10];
283	for (let i = 0; i < 10; ++i) {
284		v0[i] = i * i;
285	}
286
287	let resObj = new ExampleClass(v0, v0);
288	let resGetV0 = resObj.v0;
289	let resGetV1 = resObj.v1;
290
291	for (let i = 0; i < 10; ++i) {
292		if ((resGetV0[i] as int) != v0[i] || (resGetV1[i] as int) != v0[i]) {
293			return 1;
294		}
295	}
296	return 0;
297}
298
299function jsnewSetPropertyArray(): int {
300	let v0: int[] = new int[10];
301	for (let i = 0; i < 10; ++i) {
302		v0[i] = i * i;
303	}
304
305	let resObj = new ClassWithEmptyConstructor();
306
307	resObj.v0 = v0;
308	resObj.v1 = v0;
309	let resGetV0 = resObj.v0;
310	let resGetV1 = resObj.v1;
311
312	for (let i = 0; i < 10; ++i) {
313		if ((resGetV0[i] as int) != v0[i] || (resGetV1[i] as int) != v0[i]) {
314			return 1;
315		}
316	}
317	return 0;
318}
319
320function jscallStaticMethodArray(): int {
321	let v0: int[] = new int[10];
322	for (let i = 0; i < 10; ++i) {
323		v0[i] = i * i;
324	}
325
326	let res = ExampleClass.evaluateArray(v0, 10);
327	for (let i = 0; i < 10; ++i) {
328		if ((res[i] as int) != 2 * i * i) {
329			return 1;
330		}
331	}
332	return 0;
333}
334
335function testNamespace(): int {
336	let v0: int = 1;
337	let v1: String = 'Pinky';
338	let resObj = MyNamespace.createKitten(v0, v1);
339	let resId = resObj.id as int;
340	let resName = resObj.name as String;
341	if (resId == v0 && resName == v1) {
342		return 0;
343	} else {
344		return 1;
345	}
346}
347