swift icon indicating copy to clipboard operation
swift copied to clipboard

`main` function in `@main` types fails with error

Open MaxDesiatov opened this issue 3 years ago • 3 comments

Describe the bug This sample code fails immediately after it starts executing:

import JavaScriptEventLoop

@main
enum Main {
  static func main() async throws {
    JavaScriptEventLoop.installGlobalExecutor()
  }
}

Screenshots Screenshot 2022-08-28 at 21 44 22

Environment SwiftWasm 5.6.0, carton 0.16.1

MaxDesiatov avatar Aug 28 '22 20:08 MaxDesiatov

It's expected behavior because async_Main calls exit(0) at the end of the initial job.

kateinoigakukun avatar Aug 29 '22 02:08 kateinoigakukun

My concern here is that uncaught JS error may lead to some unexpected/incorrect state, or at least confuse users. Maybe we should detect this specific exit(0) in our entrypoint code to make sure it's handled appropriately?

MaxDesiatov avatar Aug 29 '22 11:08 MaxDesiatov

@MaxDesiatov Yes, that should be handled by instance startup JS code.

kateinoigakukun avatar Aug 29 '22 11:08 kateinoigakukun