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/*
17 * @tc.name:object
18 * @tc.desc:test object
19 * @tc.type: FUNC
20 * @tc.require: issueI9DUIF
21 */
22
23// test case for getPrototypeOf
24var _handler, _target;
25var target = {};
26var handler = {
27  getPrototypeOf: function(t) {
28    _handler = this;
29    _target = t;
30    return {};
31  }
32};
33
34var prototypeObj = {};
35var obj01 = Object.create(prototypeObj);
36var obj02 = new Proxy(target, handler);
37
38Object.getPrototypeOf(obj01);
39print(_handler === handler);
40print(_target === target);
41
42Object.getPrototypeOf(obj02);
43print(_handler === handler);
44print(_target === target);
45
46let obj1 = new Int8Array([-5, 10, 20, 30, 40, 50, 60.6]);
47let obj2 = {
48    a: 1,
49    b: 2,
50    c: 3,
51};
52Object.defineProperty(obj2, '23', {
53    value: 31,
54    enumerable: false,
55})
56Object.defineProperty(obj2, 'abc', {
57    value: 31,
58    enumerable: false,
59})
60let obj3 = {
61    a: 1,
62    b: 2,
63    c: 3,
64};
65let obj4 = {
66    1: 1,
67    2: 2,
68    3: 3,
69};
70let obj5 = {
71    1: 1,
72    2: 2,
73    3: 3,
74    a: 1,
75    b: 2,
76    c: 3,
77};
78let obj6 = {
79    a: 1,
80    b: 2,
81    c: 3,
82};
83const a = Symbol('a');
84const b = Symbol.for('b');
85obj6[a] = 'aSymbol';
86obj6[b] = 'bSymbol';
87let obj7 = Object.create(
88    {},
89    {
90        getBar: {
91            value() {
92                return 55;
93            },
94            writable: false,
95            enumerable: false,
96            configurable: false,
97        },
98    },
99);
100let obj11 = new Int8Array([-5, 10, 20, 30, 40, 50, 60.6]);
101let obj12 = {
102    a: 1,
103    b: 2,
104    c: 3,
105};
106Object.defineProperty(obj12, '23', {
107    value: 31,
108    enumerable: false,
109})
110Object.defineProperty(obj12, 'abc', {
111    value: 31,
112    enumerable: false,
113})
114let obj13 = {
115    a: 1,
116    b: 2,
117    c: 3,
118};
119let obj14 = new Object();
120Object.preventExtensions(obj14);
121let obj15 = {
122    1: 1,
123    2: 2,
124    3: 3,
125};
126Object.preventExtensions(obj15);
127let obj16 = {
128    1: 1,
129    2: 2,
130    3: 3,
131    a: 1,
132    b: 2,
133    c: 3,
134};
135Object.preventExtensions(obj16);
136let obj17 = Object.create(
137    {},
138    {
139        getBar: {
140            value() {
141                return 55;
142            },
143            configurable: true,
144            writable: true,
145        },
146    },
147);
148Object.preventExtensions(obj17);
149let obj18 = Object.create(
150    {},
151    {
152        getBar: {
153            value() {
154                return 55;
155            },
156            configurable: false,
157            writable: true,
158        },
159    },
160);
161Object.preventExtensions(obj18);
162let obj19 = Object.create(
163    {},
164    {
165        getBar: {
166            value() {
167                return 55;
168            },
169            configurable: false,
170            writable: false,
171        },
172    },
173);
174Object.preventExtensions(obj19);
175
176// test for getOwnPropertyNames()
177print(Object.getOwnPropertyNames(obj1));
178print(Object.getOwnPropertyNames(obj2));
179print(Object.getOwnPropertyNames(obj3));
180print(Object.getOwnPropertyNames(obj4));
181print(Object.getOwnPropertyNames(obj5));
182print(Object.getOwnPropertyNames(obj6));
183// test for getOwnPropertySymbols()
184print(Object.getOwnPropertySymbols(obj1).length);
185print(Object.getOwnPropertySymbols(obj2).length);
186print(Object.getOwnPropertySymbols(obj3).length);
187print(Object.getOwnPropertySymbols(obj4).length);
188print(Object.getOwnPropertySymbols(obj5).length);
189print(Object.getOwnPropertySymbols(obj6).length);
190// test for isFrozen()
191print(Object.isFrozen(obj11));
192print(Object.isFrozen(obj12));
193print(Object.isFrozen(obj13));
194print(Object.isFrozen(obj14));
195print(Object.isFrozen(obj15));
196print(Object.isFrozen(obj16));
197print(Object.isFrozen(obj17));
198print(Object.isFrozen(obj18));
199print(Object.isFrozen(obj19));
200// test for isSealed()
201print(Object.isSealed(obj11));
202print(Object.isSealed(obj12));
203print(Object.isSealed(obj13));
204print(Object.isSealed(obj14));
205print(Object.isSealed(obj15));
206print(Object.isSealed(obj16));
207print(Object.isSealed(obj17));
208print(Object.isSealed(obj18));
209print(Object.isSealed(obj19));
210// test for getOwnPropertyDescriptors()
211let desc1 = Object.getOwnPropertyDescriptors(obj1);
212let desc2 = Object.getOwnPropertyDescriptors(obj2);
213let desc3 = Object.getOwnPropertyDescriptors(obj3);
214let desc4 = Object.getOwnPropertyDescriptors(obj4);
215let desc5 = Object.getOwnPropertyDescriptors(obj5);
216let desc6 = Object.getOwnPropertyDescriptors(obj6);
217let desc7 = Object.getOwnPropertyDescriptors(obj7);
218print(JSON.stringify(desc1[0]));
219print(JSON.stringify(desc2.abc));
220print(JSON.stringify(desc3.a));
221print(JSON.stringify(desc4[1]));
222print(JSON.stringify(desc5[3]));
223print(JSON.stringify(desc6.c));
224print(JSON.stringify(desc7.getBar));