1/*
2 * Copyright (c) 2021 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:proxy
18 * @tc.desc:test Proxy
19 * @tc.type: FUNC
20 * @tc.require: issueI5NO8G
21 */
22function add(a, b) {
23    return a + b
24}
25
26let addProxy = new Proxy(add, {
27    apply: function(target, thisObj, args) {
28        return target.apply(thisObj, args)
29    }
30})
31
32for (var a = 1; a < 4; a++) {
33    print(addProxy(a, 12345 * a) == add(12345 * a, a))
34}
35
36class EmployeeEntity {
37}
38let obj = new Proxy(EmployeeEntity,{});
39let arr = [obj];
40let set = new Set(arr);
41print(set.has(obj));
42
43const a1 = [-122934378, 536870889, -4294967295, -8, 11];
44const a2 = {
45};
46const a3 = new Proxy(a1, a2);
47Object.freeze(a3);
48print(Object.isFrozen(a3));
49
50// CreateObjectWithExcludedKeysDealWithProxy
51const v0 = {
52    value : 'name'
53};
54const v5 = new Proxy(v0, {});
55const {...v1} = v5;
56print(v5.value);
57print(v1.value);
58print(v0.value);
59const arr2 = [1, 2, 3];
60const handler = {};
61const proxy = new Proxy(arr2, handler);
62const arr3 = proxy.constructor(1, 2, 3, 4);
63print(arr3);
64
65function Target() {}
66var handler1 = {
67    construct: function(t, args) {
68        return new t(args[0], args[1]);
69    }
70};
71var P = new Proxy(Target, handler1);
72new P(1, 1.1);
73print(JSON.stringify(P));
74
75try {
76    const v0 = /\011+/iyd;
77    const v2 = new Uint8ClampedArray(v0, Uint8ClampedArray, Uint8ClampedArray);
78    const v5 = new Proxy({}, {});
79    new v5(...v2);
80} catch (e) {
81    print("constructor is fail");
82}
83const v3 = new Uint8ClampedArray(WeakMap);
84const o3 = {
85};
86const v6 = new Proxy(v3, o3);
87try {
88    new WeakMap([v6]);
89} catch (error) {
90    print(error.name);
91}
92
93let arr1 = new Array;
94let pro1 = new Proxy(arr1, {});
95print(Object.prototype.toString.call(pro1));
96
97
98{
99    const v0 = [1.0,2.2250738585072014e-308,-7.829944258836235e+307,-7.46187308415638,-413646.9640026712,5.525707214803659e+305,-1000000000000.0];
100    const o1 = {
101    };
102    const v3 = new Proxy(v0, o1);
103
104    function F4(a6, a7) {
105        const v9 = new Proxy(RegExp, v3);
106        new v9(a6, v9, F4);
107    }
108    try {
109        new F4();
110    } catch (error) {
111        print(error);
112    }
113}
114class C9{};
115let v4 = new Proxy(Uint32Array,Reflect);
116class C4 extends v4 {
117  constructor(a6,a7,a8){
118    super();
119    new C9(a7,C4);
120  }
121}
122new C4();
123print("test proxy constructor success!")
124
125var proxyHandler = {};
126var object = new Proxy({}, proxyHandler);
127print(Object.prototype.isPrototypeOf.call(object, object));
128
129{
130  function f0() {
131    return f0;
132  }
133  class C1 extends f0 {
134  }
135
136  try{
137     let  v11 = new Proxy(C1);
138  }catch(err) {
139    print(err)
140  }
141}