Skip to content

BridgeJS: Support exporting protocol methods with async and throws - #820

Open
wfltaylor wants to merge 1 commit into
swiftwasm:mainfrom
wfltaylor:async-throws-protocol
Open

wfltaylor wants to merge 1 commit into
swiftwasm:mainfrom
wfltaylor:async-throws-protocol

Conversation

@wfltaylor

@wfltaylor wfltaylor commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Make it so you can implement protocol methods which are async and throws(JSException) in JS. This also fixes a bug where JS exceptions thrown synchronously in async functions were not handled, and allows a non-Promise return (like await).

printer.write("const reject = \(s).memory.getObject(rejectRef);")
printer.write(contentsOf: body)
printer.write("try {")
printer.indent {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment above renderAsyncFunction still says the body "chains .then(resolve, reject) on the import's returned Promise". With this change it goes through Promise.resolve(...), and a synchronous throw ends up in reject. I'd just drop that last part rather than reword it. The body is ten lines, and a description of it will drift again next time:

/// Renders an async import function with resolve/reject closure refs.
///
/// The generated function takes `resolveRef` and `rejectRef` as the first parameters
/// and settles them with the result of the import call.

@krodak

krodak commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thanks, this is great 🎉

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants