From 62ecff0b4052e1dee95c3bc6ad1dbdf9cdd61299 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 5 Dec 2024 10:05:10 +0000 Subject: [PATCH] LibWeb: Report exceptions that occur during microtask callback --- Libraries/LibWeb/HTML/HTMLCanvasElement.cpp | 4 +-- .../LibWeb/HTML/UniversalGlobalScope.cpp | 8 ++--- ...-cross-realm-callback-report-exception.txt | 6 ++++ ...-cross-realm-callback-report-exception.txt | 6 ++++ ...cross-realm-callback-report-exception.html | 29 +++++++++++++++++++ ...cross-realm-callback-report-exception.html | 28 ++++++++++++++++++ 6 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-canvas-element/toBlob-cross-realm-callback-report-exception.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-canvas-element/toBlob-cross-realm-callback-report-exception.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.html diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 0b3a630d437..0e9fc291561 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -375,8 +375,8 @@ WebIDL::ExceptionOr HTMLCanvasElement::to_blob(GC::Refbuffer, TRY_OR_THROW_OOM(vm(), String::from_utf8(file_result->mime_type))); - // 2. Invoke callback with « result ». - TRY(WebIDL::invoke_callback(*callback, {}, move(blob_result))); + // 2. Invoke callback with « result » and "report". + TRY(WebIDL::invoke_callback(*callback, {}, WebIDL::ExceptionBehavior::Report, move(blob_result))); return {}; }); if (maybe_error.is_throw_completion()) diff --git a/Libraries/LibWeb/HTML/UniversalGlobalScope.cpp b/Libraries/LibWeb/HTML/UniversalGlobalScope.cpp index a655e333a21..3199611b7fe 100644 --- a/Libraries/LibWeb/HTML/UniversalGlobalScope.cpp +++ b/Libraries/LibWeb/HTML/UniversalGlobalScope.cpp @@ -84,11 +84,9 @@ void UniversalGlobalScopeMixin::queue_microtask(WebIDL::CallbackType& callback) if (is(this_impl())) document = &static_cast(this_impl()).associated_document(); - // The queueMicrotask(callback) method must queue a microtask to invoke callback, and if callback throws an exception, report the exception. - HTML::queue_a_microtask(document, GC::create_function(realm.heap(), [&callback, &realm] { - auto result = WebIDL::invoke_callback(callback, {}); - if (result.is_error()) - HTML::report_exception(result, realm); + // The queueMicrotask(callback) method must queue a microtask to invoke callback with « » and "report". + HTML::queue_a_microtask(document, GC::create_function(realm.heap(), [&callback] { + (void)WebIDL::invoke_callback(callback, {}, WebIDL::ExceptionBehavior::Report); })); } diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-canvas-element/toBlob-cross-realm-callback-report-exception.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-canvas-element/toBlob-cross-realm-callback-report-exception.txt new file mode 100644 index 00000000000..b03164168bb --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-canvas-element/toBlob-cross-realm-callback-report-exception.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass toBlob() reports the exception from its callback in the callback's global object \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.txt new file mode 100644 index 00000000000..1519c3376f6 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass queueMicrotask() 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/html/semantics/embedded-content/the-canvas-element/toBlob-cross-realm-callback-report-exception.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-canvas-element/toBlob-cross-realm-callback-report-exception.html new file mode 100644 index 00000000000..9e7faad6ff9 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-canvas-element/toBlob-cross-realm-callback-report-exception.html @@ -0,0 +1,29 @@ + + +toBlob() reports the exception from its callback in the callback's global object + + + + + + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.html new file mode 100644 index 00000000000..9c1113eab8a --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.html @@ -0,0 +1,28 @@ + + +queueMicrotask() reports the exception from its callback in the callback's global object + + + + + +