diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-01 18:16:12 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-01 20:14:45 +0200 |
commit | ded8e84f32cf937bf1115f2a8dd0d19db55e212a (patch) | |
tree | 5067aa93b2245fa30da73a8d37870078c7cc6d16 /Userland | |
parent | 7f551d7f6a7afc7496cece31126464813fb1aa28 (diff) | |
download | serenity-ded8e84f32cf937bf1115f2a8dd0d19db55e212a.zip |
LibWeb: Add the missing CloseEvent IDL constructor
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/CloseEvent.h | 26 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/CloseEvent.idl | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/WebSocket.cpp | 6 |
3 files changed, 31 insertions, 9 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/CloseEvent.h b/Userland/Libraries/LibWeb/HTML/CloseEvent.h index 9c0e71064b..3b7c56f2f7 100644 --- a/Userland/Libraries/LibWeb/HTML/CloseEvent.h +++ b/Userland/Libraries/LibWeb/HTML/CloseEvent.h @@ -10,27 +10,37 @@ namespace Web::HTML { +struct CloseEventInit : public DOM::EventInit { + bool was_clean { false }; + u16 code { 0 }; + String reason { "" }; +}; + class CloseEvent : public DOM::Event { public: using WrapperType = Bindings::CloseEventWrapper; - static NonnullRefPtr<CloseEvent> create(const FlyString& event_name, bool was_clean, u16 code, const String& reason) + static NonnullRefPtr<CloseEvent> create(FlyString const& event_name, CloseEventInit const& event_init = {}) + { + return adopt_ref(*new CloseEvent(event_name, event_init)); + } + static NonnullRefPtr<CloseEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, CloseEventInit const& event_init) { - return adopt_ref(*new CloseEvent(event_name, was_clean, code, reason)); + return CloseEvent::create(event_name, event_init); } virtual ~CloseEvent() override = default; - bool was_clean() { return m_was_clean; } + bool was_clean() const { return m_was_clean; } u16 code() const { return m_code; } String reason() const { return m_reason; } protected: - CloseEvent(const FlyString& event_name, bool was_clean, u16 code, const String& reason) - : Event(event_name) - , m_was_clean(was_clean) - , m_code(code) - , m_reason(reason) + CloseEvent(FlyString const& event_name, CloseEventInit const& event_init) + : Event(event_name, event_init) + , m_was_clean(event_init.was_clean) + , m_code(event_init.code) + , m_reason(event_init.reason) { } diff --git a/Userland/Libraries/LibWeb/HTML/CloseEvent.idl b/Userland/Libraries/LibWeb/HTML/CloseEvent.idl index bc2df5c1f8..7abf0cb6a4 100644 --- a/Userland/Libraries/LibWeb/HTML/CloseEvent.idl +++ b/Userland/Libraries/LibWeb/HTML/CloseEvent.idl @@ -1,7 +1,15 @@ +#import <DOM/Event.idl> + interface CloseEvent : Event { + constructor(DOMString type, optional CloseEventInit eventInitDict = {}); readonly attribute boolean wasClean; readonly attribute unsigned short code; readonly attribute USVString reason; +}; +dictionary CloseEventInit : EventInit { + boolean wasClean = false; + unsigned short code = 0; + USVString reason = ""; }; diff --git a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp b/Userland/Libraries/LibWeb/HTML/WebSocket.cpp index bd50c022ef..c5dfca9088 100644 --- a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp +++ b/Userland/Libraries/LibWeb/HTML/WebSocket.cpp @@ -189,7 +189,11 @@ void WebSocket::on_close(u16 code, String reason, bool was_clean) { // 1. Change the readyState attribute's value to CLOSED. This is handled by the Protocol's WebSocket // 2. If [needed], fire an event named error at the WebSocket object. This is handled by the Protocol's WebSocket - dispatch_event(CloseEvent::create(EventNames::close, was_clean, code, reason)); + CloseEventInit event_init {}; + event_init.was_clean = was_clean; + event_init.code = code; + event_init.reason = move(reason); + dispatch_event(CloseEvent::create(EventNames::close, event_init)); } // https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol |