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:sendablefunc
18 * @tc.desc:test sendablefunc
19 * @tc.type: FUNC
20 * @tc.require: issueI8R6LC
21 */
22
23// @ts-nocheck
24declare function print(str: any): string;
25
26print("========== Test Normal Function ==========")
27function fooTop()
28{
29    'use sendable'
30    print("sendable foo top");
31}
32
33class C {
34    constructor() {
35        'use sendable'
36    }
37    PrintStr() {
38        print("sendable class C top");
39    }
40}
41function foo(a : number) {
42    'use sendable'
43    print("sendable func foo :" + a);
44    fooTop();
45    let c = new C();
46    c.PrintStr();
47}
48
49function bar()
50{
51    'use sendable'
52    print("sendable func bar");
53}
54
55class A {
56    constructor() {
57        'use sendable'
58    }
59    fooA() {
60        foo(1);
61    }
62}
63
64type FuncType = () => void
65class B {
66    callback: FuncType;
67    constructor(f : FuncType) {
68        'use sendable'
69        this.callback = f;
70    }
71}
72let a = new A()
73a.fooA()
74let b = new B(bar)
75b.callback();
76
77print("========== Test Async Function ==========")
78function sendData() {
79    'use sendable'
80    print("await send data");
81}
82  
83async function fooAsyncTop()
84{
85    'use sendable'
86    print("sendable async foo top");
87}
88
89async function fooAsync(a : number) {
90    'use sendable'
91    print("sendable async func foo :" + a);
92    fooAsyncTop();
93    let c = new C();
94    c.PrintStr();
95    await sendData();
96}
97  
98async function barAsync()
99{
100    'use sendable'
101    print("sendable async func bar");
102}
103  
104class D {
105    constructor() {
106        'use sendable'
107    }
108    fooD() {
109        fooAsync(2);
110    }
111}
112  
113type FuncAsyncType = () => Promise<void>
114
115class E {
116    callback: FuncAsyncType;
117    constructor(f : FuncAsyncType) {
118        'use sendable'
119        this.callback = f;
120    }
121}
122let d = new D()
123d.fooD()
124let e = new E(barAsync)
125e.callback();
126print(fooAsyncTop.name);
127print(fooTop.name);
128print(fooTop.length)
129print(fooTop.prototype);