14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci/*
174514f5e3Sopenharmony_ci * @tc.name:async
184514f5e3Sopenharmony_ci * @tc.desc:test async function
194514f5e3Sopenharmony_ci * @tc.type: FUNC
204514f5e3Sopenharmony_ci * @tc.require: issueI5NO8G
214514f5e3Sopenharmony_ci */
224514f5e3Sopenharmony_ciasync function foo() {
234514f5e3Sopenharmony_ci    var a = await 1
244514f5e3Sopenharmony_ci    print(a)
254514f5e3Sopenharmony_ci}
264514f5e3Sopenharmony_ci
274514f5e3Sopenharmony_civar s = foo()
284514f5e3Sopenharmony_civar arrow = () => {}
294514f5e3Sopenharmony_civar async_arrow = async () => {}
304514f5e3Sopenharmony_ci
314514f5e3Sopenharmony_ciprint(foo.name)
324514f5e3Sopenharmony_ciprint(foo.call != undefined)
334514f5e3Sopenharmony_ciprint(foo.__proto__.constructor.name);
344514f5e3Sopenharmony_ciprint(foo.__proto__.__proto__.constructor.name);
354514f5e3Sopenharmony_ciprint(foo.__proto__.__proto__.__proto__.constructor.name);
364514f5e3Sopenharmony_ciprint(foo.length)
374514f5e3Sopenharmony_ciprint(arrow.name)
384514f5e3Sopenharmony_ciprint(async_arrow.name)
394514f5e3Sopenharmony_ci
404514f5e3Sopenharmony_cis.then(msg=>{
414514f5e3Sopenharmony_ci    print(msg)
424514f5e3Sopenharmony_ci})
434514f5e3Sopenharmony_ci
444514f5e3Sopenharmony_ci// should return Promise
454514f5e3Sopenharmony_ciasync function testAsync() {
464514f5e3Sopenharmony_ci    throw new Error("hello world!!!");
474514f5e3Sopenharmony_ci}
484514f5e3Sopenharmony_civar a = testAsync();
494514f5e3Sopenharmony_ciprint(a instanceof Promise);
504514f5e3Sopenharmony_cia.then(
514514f5e3Sopenharmony_ci    function (result) {
524514f5e3Sopenharmony_ci        print("testAsync success!!!");
534514f5e3Sopenharmony_ci    },
544514f5e3Sopenharmony_ci    function (result) {
554514f5e3Sopenharmony_ci        print("testAsync failed: " + result);
564514f5e3Sopenharmony_ci    }
574514f5e3Sopenharmony_ci)
584514f5e3Sopenharmony_ciprint("main over");
594514f5e3Sopenharmony_ci
604514f5e3Sopenharmony_cilet obj = {
614514f5e3Sopenharmony_ci    async *foo() {
624514f5e3Sopenharmony_ci        yield await Promise.resolve('a');
634514f5e3Sopenharmony_ci        yield await Promise.resolve('b');
644514f5e3Sopenharmony_ci        yield await Promise.resolve('c');
654514f5e3Sopenharmony_ci    }
664514f5e3Sopenharmony_ci}
674514f5e3Sopenharmony_cilet str = '';
684514f5e3Sopenharmony_ciasync function generate() {
694514f5e3Sopenharmony_ci    for await (const val of obj.foo()) {
704514f5e3Sopenharmony_ci        str = str + val;
714514f5e3Sopenharmony_ci    }
724514f5e3Sopenharmony_ci    print(str);
734514f5e3Sopenharmony_ci}
744514f5e3Sopenharmony_cigenerate();
754514f5e3Sopenharmony_ci
764514f5e3Sopenharmony_ci
774514f5e3Sopenharmony_ciclass C0 {
784514f5e3Sopenharmony_ci    constructor(a2, a3, a4) {
794514f5e3Sopenharmony_ci        async function* f5(a6, a7, a8, a9) {
804514f5e3Sopenharmony_ci        }
814514f5e3Sopenharmony_ci        f5(this, a4, a2, C0).next();
824514f5e3Sopenharmony_ci        new C0();
834514f5e3Sopenharmony_ci    }
844514f5e3Sopenharmony_ci}
854514f5e3Sopenharmony_citry {
864514f5e3Sopenharmony_ci    new C0(C0, C0, C0);
874514f5e3Sopenharmony_ci} catch (e) {
884514f5e3Sopenharmony_ci    print(e);
894514f5e3Sopenharmony_ci}