From eed69e5093011aad0663a705c982302180dd0c64 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sun, 5 Mar 2023 10:33:56 +0100 Subject: [PATCH] LibWeb: Port MessageEvent to new String --- Userland/Libraries/LibWeb/DOM/Document.cpp | 2 +- .../Libraries/LibWeb/HTML/MessageEvent.cpp | 8 ++++---- Userland/Libraries/LibWeb/HTML/MessageEvent.h | 19 ++++++++++--------- .../Libraries/LibWeb/HTML/MessageEvent.idl | 2 +- .../Libraries/LibWeb/HTML/MessagePort.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/Window.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/Worker.cpp | 4 ++-- .../Libraries/LibWeb/WebSockets/WebSocket.cpp | 8 ++++---- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 266681570da..8db5a31feb2 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1298,7 +1298,7 @@ WebIDL::ExceptionOr> Document::create_event(DeprecatedSt } else if (Infra::is_ascii_case_insensitive_match(interface, "keyboardevent"sv)) { event = TRY(UIEvents::KeyboardEvent::create(realm, "")); } else if (Infra::is_ascii_case_insensitive_match(interface, "messageevent"sv)) { - event = TRY(HTML::MessageEvent::create(realm, "")); + event = TRY(HTML::MessageEvent::create(realm, String {})); } else if (Infra::is_ascii_case_insensitive_match(interface, "mouseevent"sv) || Infra::is_ascii_case_insensitive_match(interface, "mouseevents"sv)) { event = TRY(UIEvents::MouseEvent::create(realm, "")); diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp b/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp index 639cad228af..af331ebe3d5 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp @@ -9,18 +9,18 @@ namespace Web::HTML { -WebIDL::ExceptionOr> MessageEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, MessageEventInit const& event_init) +WebIDL::ExceptionOr> MessageEvent::create(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init) { return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, event_name, event_init)); } -WebIDL::ExceptionOr> MessageEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, MessageEventInit const& event_init) +WebIDL::ExceptionOr> MessageEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init) { return create(realm, event_name, event_init); } -MessageEvent::MessageEvent(JS::Realm& realm, DeprecatedFlyString const& event_name, MessageEventInit const& event_init) - : DOM::Event(realm, event_name, event_init) +MessageEvent::MessageEvent(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init) + : DOM::Event(realm, event_name.to_deprecated_fly_string(), event_init) , m_data(event_init.data) , m_origin(event_init.origin) , m_last_event_id(event_init.last_event_id) diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.h b/Userland/Libraries/LibWeb/HTML/MessageEvent.h index 838f25bbb66..fe824ae5b68 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageEvent.h +++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.h @@ -7,37 +7,38 @@ #pragma once +#include #include namespace Web::HTML { struct MessageEventInit : public DOM::EventInit { JS::Value data { JS::js_null() }; - DeprecatedString origin { "" }; - DeprecatedString last_event_id { "" }; + String origin; + String last_event_id; }; class MessageEvent : public DOM::Event { WEB_PLATFORM_OBJECT(MessageEvent, DOM::Event); public: - static WebIDL::ExceptionOr> create(JS::Realm&, DeprecatedFlyString const& event_name, MessageEventInit const& event_init = {}); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, MessageEventInit const& event_init); + static WebIDL::ExceptionOr> create(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init = {}); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init); - MessageEvent(JS::Realm&, DeprecatedFlyString const& event_name, MessageEventInit const& event_init); + MessageEvent(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init); virtual ~MessageEvent() override; JS::Value data() const { return m_data; } - DeprecatedString const& origin() const { return m_origin; } - DeprecatedString const& last_event_id() const { return m_last_event_id; } + String const& origin() const { return m_origin; } + String const& last_event_id() const { return m_last_event_id; } private: virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; JS::Value m_data; - DeprecatedString m_origin; - DeprecatedString m_last_event_id; + String m_origin; + String m_last_event_id; }; } diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.idl b/Userland/Libraries/LibWeb/HTML/MessageEvent.idl index f394f7b6d2d..443635b5da8 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageEvent.idl +++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.idl @@ -1,7 +1,7 @@ #import // https://html.spec.whatwg.org/multipage/comms.html#messageevent -[Exposed=(Window,Worker)] +[Exposed=(Window,Worker), UseNewAKString] interface MessageEvent : Event { constructor(DOMString type, optional MessageEventInit eventInitDict = {}); diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp index df8a526599e..a32f9e3b11c 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp @@ -98,8 +98,8 @@ void MessagePort::post_message(JS::Value message) main_thread_event_loop().task_queue().add(HTML::Task::create(HTML::Task::Source::PostedMessage, nullptr, [target_port, message] { MessageEventInit event_init {}; event_init.data = message; - event_init.origin = ""; - target_port->dispatch_event(MessageEvent::create(target_port->realm(), HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors()); + event_init.origin = ""_string.release_value_but_fixme_should_propagate_errors(); + target_port->dispatch_event(MessageEvent::create(target_port->realm(), String::from_deprecated_string(HTML::EventNames::message).release_value_but_fixme_should_propagate_errors(), event_init).release_value_but_fixme_should_propagate_errors()); })); } diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index b3c56fc3640..c073cdf0c9e 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -916,8 +916,8 @@ WebIDL::ExceptionOr Window::post_message_impl(JS::Value message, Deprecate HTML::queue_global_task(HTML::Task::Source::PostedMessage, *this, [this, message] { HTML::MessageEventInit event_init {}; event_init.data = message; - event_init.origin = ""; - dispatch_event(HTML::MessageEvent::create(realm(), HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors()); + event_init.origin = ""_string.release_value_but_fixme_should_propagate_errors(); + dispatch_event(HTML::MessageEvent::create(realm(), String::from_deprecated_string(HTML::EventNames::message).release_value_but_fixme_should_propagate_errors(), event_init).release_value_but_fixme_should_propagate_errors()); }); return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/Worker.cpp b/Userland/Libraries/LibWeb/HTML/Worker.cpp index e7ccf279002..27bf5fee1bd 100644 --- a/Userland/Libraries/LibWeb/HTML/Worker.cpp +++ b/Userland/Libraries/LibWeb/HTML/Worker.cpp @@ -165,8 +165,8 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti event_loop.task_queue().add(HTML::Task::create(HTML::Task::Source::PostedMessage, nullptr, [this, message] { MessageEventInit event_init {}; event_init.data = message; - event_init.origin = ""; - dispatch_event(MessageEvent::create(*m_worker_realm, HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors()); + event_init.origin = ""_string.release_value_but_fixme_should_propagate_errors(); + dispatch_event(MessageEvent::create(*m_worker_realm, String::from_deprecated_string(HTML::EventNames::message).release_value_but_fixme_should_propagate_errors(), event_init).release_value_but_fixme_should_propagate_errors()); })); return JS::js_undefined(); diff --git a/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp index 07b7d6c78ed..275116fae6e 100644 --- a/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp +++ b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp @@ -234,8 +234,8 @@ void WebSocket::on_message(ByteBuffer message, bool is_text) auto text_message = DeprecatedString(ReadonlyBytes(message)); HTML::MessageEventInit event_init; event_init.data = JS::PrimitiveString::create(vm(), text_message); - event_init.origin = url(); - dispatch_event(HTML::MessageEvent::create(realm(), HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors()); + event_init.origin = String::from_deprecated_string(url()).release_value_but_fixme_should_propagate_errors(); + dispatch_event(HTML::MessageEvent::create(realm(), String::from_deprecated_string(HTML::EventNames::message).release_value_but_fixme_should_propagate_errors(), event_init).release_value_but_fixme_should_propagate_errors()); return; } @@ -246,8 +246,8 @@ void WebSocket::on_message(ByteBuffer message, bool is_text) // type indicates that the data is Binary and binaryType is "arraybuffer" HTML::MessageEventInit event_init; event_init.data = JS::ArrayBuffer::create(realm(), message); - event_init.origin = url(); - dispatch_event(HTML::MessageEvent::create(realm(), HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors()); + event_init.origin = String::from_deprecated_string(url()).release_value_but_fixme_should_propagate_errors(); + dispatch_event(HTML::MessageEvent::create(realm(), String::from_deprecated_string(HTML::EventNames::message).release_value_but_fixme_should_propagate_errors(), event_init).release_value_but_fixme_should_propagate_errors()); return; }