14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci/* 174514f5e3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 184514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 194514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 204514f5e3Sopenharmony_ci * You may obtain a copy of the License at 214514f5e3Sopenharmony_ci * 224514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 234514f5e3Sopenharmony_ci * 244514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 254514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 264514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 274514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 284514f5e3Sopenharmony_ci * limitations under the License. 294514f5e3Sopenharmony_ci */ 304514f5e3Sopenharmony_ci 314514f5e3Sopenharmony_cifunction TestSample() 324514f5e3Sopenharmony_ci{ 334514f5e3Sopenharmony_ci print("TestSample:"); 344514f5e3Sopenharmony_ci let arr: number[] = new Array(1025).fill(0); 354514f5e3Sopenharmony_ci arr[1] = 1; 364514f5e3Sopenharmony_ci print(arr[1]); 374514f5e3Sopenharmony_ci} 384514f5e3Sopenharmony_ci 394514f5e3Sopenharmony_cifunction TestArrayWithElementsAndProperties() 404514f5e3Sopenharmony_ci{ 414514f5e3Sopenharmony_ci print("TestArrayWithElementsAndProperties:"); 424514f5e3Sopenharmony_ci let arr: number[] = new Array(2048) 434514f5e3Sopenharmony_ci arr[1] = 2; 444514f5e3Sopenharmony_ci arr[3] = 4; 454514f5e3Sopenharmony_ci arr.x1 = 1; 464514f5e3Sopenharmony_ci arr.x2 = 2; 474514f5e3Sopenharmony_ci arr.x3 = 3; 484514f5e3Sopenharmony_ci arr.x4 = 4; 494514f5e3Sopenharmony_ci arr.x5 = 5; 504514f5e3Sopenharmony_ci arr.length = 2047; 514514f5e3Sopenharmony_ci 524514f5e3Sopenharmony_ci arr.fill("000"); 534514f5e3Sopenharmony_ci print(arr[1]); 544514f5e3Sopenharmony_ci print(arr[3]); 554514f5e3Sopenharmony_ci print(arr.x1); 564514f5e3Sopenharmony_ci print(arr.x2); 574514f5e3Sopenharmony_ci print(arr.x3); 584514f5e3Sopenharmony_ci print(arr.x4); 594514f5e3Sopenharmony_ci print(arr.x5); 604514f5e3Sopenharmony_ci print(arr.length); 614514f5e3Sopenharmony_ci} 624514f5e3Sopenharmony_ci 634514f5e3Sopenharmony_cifunction TestFullArrayWithElementsAndProperties() 644514f5e3Sopenharmony_ci{ 654514f5e3Sopenharmony_ci print("TestFullArrayWithElementsAndProperties:"); 664514f5e3Sopenharmony_ci let arr: number[] = new Array(2048) 674514f5e3Sopenharmony_ci arr.x1 = 1; 684514f5e3Sopenharmony_ci arr.x2 = 2; 694514f5e3Sopenharmony_ci arr.x3 = 3; 704514f5e3Sopenharmony_ci arr.x4 = 4; 714514f5e3Sopenharmony_ci arr.x5 = 5; 724514f5e3Sopenharmony_ci for (let i: number = 0; i < 2048; i++) { 734514f5e3Sopenharmony_ci arr[i] = "apple" 744514f5e3Sopenharmony_ci } 754514f5e3Sopenharmony_ci arr.length = 2047; 764514f5e3Sopenharmony_ci arr.fill(0); 774514f5e3Sopenharmony_ci for (let i: number = 0; i < 5; i++) { 784514f5e3Sopenharmony_ci print(arr[i]); 794514f5e3Sopenharmony_ci } 804514f5e3Sopenharmony_ci for (let i: number = 2045; i < 2048; i++) { 814514f5e3Sopenharmony_ci print(arr[i]); 824514f5e3Sopenharmony_ci } 834514f5e3Sopenharmony_ci print(arr.apple); 844514f5e3Sopenharmony_ci print(arr.x1); 854514f5e3Sopenharmony_ci print(arr.x2); 864514f5e3Sopenharmony_ci print(arr.x3); 874514f5e3Sopenharmony_ci print(arr.x4); 884514f5e3Sopenharmony_ci print(arr.x5); 894514f5e3Sopenharmony_ci print(arr.length); 904514f5e3Sopenharmony_ci} 914514f5e3Sopenharmony_ci 924514f5e3Sopenharmony_cifunction TestShouldNotOptimizeAsFastElements() 934514f5e3Sopenharmony_ci{ 944514f5e3Sopenharmony_ci print("TestShouldNotOptimizeAsFastElements:"); 954514f5e3Sopenharmony_ci let arr: number[] = new Array(1025) 964514f5e3Sopenharmony_ci arr.x1 = 1; 974514f5e3Sopenharmony_ci arr.x2 = 2; 984514f5e3Sopenharmony_ci arr.x3 = 3; 994514f5e3Sopenharmony_ci arr.x4 = 4; 1004514f5e3Sopenharmony_ci arr.x5 = 5; 1014514f5e3Sopenharmony_ci for (let i: number = 0; i < 1025; i++) { 1024514f5e3Sopenharmony_ci arr[i] = "apple" 1034514f5e3Sopenharmony_ci } 1044514f5e3Sopenharmony_ci arr.length = 0; 1054514f5e3Sopenharmony_ci arr.fill(0); 1064514f5e3Sopenharmony_ci for (let i: number = 0; i < 5; i++) { 1074514f5e3Sopenharmony_ci print(arr[i]); 1084514f5e3Sopenharmony_ci } 1094514f5e3Sopenharmony_ci for (let i: number = 1020; i < 1025; i++) { 1104514f5e3Sopenharmony_ci print(arr[i]); 1114514f5e3Sopenharmony_ci } 1124514f5e3Sopenharmony_ci print(arr.apple); 1134514f5e3Sopenharmony_ci print(arr.x1); 1144514f5e3Sopenharmony_ci print(arr.x2); 1154514f5e3Sopenharmony_ci print(arr.x3); 1164514f5e3Sopenharmony_ci print(arr.x4); 1174514f5e3Sopenharmony_ci print(arr.x5); 1184514f5e3Sopenharmony_ci print(arr.length); 1194514f5e3Sopenharmony_ci} 1204514f5e3Sopenharmony_ci 1214514f5e3Sopenharmony_cifunction TestStringArrayWithElementsAndProperties() 1224514f5e3Sopenharmony_ci{ 1234514f5e3Sopenharmony_ci print("TestStringArrayWithElementsAndProperties:"); 1244514f5e3Sopenharmony_ci let arr: string[] = new Array(1025) 1254514f5e3Sopenharmony_ci arr[1] = "apple" 1264514f5e3Sopenharmony_ci arr.apple = "b" 1274514f5e3Sopenharmony_ci 1284514f5e3Sopenharmony_ci arr.fill("ark"); 1294514f5e3Sopenharmony_ci print(arr[0]); 1304514f5e3Sopenharmony_ci print(arr[1]); 1314514f5e3Sopenharmony_ci print(arr.apple); 1324514f5e3Sopenharmony_ci} 1334514f5e3Sopenharmony_ci 1344514f5e3Sopenharmony_cifunction TestSpecialCase() 1354514f5e3Sopenharmony_ci{ 1364514f5e3Sopenharmony_ci print("TestSpecialCase:"); 1374514f5e3Sopenharmony_ci let arr: number[] = new Array(1025); 1384514f5e3Sopenharmony_ci Object.defineProperty(arr, '0', { 1394514f5e3Sopenharmony_ci value: 42, 1404514f5e3Sopenharmony_ci writable: false, 1414514f5e3Sopenharmony_ci }); 1424514f5e3Sopenharmony_ci arr.fill(1); 1434514f5e3Sopenharmony_ci print(arr[0]); 1444514f5e3Sopenharmony_ci} 1454514f5e3Sopenharmony_ci 1464514f5e3Sopenharmony_ciTestSample(); 1474514f5e3Sopenharmony_ciTestArrayWithElementsAndProperties(); 1484514f5e3Sopenharmony_ciTestFullArrayWithElementsAndProperties(); 1494514f5e3Sopenharmony_ciTestShouldNotOptimizeAsFastElements(); 1504514f5e3Sopenharmony_ciTestStringArrayWithElementsAndProperties(); 1514514f5e3Sopenharmony_citry { 1524514f5e3Sopenharmony_ci TestSpecialCase(); 1534514f5e3Sopenharmony_ci} catch (e) {}