1/* 2 * Copyright (c) 2023 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 16function createArray(len) { 17 return Array.apply(null, { length: len }); 18} 19 20let arr = createArray(10); 21let a1 = createArray(23.2); 22let a2 = createArray(); 23print(arr); 24print(a1); 25print(a2.length); 26const v1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; 27const v4 = Int8Array.from(v1, v5 => v5.charCodeAt(0)); 28Object.defineProperty(v4, "length", { 29 value: 0 30}); 31print(String.fromCharCode.apply(null, v4)); 32 33function f0(a, b) { 34 print(a, b); 35} 36 37let v38; 38 39function f2() { 40 arguments.length = -1; 41 v38 = arguments; 42} 43 44f2(1, 2); 45f0.apply(null, v38); 46 47// undefined 48try { 49 const v3 = new ArrayBuffer(17); 50 51 function F4(a6, a7) { 52 if (!new.target) { 53 throw 'must be called with new'; 54 } 55 56 function f8(a9, a10, a11) { 57 } 58 59 const v14 = new BigUint64Array(31); 60 const o15 = { 61 ...v14, 62 ...v14, 63 }; 64 Object.defineProperty(o15, 4, { set: f8 }); 65 } 66 67 const v16 = new F4(); 68 F4(v16, v3); 69} catch (error) { 70 print(error.name) 71} 72 73// undefined 74try { 75 const v3 = [100, Int8Array]; 76 const v6 = new ArrayBuffer(13); 77 78 function F7(a9, a10) { 79 if (!new.target) { 80 throw 'must be called with new'; 81 } 82 83 function f11(a12, a13, a14) { 84 } 85 86 const v17 = new BigUint64Array(35); 87 const o18 = { 88 ...v17, 89 ...v17, 90 }; 91 Object.defineProperty(o18, 4, { set: f11 }); 92 } 93 94 const v19 = new F7(); 95 F7(v19, v6); 96 JSON.stringify(6, v3); 97} catch (error) { 98 print(error.name) 99} 100 101print(Function.name); 102print(Function.length); 103print(Function.prototype.name); 104print(Function.prototype.length); 105 106for (let key in Function) { 107 print(key); 108} 109 110for (let key in Function.prototype) { 111 print(key); 112} 113 114var backup_apply = Function.prototype.apply; 115Function.prototype.constructor = 1; 116Function.prototype.apply = 1; 117Function.prototype.bind = 1; 118Function.prototype.call = 1; 119Function.prototype.toString = 1; 120 121try{ 122 Function.name = 1; 123} catch(e) { 124 print(e); 125} 126 127try{ 128 Function.length = 1; 129} catch(e) { 130 print(e); 131} 132 133try{ 134 Function.prototype = 1; 135} catch(e) { 136 print(e); 137} 138 139try{ 140 Function.prototype.name = 1; 141} catch(e) { 142 print(e); 143} 144 145try{ 146 Function.prototype.length = 1; 147} catch(e) { 148 print(e); 149} 150 151try{ 152 Function.prototype.caller = 1; 153} catch(e) { 154 print(e); 155} 156 157try{ 158 Function.prototype.arguments = 1; 159} catch(e) { 160 print(e); 161} 162 163 164try{ 165 Function.prototype[Symbol.hasInstance] = 1; 166} catch(e) { 167 print(e); 168} 169 170Function.prototype.apply = backup_apply; 171 172let a3 = [1, 2, 3]; 173function func1(a, b, c, d) { 174 arguments.length = 100; 175 func2.apply(null, arguments, 0, 0); // c interpreter 176} 177function func2(a) { 178 print(a.length); 179 for (let i = 0; i < a.length; ++i) { 180 print(a[i]); 181 } 182} 183func1(a3); 184