mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:48:13 +00:00
LibWeb: Add the missing CloseEvent IDL constructor
This commit is contained in:
parent
7f551d7f6a
commit
ded8e84f32
3 changed files with 32 additions and 10 deletions
|
@ -10,27 +10,37 @@
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
struct CloseEventInit : public DOM::EventInit {
|
||||||
|
bool was_clean { false };
|
||||||
|
u16 code { 0 };
|
||||||
|
String reason { "" };
|
||||||
|
};
|
||||||
|
|
||||||
class CloseEvent : public DOM::Event {
|
class CloseEvent : public DOM::Event {
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::CloseEventWrapper;
|
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, was_clean, code, reason));
|
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 CloseEvent::create(event_name, event_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~CloseEvent() override = default;
|
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; }
|
u16 code() const { return m_code; }
|
||||||
String reason() const { return m_reason; }
|
String reason() const { return m_reason; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CloseEvent(const FlyString& event_name, bool was_clean, u16 code, const String& reason)
|
CloseEvent(FlyString const& event_name, CloseEventInit const& event_init)
|
||||||
: Event(event_name)
|
: Event(event_name, event_init)
|
||||||
, m_was_clean(was_clean)
|
, m_was_clean(event_init.was_clean)
|
||||||
, m_code(code)
|
, m_code(event_init.code)
|
||||||
, m_reason(reason)
|
, m_reason(event_init.reason)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
|
#import <DOM/Event.idl>
|
||||||
|
|
||||||
interface CloseEvent : Event {
|
interface CloseEvent : Event {
|
||||||
|
constructor(DOMString type, optional CloseEventInit eventInitDict = {});
|
||||||
|
|
||||||
readonly attribute boolean wasClean;
|
readonly attribute boolean wasClean;
|
||||||
readonly attribute unsigned short code;
|
readonly attribute unsigned short code;
|
||||||
readonly attribute USVString reason;
|
readonly attribute USVString reason;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary CloseEventInit : EventInit {
|
||||||
|
boolean wasClean = false;
|
||||||
|
unsigned short code = 0;
|
||||||
|
USVString reason = "";
|
||||||
};
|
};
|
||||||
|
|
|
@ -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
|
// 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
|
// 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
|
// https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue