1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:48:13 +00:00

LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated

This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
This commit is contained in:
Andreas Kling 2022-08-28 13:42:07 +02:00
parent bb547ce1c4
commit 6f433c8656
445 changed files with 4797 additions and 4268 deletions

View file

@ -19,29 +19,14 @@ namespace Web::HTML {
E(onmessageerror, HTML::EventNames::messageerror)
// https://html.spec.whatwg.org/multipage/web-messaging.html#message-ports
class MessagePort final
: public RefCounted<MessagePort>
, public Weakable<MessagePort>
, public DOM::EventTarget
, public Bindings::Wrappable {
class MessagePort final : public DOM::EventTarget {
WEB_PLATFORM_OBJECT(MessagePort, DOM::EventTarget);
public:
using WrapperType = Bindings::MessagePortWrapper;
using RefCounted::ref;
using RefCounted::unref;
static NonnullRefPtr<MessagePort> create()
{
return adopt_ref(*new MessagePort());
}
static JS::NonnullGCPtr<MessagePort> create(HTML::Window&);
virtual ~MessagePort() override;
// ^EventTarget
virtual void ref_event_target() override { ref(); }
virtual void unref_event_target() override { unref(); }
virtual JS::Object* create_wrapper(JS::Realm&) override;
// https://html.spec.whatwg.org/multipage/web-messaging.html#entangle
void entangle_with(MessagePort&);
@ -60,13 +45,15 @@ public:
#undef __ENUMERATE
private:
MessagePort();
explicit MessagePort(HTML::Window&);
virtual void visit_edges(Cell::Visitor&) override;
bool is_entangled() const { return m_remote_port; }
void disentangle();
// The HTML spec implies(!) that this is MessagePort.[[RemotePort]]
WeakPtr<MessagePort> m_remote_port;
JS::GCPtr<MessagePort> m_remote_port;
// https://html.spec.whatwg.org/multipage/web-messaging.html#has-been-shipped
bool m_has_been_shipped { false };
@ -76,3 +63,5 @@ private:
};
}
WRAPPER_HACK(MessagePort, Web::HTML)