From 7a41ab960cb168157285454dc15ac3624a383538 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 5 Dec 2024 09:59:50 +0000 Subject: [PATCH] LibWeb: Report exceptions when invoking intersection observer callback --- Libraries/LibWeb/DOM/Document.cpp | 5 ++-- .../callback-cross-realm-report-exception.txt | 6 ++++ ...callback-cross-realm-report-exception.html | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/intersection-observer/callback-cross-realm-report-exception.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/intersection-observer/callback-cross-realm-report-exception.html diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index a9f160c150b..ed28f195948 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -4009,9 +4009,8 @@ void Document::queue_intersection_observer_task() auto& callback = observer->callback(); // 5. Invoke callback with queue as the first argument, observer as the second argument, and observer as the callback this value. If this throws an exception, report the exception. - auto completion = WebIDL::invoke_callback(callback, observer.ptr(), wrapped_queue, observer.ptr()); - if (completion.is_abrupt()) - HTML::report_exception(completion, realm); + // NOTE: This does not follow the spec as written precisely, but this is the same thing we do elsewhere and there is a WPT test that relies on this. + (void)WebIDL::invoke_callback(callback, observer.ptr(), WebIDL::ExceptionBehavior::Report, wrapped_queue, observer.ptr()); } })); } diff --git a/Tests/LibWeb/Text/expected/wpt-import/intersection-observer/callback-cross-realm-report-exception.txt b/Tests/LibWeb/Text/expected/wpt-import/intersection-observer/callback-cross-realm-report-exception.txt new file mode 100644 index 00000000000..0047e60d5b4 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/intersection-observer/callback-cross-realm-report-exception.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass IntersectionObserver reports the exception from its callback in the callback's global object \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/intersection-observer/callback-cross-realm-report-exception.html b/Tests/LibWeb/Text/input/wpt-import/intersection-observer/callback-cross-realm-report-exception.html new file mode 100644 index 00000000000..f60d60327c4 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/intersection-observer/callback-cross-realm-report-exception.html @@ -0,0 +1,30 @@ + + +IntersectionObserver reports the exception from its callback in the callback's global object + + + + + +