From 6ac018bcb6d6698d6ecb0466461805cb8d4832c1 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Tue, 3 Dec 2024 03:05:15 +1300 Subject: [PATCH] LibWeb: Fix crash accessing 'empty' PromiseRejectionEvent reason The 'reason' was getting initialized to 'empty' state when not provided through the constructor, which results in a crash when accessed through throw_dom_exception_if_needed in the generated IDL getter. --- Libraries/LibWeb/HTML/PromiseRejectionEvent.h | 2 +- .../promise-rejection-event-constructor.txt | 11 ++++ .../promise-rejection-event-constructor.html | 50 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.html diff --git a/Libraries/LibWeb/HTML/PromiseRejectionEvent.h b/Libraries/LibWeb/HTML/PromiseRejectionEvent.h index adc253b2d7f..e6a1d46d47e 100644 --- a/Libraries/LibWeb/HTML/PromiseRejectionEvent.h +++ b/Libraries/LibWeb/HTML/PromiseRejectionEvent.h @@ -17,7 +17,7 @@ namespace Web::HTML { struct PromiseRejectionEventInit : public DOM::EventInit { GC::Root promise; - JS::Value reason; + JS::Value reason { JS::js_undefined() }; }; class PromiseRejectionEvent final : public DOM::Event { diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.txt new file mode 100644 index 00000000000..a7be1022606 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.txt @@ -0,0 +1,11 @@ +Summary + +Harness status: OK + +Rerun + +Found 1 tests + +1 Pass +Details +Result Test Name MessagePass This tests the constructor for the PromiseRejectionEvent DOM class. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.html new file mode 100644 index 00000000000..50186871138 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.html @@ -0,0 +1,50 @@ + + + + + +