From 1975640e31c50e9d20b0d307cbe67df4dcb8e36a Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Fri, 30 Aug 2024 09:39:07 +0900 Subject: [PATCH] =?UTF-8?q?LibWeb:=20Make=20=E2=80=9Ccreate=20an=20event?= =?UTF-8?q?=E2=80=9D=20set=20the=20event=E2=80=99s=20isTrusted=20to=20true?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change ensures that when then the code corresponding to the “create an event” operation at https://dom.spec.whatwg.org/#concept-event-create is called, the event’s isTrusted is set to true — as the spec requires. That causes the failures for the following WPT tests to pass: - https://wpt.fyi/results/html/semantics/forms/the-input-element/checkbox.html?run_id=5080423051034624 - https://wpt.fyi/results/html/semantics/interactive-elements/the-dialog-element/dialog-close.html?run_id=5080423051034624 …and there are likely a number of similar WPT tests that hit this same code path which this commit will cause to be changed to passes. Otherwise, without this change, the “create event” implementation doesn’t conform to the spec requirements – nor behave interoperably with other existing engines — and those WPT test would continue to fail. This change also ensures that isTrusted continues to be set to false for synthetic events. --- .../synthetic-event-constructor-istrusted-check.txt | 1 + .../synthetic-event-constructor-istrusted-check.html | 6 ++++++ Userland/Libraries/LibWeb/DOM/Event.cpp | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/synthetic-event-constructor-istrusted-check.txt create mode 100644 Tests/LibWeb/Text/input/synthetic-event-constructor-istrusted-check.html diff --git a/Tests/LibWeb/Text/expected/synthetic-event-constructor-istrusted-check.txt b/Tests/LibWeb/Text/expected/synthetic-event-constructor-istrusted-check.txt new file mode 100644 index 00000000000..b4b47ef2487 --- /dev/null +++ b/Tests/LibWeb/Text/expected/synthetic-event-constructor-istrusted-check.txt @@ -0,0 +1 @@ +new Event('x').isTrusted is false diff --git a/Tests/LibWeb/Text/input/synthetic-event-constructor-istrusted-check.html b/Tests/LibWeb/Text/input/synthetic-event-constructor-istrusted-check.html new file mode 100644 index 00000000000..6af2c485cb4 --- /dev/null +++ b/Tests/LibWeb/Text/input/synthetic-event-constructor-istrusted-check.html @@ -0,0 +1,6 @@ + + diff --git a/Userland/Libraries/LibWeb/DOM/Event.cpp b/Userland/Libraries/LibWeb/DOM/Event.cpp index 98614230812..42edf0008c1 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.cpp +++ b/Userland/Libraries/LibWeb/DOM/Event.cpp @@ -18,14 +18,18 @@ namespace Web::DOM { JS_DEFINE_ALLOCATOR(Event); +// https://dom.spec.whatwg.org/#concept-event-create JS::NonnullGCPtr Event::create(JS::Realm& realm, FlyString const& event_name, EventInit const& event_init) { - return realm.heap().allocate(realm, realm, event_name, event_init); + auto event = realm.heap().allocate(realm, realm, event_name, event_init); + // 4. Initialize event’s isTrusted attribute to true. + event->m_is_trusted = true; + return event; } WebIDL::ExceptionOr> Event::construct_impl(JS::Realm& realm, FlyString const& event_name, EventInit const& event_init) { - return create(realm, event_name, event_init); + return realm.heap().allocate(realm, realm, event_name, event_init); } // https://dom.spec.whatwg.org/#inner-event-creation-steps