From fe7180bc74ac0ea9d2ec91f8446c1780d21c5973 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 18 Aug 2022 23:49:14 -0700 Subject: Synchronously dispatch `close` event --- src/bun.js/bindings/webcore/WebSocket.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/bun.js') diff --git a/src/bun.js/bindings/webcore/WebSocket.cpp b/src/bun.js/bindings/webcore/WebSocket.cpp index 004b907b5..4cfe39f95 100644 --- a/src/bun.js/bindings/webcore/WebSocket.cpp +++ b/src/bun.js/bindings/webcore/WebSocket.cpp @@ -880,6 +880,11 @@ void WebSocket::didClose(unsigned unhandledBufferedAmount, unsigned short code, this->m_connectedWebSocketKind = ConnectedWebSocketKind::None; this->m_upgradeClient = nullptr; + if (this->hasEventListeners("close"_s)) { + this->dispatchEvent(CloseEvent::create(wasClean, code, reason)); + return; + } + if (auto* context = scriptExecutionContext()) { this->m_pendingActivityCount++; context->postTask([this, code, wasClean, reason, protectedThis = Ref { *this }](ScriptExecutionContext& context) { -- cgit v1.2.3