mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibWeb/HTML: Teach MessageEvent to work with origins
Corresponds to whatwg/html@748b068c7c Which fixes the Origin.from() handling for MessageEvent's.
This commit is contained in:
committed by
Shannon Booth
parent
fa1c046e68
commit
a0878ec057
Notes:
github-actions[bot]
2026-03-23 21:33:47 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/a0878ec0571 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8458
@@ -68,6 +68,24 @@ void MessageEvent::visit_edges(Cell::Visitor& visitor)
|
||||
[&](auto const& ref) { visitor.visit(ref); });
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/comms.html#dom-messageevent-origin
|
||||
String MessageEvent::origin() const
|
||||
{
|
||||
return m_origin.visit(
|
||||
// 1. If this's origin is an origin, then return the serialization of this's origin.
|
||||
[](URL::Origin const& origin) {
|
||||
return origin.serialize();
|
||||
},
|
||||
// 2. If this's origin is null, then return the empty string.
|
||||
[](Empty) {
|
||||
return String {};
|
||||
},
|
||||
// 3. Return this's origin.
|
||||
[](String const& origin) {
|
||||
return origin;
|
||||
});
|
||||
}
|
||||
|
||||
MessageEvent::SourceResult MessageEvent::source() const
|
||||
{
|
||||
return m_source.visit(
|
||||
@@ -119,8 +137,14 @@ void MessageEvent::init_message_event(String const& type, bool bubbles, bool can
|
||||
// https://html.spec.whatwg.org/multipage/comms.html#the-messageevent-interface:extract-an-origin
|
||||
Optional<URL::Origin> MessageEvent::extract_an_origin() const
|
||||
{
|
||||
// Objects implementing the MessageEvent interface's extract an origin steps are to return this's relevant settings object's origin.
|
||||
return relevant_settings_object(*this).origin();
|
||||
// Objects implementing the MessageEvent interface's extract an origin steps are to return this's origin if it is an origin; otherwise null.
|
||||
return m_origin.visit(
|
||||
[](URL::Origin const& origin) -> Optional<URL::Origin> {
|
||||
return origin;
|
||||
},
|
||||
[](auto const&) -> Optional<URL::Origin> {
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user