diff --git a/Libraries/LibWeb/Gamepad/GamepadEvent.cpp b/Libraries/LibWeb/Gamepad/GamepadEvent.cpp index e9ef15dcea..f0efc8f103 100644 --- a/Libraries/LibWeb/Gamepad/GamepadEvent.cpp +++ b/Libraries/LibWeb/Gamepad/GamepadEvent.cpp @@ -20,7 +20,7 @@ WebIDL::ExceptionOr> GamepadEvent::construct_impl(JS::Real GamepadEvent::GamepadEvent(JS::Realm& realm, FlyString const& event_name, GamepadEventInit const& event_init) : DOM::Event(realm, event_name, event_init) - , m_gamepad(*event_init.gamepad) + , m_gamepad(event_init.gamepad.has_value() ? event_init.gamepad->ptr() : nullptr) { } diff --git a/Libraries/LibWeb/Gamepad/GamepadEvent.h b/Libraries/LibWeb/Gamepad/GamepadEvent.h index 5f6ca6abbb..2abdb2ab16 100644 --- a/Libraries/LibWeb/Gamepad/GamepadEvent.h +++ b/Libraries/LibWeb/Gamepad/GamepadEvent.h @@ -11,7 +11,7 @@ namespace Web::Gamepad { struct GamepadEventInit : public DOM::EventInit { - GC::Root gamepad; + Optional> gamepad; }; class GamepadEvent final : public DOM::Event { @@ -19,18 +19,18 @@ class GamepadEvent final : public DOM::Event { GC_DECLARE_ALLOCATOR(GamepadEvent); public: - [[nodiscard]] static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& event_name, GamepadEventInit const&); + [[nodiscard]] static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& event_name, GamepadEventInit const& = {}); virtual ~GamepadEvent() override; - GC::Ref gamepad() const { return m_gamepad; } + GC::Ptr gamepad() const { return m_gamepad; } private: GamepadEvent(JS::Realm&, FlyString const& event_name, GamepadEventInit const& event_init); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; - GC::Ref m_gamepad; + GC::Ptr m_gamepad; }; } diff --git a/Libraries/LibWeb/Gamepad/GamepadEvent.idl b/Libraries/LibWeb/Gamepad/GamepadEvent.idl index 1ef43b4069..888e30a562 100644 --- a/Libraries/LibWeb/Gamepad/GamepadEvent.idl +++ b/Libraries/LibWeb/Gamepad/GamepadEvent.idl @@ -4,11 +4,15 @@ // https://w3c.github.io/gamepad/#dom-gamepadevent [Exposed=Window] interface GamepadEvent : Event { - constructor(DOMString type, GamepadEventInit eventInitDict); - [SameObject] readonly attribute Gamepad gamepad; + // eventInitDict is not marked as optional in the specification, but existing implementations treat it as optional. + // See: https://github.com/w3c/gamepad/pull/217 + constructor(DOMString type, optional GamepadEventInit eventInitDict = {}); + [SameObject] readonly attribute Gamepad? gamepad; }; // https://w3c.github.io/gamepad/#dom-gamepadeventinit dictionary GamepadEventInit : EventInit { - required Gamepad gamepad; + // This is marked as required in the specification, but existing implementations treat it as optional. + // See: https://github.com/w3c/gamepad/pull/217 + Gamepad? gamepad = null; }; diff --git a/Tests/LibWeb/Text/expected/wpt-import/dom/events/Event-timestamp-high-resolution.https.txt b/Tests/LibWeb/Text/expected/wpt-import/dom/events/Event-timestamp-high-resolution.https.txt index 6775686423..9456632bed 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/dom/events/Event-timestamp-high-resolution.https.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/dom/events/Event-timestamp-high-resolution.https.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail Constructed GamepadEvent timestamp should be high resolution and have the same time origin as performance.now() \ No newline at end of file +1 Pass +Pass Constructed GamepadEvent timestamp should be high resolution and have the same time origin as performance.now() \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/gamepad/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/gamepad/idlharness.window.txt index c7cb54cf61..3cabe95b4b 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/gamepad/idlharness.window.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/gamepad/idlharness.window.txt @@ -2,8 +2,8 @@ Harness status: OK Found 85 tests -81 Pass -4 Fail +83 Pass +2 Fail Pass idl_test setup Pass idl_test validation Pass Partial interface Navigator: original interface defined @@ -72,15 +72,15 @@ Pass GamepadHapticActuator interface: attribute effects Pass GamepadHapticActuator interface: operation playEffect(GamepadHapticEffectType, optional GamepadEffectParameters) Pass GamepadHapticActuator interface: operation reset() Pass GamepadEvent interface: existence and properties of interface object -Pass GamepadEvent interface object length +Fail GamepadEvent interface object length Pass GamepadEvent interface object name Pass GamepadEvent interface: existence and properties of interface prototype object Pass GamepadEvent interface: existence and properties of interface prototype object's "constructor" property Pass GamepadEvent interface: existence and properties of interface prototype object's @@unscopables property Pass GamepadEvent interface: attribute gamepad -Fail GamepadEvent must be primary interface of new GamepadEvent("gamepad") -Fail Stringification of new GamepadEvent("gamepad") -Fail GamepadEvent interface: new GamepadEvent("gamepad") must inherit property "gamepad" with the proper type +Pass GamepadEvent must be primary interface of new GamepadEvent("gamepad") +Pass Stringification of new GamepadEvent("gamepad") +Pass GamepadEvent interface: new GamepadEvent("gamepad") must inherit property "gamepad" with the proper type Pass HTMLBodyElement interface: attribute ongamepadconnected Pass HTMLBodyElement interface: attribute ongamepaddisconnected Pass Window interface: attribute ongamepadconnected