Skip to content

[embind] Allow awaiting Promises in non-Promise coroutines & catching Promise C++ exceptions#26195

Draft
stevenwdv wants to merge 3 commits intoemscripten-core:mainfrom
stevenwdv:val-coro-fixes
Draft

[embind] Allow awaiting Promises in non-Promise coroutines & catching Promise C++ exceptions#26195
stevenwdv wants to merge 3 commits intoemscripten-core:mainfrom
stevenwdv:val-coro-fixes

Conversation

@stevenwdv
Copy link
Contributor

@stevenwdv stevenwdv commented Feb 1, 2026

Closes #26064
Closes #25396

Still crashes on test_embind_val_coro_catch_cpp_exception, not sure why due to #26213.

TODO:

  • What to do on rejection in the !__cpp_exceptions case in a non-Promise coroutine?
    • I'll just rethrow the JS exception in await_resume anyway.
  • And should a non-C++ exception immediately reject a Promise since we cannot catch it (Allow catching JavaScript exceptions from C++ #11496)? Can we even distinguish C++ exceptions from non-C++ ones?
    • Seems hard to distinguish since there's 3 possible exception types depending on the compiler settings, once of which is just a number.

…ipten-core#26064), allow catching Promise C++ exceptions (closes emscripten-core#25396)

Still crashes on `test_embind_val_coro_catch_cpp_exception`, not sure why.
TODO: What to do on rejection in the !__cpp_exceptions case in a non-Promise coroutine?
@sbc100 sbc100 changed the title Allow awaiting Promises in non-Promise coroutines & catching Promise C++ exceptions [embind] Allow awaiting Promises in non-Promise coroutines & catching Promise C++ exceptions Feb 1, 2026
@sbc100 sbc100 added the embind label Feb 1, 2026
@stevenwdv
Copy link
Contributor Author

Btw, if anyone knows why the rethrow of the val wrapping a std::runtime_error in await_resume may be crashing, let me know, because I haven't figured it out.

@stevenwdv
Copy link
Contributor Author

The cause of the crash seems to be #26213

I'll not terminate here so non-C++ exceptions still propagate to `await_resume`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow awaiting val Promises in other coroutines Coroutines with val.h cannot catch exceptions

2 participants