LibWeb: Establish WebSocket connections in parallel

This commit is contained in:
Andrew Kaster 2025-01-14 14:15:56 -07:00 committed by Andrew Kaster
commit a869a1c056
Notes: github-actions[bot] 2025-02-18 18:37:09 +00:00
2 changed files with 9 additions and 6 deletions

View file

@ -24,6 +24,7 @@
#include <LibWeb/HTML/MessageEvent.h> #include <LibWeb/HTML/MessageEvent.h>
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h> #include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
#include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/WebIDL/AbstractOperations.h> #include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/Buffers.h> #include <LibWeb/WebIDL/Buffers.h>
#include <LibWeb/WebIDL/DOMException.h> #include <LibWeb/WebIDL/DOMException.h>
@ -97,11 +98,13 @@ WebIDL::ExceptionOr<GC::Ref<WebSocket>> WebSocket::construct_impl(JS::Realm& rea
web_socket->set_url(*url_record); web_socket->set_url(*url_record);
// 11. Let client be thiss relevant settings object. // 11. Let client be thiss relevant settings object.
auto& client = relevant_settings_object; // 12. Run this step in parallel:
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(vm.heap(), [web_socket, url_record, protocols_sequence = move(protocols_sequence)]() {
auto& client = HTML::relevant_settings_object(*web_socket);
// FIXME: 12. Run this step in parallel: // 1. Establish a WebSocket connection given urlRecord, protocols, and client. [FETCH]
// 1. Establish a WebSocket connection given urlRecord, protocols, and client. [FETCH] (void)web_socket->establish_web_socket_connection(*url_record, protocols_sequence, client);
TRY_OR_THROW_OOM(vm, web_socket->establish_web_socket_connection(*url_record, protocols_sequence, client)); }));
return web_socket; return web_socket;
} }
@ -119,7 +122,7 @@ void WebSocket::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(WebSocket); WEB_SET_PROTOTYPE_FOR_INTERFACE(WebSocket);
} }
ErrorOr<void> WebSocket::establish_web_socket_connection(URL::URL& url_record, Vector<String>& protocols, HTML::EnvironmentSettingsObject& client) ErrorOr<void> WebSocket::establish_web_socket_connection(URL::URL const& url_record, Vector<String> const& protocols, HTML::EnvironmentSettingsObject& client)
{ {
// FIXME: Integrate properly with FETCH as per https://fetch.spec.whatwg.org/#websocket-opening-handshake // FIXME: Integrate properly with FETCH as per https://fetch.spec.whatwg.org/#websocket-opening-handshake

View file

@ -65,7 +65,7 @@ private:
virtual void initialize(JS::Realm&) override; virtual void initialize(JS::Realm&) override;
ErrorOr<void> establish_web_socket_connection(URL::URL& url_record, Vector<String>& protocols, HTML::EnvironmentSettingsObject& client); ErrorOr<void> establish_web_socket_connection(URL::URL const& url_record, Vector<String> const& protocols, HTML::EnvironmentSettingsObject& client);
URL::URL m_url; URL::URL m_url;
String m_binary_type { "blob"_string }; String m_binary_type { "blob"_string };