Skip to content

Comments

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

Draft
stevenwdv wants to merge 6 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 6 commits intoemscripten-core:mainfrom
stevenwdv:val-coro-fixes

Conversation

@stevenwdv
Copy link
Contributor

@stevenwdv stevenwdv commented Feb 1, 2026

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

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.
    • We need to, as otherwise test_embind_val_coro_propagate_js_error fails

Fixes: #26064
Fixes: #25396

…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

@stevenwdv
Copy link
Contributor Author

stevenwdv commented Feb 18, 2026

Currently -fno-exceptions tests seem to fail on #26290, although it could be that there's another cause that __cxa_throw gets linked in despite exceptions being disabled..?

@stevenwdv
Copy link
Contributor Author

Currently -fno-exceptions tests seem to fail on #26290, although it could be that there's another cause that __cxa_throw gets linked in despite exceptions being disabled..?

Actually, the error message for test_embind_val_coro_propagate_js_error_noexcept, besides complaining about exceptionLast, also says:

error: DISABLE_EXCEPTION_THROWING was set (likely due to -fno-exceptions), which means no C++ exception throwing support code is linked in, but such support is required by symbol '__cxa_throw'. Either do not set DISABLE_EXCEPTION_THROWING (if you do want exception throwing) or compile all source files with -fno-exceptions (so that no exceptions support code is required); also make sure DISABLE_EXCEPTION_CATCHING is set to the right value - if you want exceptions, it should be off, and vice versa.

But I don't see where I'm referencing __cxa_throw? @aheejin sorry for mentioning you, would you know more about this? (In this test I'm intentionally disabling exceptions to test if Promises still reject when awaiting promises rejected by JS errors.)


Besides that test_embind_val_coro_catch_cpp_exception apparently now fails, but I haven't looked into that yet.

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