LibWeb: Avoid unhandled rejection when reporting module script errors

Report module script evaluation failures without replacing the returned
evaluation promise or rethrowing from the reporting reaction. This
avoids surfacing the same failure as both a script error and an
unhandled promise rejection.
This commit is contained in:
Shannon Booth 2026-05-15 16:10:26 +02:00 committed by Shannon Booth
parent 881c1484fe
commit 951e2e1986
Notes: github-actions[bot] 2026-05-16 07:53:32 +00:00
10 changed files with 89 additions and 4 deletions

View file

@ -301,10 +301,9 @@ WebIDL::Promise* ModuleScript::run(PreventErrorReporting prevent_error_reporting
// 8. If preventErrorReporting is false, then upon rejection of evaluationPromise with reason, report the exception given by reason for script.
if (prevent_error_reporting == PreventErrorReporting::No) {
HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
evaluation_promise = WebIDL::upon_rejection(*evaluation_promise, GC::create_function(realm.heap(), [&realm](JS::Value reason) -> WebIDL::ExceptionOr<JS::Value> {
auto& window_or_worker = as<WindowOrWorkerGlobalScopeMixin>(realm.global_object());
window_or_worker.report_an_exception(reason);
return throw_completion(reason);
WebIDL::upon_rejection(*evaluation_promise, GC::create_function(realm.heap(), [&realm](JS::Value reason) -> WebIDL::ExceptionOr<JS::Value> {
as<WindowOrWorkerGlobalScopeMixin>(realm.global_object()).report_an_exception(reason);
return JS::js_undefined();
}));
}