◐ Shell
clean mode source ↗

BridgeJS: Support throwing any error conforming to ConvertibleToJSException by wfltaylor · Pull Request #695 · swiftwasm/JavaScriptKit

It is beneficial for @JS methods to be usable by non-JS consumers, but requiring the error type to be JSException makes this unachievable for methods which throw.

I'm not sure I understand, can you elaborate and provide an example?

For example, someone might want to write cross platform SDK which is consumed by JavaScript on the web, but Java on Android, and C++ on the server. Currently, any throwing function would need to be wrapped to map any error to JSException to annotate it with @JS. Instead, if we could use a type which conforms to ConvertibleToJSException, the same method could be called from JavaScript code, Swift code, and any other suitable consumer.