mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb: Make eventInitDict GamepadEvent constructor parameter optional
This differs from the specification but matches the behavior of existing implementations.
This commit is contained in:
parent
5df91dc761
commit
9c204f36ec
Notes:
github-actions[bot]
2025-09-23 15:06:29 +00:00
Author: https://github.com/tcl3
Commit: 9c204f36ec
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6050
5 changed files with 20 additions and 16 deletions
|
|
@ -20,7 +20,7 @@ WebIDL::ExceptionOr<GC::Ref<GamepadEvent>> 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
namespace Web::Gamepad {
|
||||
|
||||
struct GamepadEventInit : public DOM::EventInit {
|
||||
GC::Root<Gamepad> gamepad;
|
||||
Optional<GC::Root<Gamepad>> 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<GC::Ref<GamepadEvent>> construct_impl(JS::Realm&, FlyString const& event_name, GamepadEventInit const&);
|
||||
[[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<GamepadEvent>> construct_impl(JS::Realm&, FlyString const& event_name, GamepadEventInit const& = {});
|
||||
|
||||
virtual ~GamepadEvent() override;
|
||||
|
||||
GC::Ref<Gamepad> gamepad() const { return m_gamepad; }
|
||||
GC::Ptr<Gamepad> 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<Gamepad> m_gamepad;
|
||||
GC::Ptr<Gamepad> m_gamepad;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue