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