--- a/Python/errors.c +++ b/Python/errors.c @@ -1584,6 +1584,15 @@ An exception must be set when calling this function. */ +#ifdef __EMSCRIPTEN__ +/* Optional native embedder notification, before allocation, exception + * normalization, audit hooks or sys.unraisablehook. The embedder must not call + * Python or retain the exception. Standalone CPython keeps its usual behavior. + * This also covers a deleted sys.unraisablehook and hook-argument OOM. */ +extern void web_engine_python_unraisable(const char *exception_type) + __attribute__((weak)); +#endif + static void format_unraisable_v(const char *format, va_list va, PyObject *obj) { @@ -1598,6 +1607,13 @@ PyObject *exc_type, *exc_value, *exc_tb; _PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb); +#ifdef __EMSCRIPTEN__ + if (web_engine_python_unraisable != NULL) { + web_engine_python_unraisable( + exc_type != NULL && PyType_Check(exc_type) + ? ((PyTypeObject *)exc_type)->tp_name : NULL); + } +#endif assert(exc_type != NULL); if (exc_type == NULL) {