From b309640ab0fdea21cd3af5db14e8d0382d67bedf Mon Sep 17 00:00:00 2001 From: Francis Bouvier Date: Fri, 10 Jul 2026 19:38:30 +0200 Subject: [PATCH] webapi: fix UIEvent.view default, initCustomEvent guard, KeyboardEvent flags Fixes 4 failing tests in WPT /dom/events/Event-init-while-dispatching.html (1/5 -> 5/5), and as a side effect most of Event-subclasses-constructors.html (16/49 -> 46/49). Three distinct bugs, all about synthetic (constructor-created) events not following the spec's dictionary defaults: - UIEvent.view defaulted to the window: the constructor stored `opts.view orelse frame.window` and the getter fell back to the window too, so `new UIEvent("x").view` was never null. Per UIEventInit, view defaults to null. The window fallback is kept for *trusted* (browser-generated) UI events only, which do target the window, so internal dispatch call sites stay unchanged. - initCustomEvent was missing the "short-circuit while dispatching" guard that initEvent and the other legacy initializers have. - KeyboardEvent's constructor unconditionally forced bubbles, cancelable and composed to true (correct only for trusted key events per UI Events); synthetic KeyboardEvents now follow the EventInit defaults. The unit tests asserting the old view-defaults-to-window behavior are updated to expect null. Coverage: /dom/events/Event-init-while-dispatching.html 1/5 -> 5/5, /dom/events/Event-subclasses-constructors.html 16/49 -> 46/49. No regressions across /dom/events. Co-Authored-By: Claude Fable 5 --- src/browser/tests/event/composition.html | 3 ++- src/browser/tests/event/ui.html | 4 ++-- src/browser/webapi/event/CustomEvent.zig | 5 +++++ src/browser/webapi/event/KeyboardEvent.zig | 14 +++++++++----- src/browser/webapi/event/UIEvent.zig | 14 +++++++++++--- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/browser/tests/event/composition.html b/src/browser/tests/event/composition.html index e96023358..91c76d227 100644 --- a/src/browser/tests/event/composition.html +++ b/src/browser/tests/event/composition.html @@ -11,7 +11,8 @@ testing.expectEqual("test", event.type); testing.expectEqual("", event.data); testing.expectEqual(0, event.detail); - testing.expectEqual(window, event.view); + // per UIEventInit, view defaults to null for synthetic events + testing.expectEqual(null, event.view); } diff --git a/src/browser/tests/event/ui.html b/src/browser/tests/event/ui.html index f060622a8..9c041fe4f 100644 --- a/src/browser/tests/event/ui.html +++ b/src/browser/tests/event/ui.html @@ -11,7 +11,7 @@ testing.expectEqual(5, evt.detail); testing.expectEqual(true, evt.bubbles); testing.expectEqual(true, evt.cancelable); - testing.expectEqual(window, evt.view); + testing.expectEqual(null, evt.view);