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
16/*
17 * @tc.name:error_helper
18 * @tc.desc:test error
19 * @tc.type: FUNC
20 */
21
22const v34 = [2147483648,238049746,1260900180,371215732,1655235460,-65536,-94405277,536870888,-1073741824,-65537];
23class C37 {
24}
25const v40 = new C37();
26try {
27v40.constructor(v40, v34, C37, v40);
28} catch(e45) {
29const v46 = e45.toString;
30const v50 = v46.call(v34);
31print(v50);
32}
33
34let msg = [];
35let msg_cnt = 0;
36function runNearStackLimit(f) {
37    function t() {
38        try {
39            t();
40        } catch (e) {
41            msg[msg_cnt++] = e.message;
42            f();
43        }
44    };
45    t();
46}
47let idx = 0;
48let obj = {};
49function f() {
50    idx++;
51    if (idx == 1) {
52        idx = idx11;
53        // 0 in idx
54    }
55}
56let funcs = [f];
57for (let i = 1; i < 2; i++) {
58    funcs[i] = function () {
59        funcs[i - 1]();
60    }
61}
62
63for(let i=0;i<funcs.length;i++){
64    print("********************************")
65    msg_cnt = 0;
66    idx=0;
67    runNearStackLimit(funcs[i])
68    print(msg[msg_cnt-1]);
69}
70
71// Be sure to put this case at the end because this case will change prototype of error constructor
72try {
73    0();
74} catch (err) {
75    err.constructor.prototype.name = 123456789;
76}
77try {
78    0();
79} catch (e) {}
80
81Object.defineProperty(ReferenceError.prototype, "constructor", {
82    value: "x"
83})
84try {
85    print(x13)
86} catch (e) {
87    print(e.name)
88}
89