BridgeJS: Support throwing any error conforming to ConvertibleToJSException#695
BridgeJS: Support throwing any error conforming to ConvertibleToJSException#695wfltaylor wants to merge 2 commits intoswiftwasm:mainfrom
Conversation
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 |
Introduce a new protocol
ConvertibleToJSExceptionand support throwing any error (as long as it is specified using typed throws) which conforms to this protocol. It is beneficial for@JSmethods to be usable by non-JS consumers, but requiring the error type to beJSExceptionmakes this unachievable for methods which throw.This PR also fixes an issue where the generated code for throwing methods doesn’t compile at all using Embedded Swift, since it uses
String(describing:).A potential alternative to this approach would be to emit code to support
@JSannotated Swift Errors, which would bridge them to JavaScript. This is a bit more complex so I stuck with the more straightforward approach as a first attempt.