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
16declare function print(arg:any, arg1?: any):string;
17
18const ON_HEAP_LENGTH = 100;
19const NOT_ON_HEAP_LENGTH = 5000;
20
21let ta0 = new Uint32Array(ON_HEAP_LENGTH);
22for(let i: number = 0; i < ON_HEAP_LENGTH; i++) {
23    ta0[i] = i;
24}
25
26let ta1 = new Float64Array(NOT_ON_HEAP_LENGTH);
27for(let i: number = 0; i < NOT_ON_HEAP_LENGTH; i++) {
28    ta1[i] = i;
29}
30
31// on heap
32function foo(ta: Uint32Array) {
33    let res = 0;
34    for(let i: number = 0; i < ON_HEAP_LENGTH; i++) {
35        res += ta[i];
36    }
37    print(res);
38}
39foo(ta0);
40
41// not on heap
42function bar(ta: Float64Array) {
43    let res = 0;
44    for(let i: number = 0; i < NOT_ON_HEAP_LENGTH; i++) {
45        res += ta[i];
46    }
47    print(res);
48}
49bar(ta1);
50
51
52// none
53function baz(ta: Uint32Array | Float64Array) {
54    let res = 0;
55    for(let i: number = 0; i < ON_HEAP_LENGTH; i++) {
56        res += ta[i];
57    }
58    print(res);
59}
60baz(ta0);
61baz(ta1);
62
63function foo2() {
64    for (let v0 = 0; v0 < 5; v0++) {
65        function f1(a2, a3, a4) {
66            const v6 = new BigUint64Array(a2);
67            const v8 = new Uint8ClampedArray();
68            const t13 = v8.__proto__;
69            t13.__proto__ = v6;
70            return v6;
71        }
72        f1(f1());
73    }
74}
75foo2()
76