1/* 2 * Copyright (c) 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 16// @ts-nocheck 17declare function print(arg:any):string; 18 19function test() { 20 let array = ['12dasd','1dads','sadq','tretgre']; 21 let key = "1"; 22 print(array[key]); 23} 24 25print(ArkTools.isAOTDeoptimized(test)); 26test(); 27print(ArkTools.isAOTDeoptimized(test)); 28 29class BigInteger { 30 static one: BigInteger = BigInteger.nbv(1); 31 array: (number | null)[] = []; 32 33 static nbi(): BigInteger { 34 return new BigInteger(); 35 } 36 37 static nbv(i: number): BigInteger { 38 let r = BigInteger.nbi(); 39 r.fromInt(i); 40 return r; 41 } 42 43 fromInt(x: number): void { 44 this.array = insertValue(this.array, x, 0); 45 print(this.array.length) 46 } 47} 48 49function insertValue(array: (number | null)[], value: number, i: number): (number | null)[] { 50 let arr = array; 51 const surplus = i - arr.length; 52 const surplusArr: (number | null)[] = new Array(surplus + 1).fill(null); 53 arr = arr.concat(surplusArr); 54 arr[i] = value 55 return arr 56} 57 58function hexSha1(s: string): number { 59 let x : number[] = str2binb(s); 60 x = x.concat(Array.from({ length: 12 }, () => 0)); 61 return x.length; 62} 63 64function str2binb(str: string): Array<number> { 65 let bin = Array<number>(); 66 const chrsz = 8 67 const bitoffset = 5 68 const mask = (1 << chrsz) - 1; 69 const toMax = ((str.length * chrsz - 1) >> bitoffset) - bin.length; 70 if (toMax >= 0) { 71 bin = bin.concat(Array<number>(toMax + 1)); 72 } 73 74 for (let i = 0; i < str.length * chrsz; i += chrsz) { 75 bin[i >> bitoffset] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - (i % 32)); 76 } 77 return bin; 78} 79 80function run(): void { 81 let plainText: string = 82 "Two households, both alike in dignity,\nIn here shall miss, our toil shall strive to mend."; 83 84 const copy = 5 85 for (let i = 0; i < copy; i++) { 86 plainText += plainText; 87 } 88 89 print(hexSha1(plainText)); 90} 91 92run(); 93 94function testFastPath() { 95 let array = [ 1 ] 96 97 function foo(arr) { 98 let ret = arr[0]; 99 array[0] = undefined 100 return ret 101 } 102 103 for (let i = 0; i < 100000; i++) { 104 foo(array) 105 foo(array) 106 } 107 print(array[0]) 108} 109 110testFastPath(); 111