swiftwasm / swift

WebAssembly support for the Swift programming language
https://swiftwasm.org
1.29k stars 28 forks source link

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

Open MaxDesiatov opened 1 year ago

MaxDesiatov commented 1 year ago

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

kateinoigakukun commented 1 year ago

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

MaxDesiatov commented 1 year ago

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?

kateinoigakukun commented 1 year ago

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