• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2024 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
16let counter = 0;
17
18function stack_eater(): void {
19    stack_eater();
20}
21
22function coro_stack_overflow(): Object | null {
23    stack_eater();
24    return null;
25}
26
27function coro_error(): Object {
28    throw new Error();
29}
30
31function test_stack_overflow(): boolean {
32    try {
33        await launch coro_stack_overflow();
34        console.println("No exceptions thrown by coro_stack_overflow() but should be!")
35        return false;
36    } catch (e) {
37        if (!(e instanceof StackOverflowError)) {
38            console.println("Expected StackOverflowError but another exception has been thrown!");
39            return false;
40        }
41        return true;
42    }
43}
44
45function test_error(): boolean {
46    try {
47        await launch coro_error();
48        console.println("No exceptions thrown by coro_error() but should be!")
49        return false;
50    } catch (e) {
51        if (!(e instanceof Error)) {
52            console.println("Expected Error but another exception has been thrown!");
53            return false;
54        }
55        return true;
56    }
57}
58
59export function main(): int {
60    if (!test_stack_overflow()) {
61        return 1;
62    }
63    if (!test_error()) {
64        return 1;
65    }
66    return 0;
67}
68