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