1/* 2 * Copyright (c) 2022 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/* 17 * @tc.name:builtins 18 * @tc.desc:test builtins 19 * @tc.type: FUNC 20 * @tc.require: issueI5NO8G 21 */ 22var arrayLong = {"1" : "fds", "wode" : "fff"}; 23Object.defineProperty(arrayLong, "2", { 24 configurable:true, 25 enumerable:true, 26 value:"ggg", 27 writable:true 28}) 29for (const key in arrayLong) { 30 print(key); 31 delete arrayLong[2]; 32} 33 34Object.defineProperty(arrayLong, "3", { 35 configurable:true, 36 enumerable:true, 37 value:"ggg", 38 writable:true 39}) 40for (const key in arrayLong) { 41 print(key); 42 Object.defineProperty(arrayLong, "3", { 43 configurable:true, 44 enumerable:false, 45 value:"fff", 46 writable:true 47 }) 48} 49 50Object.defineProperty(arrayLong, "4", { 51 configurable:true, 52 enumerable:false, 53 value:"ggg", 54 writable:true 55}) 56for (const key in arrayLong) { 57 print(key); 58 Object.defineProperty(arrayLong, "4", { 59 configurable:true, 60 enumerable:true, 61 value:"fff", 62 writable:true 63 }) 64 arrayLong.sss = "fds"; 65} 66 67const targetObj = { 68 _secret: 'easily scared', 69 eyeCount: 4 70}; 71 72Object.defineProperty(targetObj, "wode", { 73 configurable:true, 74 enumerable:false, 75 value:"ggg", 76 writable:true 77}) 78 79const proxy_has = new Proxy(targetObj, { 80 has: (target, key) => { 81 print("key==",key) 82 if (key.includes('_')) { 83 return false; 84 } 85 return key in target; 86 } 87}) 88 89for (const key in proxy_has) { 90 print(key); 91 delete proxy_has.eyeCount; 92} 93 94var view = new Int16Array(3); 95view[1] = 23; 96view[2] = 45; 97view[3] = 67; 98view.hhh = "wode"; 99for (const key in view) { 100 print(key); 101} 102for (const key in view) { 103 print(key); 104 delete view.hhh; 105} 106 107try { 108 const obj = {}; 109 obj.getOwnPropertyDescriptor = {}; 110 const proxy = new Proxy(new Array(100), obj); 111 for (const i in proxy) {} 112} catch (err) { 113 print(err instanceof TypeError); 114} 115 116// PoC testcase 117try { 118 class C { 119 120 } 121 C.getPrototypeOf = 3014; 122 const proxy = new Proxy([7], C); 123 for (const v in proxy) { 124 125 } 126} catch (err) { 127 print(err instanceof TypeError); 128}