2021-09-19 22:12:31 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2021-2022, Andreas Kling <andreas@ladybird.org>
|
2021-09-19 22:12:31 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2022-09-25 16:38:21 -06:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/MessageChannelPrototype.h>
|
2021-09-19 22:12:31 +02:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
#include <LibWeb/HTML/MessageChannel.h>
|
|
|
|
#include <LibWeb/HTML/MessagePort.h>
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(MessageChannel);
|
2023-11-19 19:47:52 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<MessageChannel>> MessageChannel::construct_impl(JS::Realm& realm)
|
2022-09-01 20:59:51 +02:00
|
|
|
{
|
2024-11-14 05:50:17 +13:00
|
|
|
return realm.create<MessageChannel>(realm);
|
2022-09-01 20:59:51 +02:00
|
|
|
}
|
|
|
|
|
2022-09-25 16:38:21 -06:00
|
|
|
MessageChannel::MessageChannel(JS::Realm& realm)
|
|
|
|
: PlatformObject(realm)
|
2021-09-19 22:12:31 +02:00
|
|
|
{
|
|
|
|
// 1. Set this's port 1 to a new MessagePort in this's relevant Realm.
|
2023-08-13 13:05:26 +02:00
|
|
|
m_port1 = MessagePort::create(realm);
|
2021-09-19 22:12:31 +02:00
|
|
|
|
|
|
|
// 2. Set this's port 2 to a new MessagePort in this's relevant Realm.
|
2023-08-13 13:05:26 +02:00
|
|
|
m_port2 = MessagePort::create(realm);
|
2021-09-19 22:12:31 +02:00
|
|
|
|
|
|
|
// 3. Entangle this's port 1 and this's port 2.
|
2022-02-17 13:31:09 +01:00
|
|
|
m_port1->entangle_with(*m_port2);
|
2021-09-19 22:12:31 +02:00
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
MessageChannel::~MessageChannel() = default;
|
2021-09-19 22:12:31 +02:00
|
|
|
|
2022-09-01 20:59:51 +02:00
|
|
|
void MessageChannel::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
2023-11-19 16:18:00 +13:00
|
|
|
visitor.visit(m_port1);
|
|
|
|
visitor.visit(m_port2);
|
2022-09-01 20:59:51 +02:00
|
|
|
}
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void MessageChannel::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(MessageChannel);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
MessagePort* MessageChannel::port1()
|
|
|
|
{
|
|
|
|
return m_port1;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessagePort* MessageChannel::port2()
|
|
|
|
{
|
|
|
|
return m_port2;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessagePort const* MessageChannel::port1() const
|
|
|
|
{
|
|
|
|
return m_port1;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessagePort const* MessageChannel::port2() const
|
|
|
|
{
|
|
|
|
return m_port2;
|
|
|
|
}
|
|
|
|
|
2021-09-19 22:12:31 +02:00
|
|
|
}
|