mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Port MessageEvent to new String
This commit is contained in:
parent
84997ab0ee
commit
eed69e5093
Notes:
sideshowbarker
2024-07-17 16:42:19 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/eed69e5093 Pull-request: https://github.com/SerenityOS/serenity/pull/17722 Reviewed-by: https://github.com/linusg ✅
8 changed files with 26 additions and 25 deletions
|
@ -1298,7 +1298,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> 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, ""));
|
||||
|
|
|
@ -9,18 +9,18 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageEvent>> MessageEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, MessageEventInit const& event_init)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageEvent>> MessageEvent::create(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<MessageEvent>(realm, realm, event_name, event_init));
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageEvent>> MessageEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, MessageEventInit const& event_init)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageEvent>> 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)
|
||||
|
|
|
@ -7,37 +7,38 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
|
||||
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<JS::NonnullGCPtr<MessageEvent>> create(JS::Realm&, DeprecatedFlyString const& event_name, MessageEventInit const& event_init = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageEvent>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, MessageEventInit const& event_init);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageEvent>> create(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageEvent>> 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<void> 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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#import <DOM/Event.idl>
|
||||
|
||||
// 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 = {});
|
||||
|
||||
|
|
|
@ -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 = "<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 = "<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());
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -916,8 +916,8 @@ WebIDL::ExceptionOr<void> 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 = "<origin>";
|
||||
dispatch_event(HTML::MessageEvent::create(realm(), HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors());
|
||||
event_init.origin = "<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 {};
|
||||
}
|
||||
|
|
|
@ -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 = "<origin>";
|
||||
dispatch_event(MessageEvent::create(*m_worker_realm, HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors());
|
||||
event_init.origin = "<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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue