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:objectcloneproperties 18 * @tc.desc:test object clone properties 19 * @tc.type: FUNC 20 * @tc.require: issueI5NO8G 21 */ 22let obj = { 23 a: "something", 24 42: 42, 25 c: "string", 26 d: undefined 27} 28print(Object.keys(obj)); 29 30let obj2 = { 31 a: "aa", 32 get b() { 33 this.e = "ee"; 34 Object.defineProperty(obj, "c", { 35 value: "c", 36 enumerable: false 37 }); 38 return "bb"; 39 }, 40 c: "cc", 41 123: "123" 42}; 43for (const [key, value] of Object.entries(obj)) { 44 print(key + "," + value); 45} 46print("e," + obj.e); 47 48var obj3 = { 49 a: 4294967295, 50 b: -1, 51 c: 2147483647, 52 d: 2147483648, 53 e: -2147483648, 54 f: -2147483649 55} 56for (const [key, value] of Object.entries(obj3)) { 57 print(key + "," + value); 58} 59 60const objectEntries1 = { 61 a: 'somestring', 62 3: 30, 63 b: 42, 64 5: 50, 65}; 66 67print(Object.entries(objectEntries1)) 68 69const objectEntries2 = { 70 a: 'somestring', 71 3: 30, 72 b: 42, 73 5: 50, 74}; 75objectEntries2[1] = 10; 76objectEntries2[4] = 40; 77print(Object.entries(objectEntries2)) 78 79print(Object.entries("test")); 80 81let obj4 = new Int8Array([-5, 10, 20, 30, 40, 50, 60.6]); 82let obj5 = { 83 a: 1, 84 b: 2, 85 c: 3, 86}; 87Object.defineProperty(obj5, '23', { 88 value: 31, 89 enumerable: false, 90}) 91Object.defineProperty(obj5, 'abc', { 92 value: 31, 93 enumerable: false, 94}) 95let obj6 = { 96 a: 1, 97 b: 2, 98 c: 3, 99}; 100let obj7 = { 101 1: 1, 102 2: 2, 103 3: 3, 104}; 105let obj8 = { 106 1: 1, 107 2: 2, 108 3: 3, 109 a: 1, 110 b: 2, 111 c: 3, 112}; 113let obj9 = { 114 a: 1, 115 b: 2, 116 c: 3, 117}; 118const a = Symbol('a'); 119const b = Symbol.for('b'); 120obj9[a] = 'aSymbol'; 121obj9[b] = 'bSymbol'; 122let obj10 = Object.create( 123 {}, 124 { 125 getBar: { 126 value() { 127 return 55; 128 }, 129 writable: false, 130 enumerable: false, 131 configurable: false, 132 }, 133 }, 134); 135print(JSON.stringify(Object.entries(obj4))); 136print(JSON.stringify(Object.entries(obj5))); 137print(JSON.stringify(Object.entries(obj6))); 138print(JSON.stringify(Object.entries(obj7))); 139print(JSON.stringify(Object.entries(obj8))); 140print(JSON.stringify(Object.entries(obj9))); 141print(JSON.stringify(Object.entries(obj10))); 142 143let arr =[]; 144arr["aaa"]="va"; 145arr["bbb"]="vb"; 146print(Object.entries(arr)) 147