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