From c6a94fe5131bf182a9c8a32274f7b3cfd5826ff7 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 12 Jun 2025 07:56:37 -0400 Subject: [PATCH] LibWeb: Do not return a GC::Root from HTMLTrackElement's track getter There's no need to create a root each time the getter is called. We should also allocate it in the `initialize` overload rather than the constructor. --- Libraries/LibWeb/HTML/HTMLTrackElement.cpp | 3 ++- Libraries/LibWeb/HTML/HTMLTrackElement.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/HTML/HTMLTrackElement.cpp b/Libraries/LibWeb/HTML/HTMLTrackElement.cpp index d60d2b345d8..2f641a16294 100644 --- a/Libraries/LibWeb/HTML/HTMLTrackElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLTrackElement.cpp @@ -27,7 +27,6 @@ GC_DEFINE_ALLOCATOR(HTMLTrackElement); HTMLTrackElement::HTMLTrackElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - m_track = TextTrack::create(document.realm()); } HTMLTrackElement::~HTMLTrackElement() = default; @@ -36,6 +35,8 @@ void HTMLTrackElement::initialize(JS::Realm& realm) { WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTrackElement); Base::initialize(realm); + + m_track = TextTrack::create(realm); } void HTMLTrackElement::visit_edges(Cell::Visitor& visitor) diff --git a/Libraries/LibWeb/HTML/HTMLTrackElement.h b/Libraries/LibWeb/HTML/HTMLTrackElement.h index 80f8ae147af..49817d5a0eb 100644 --- a/Libraries/LibWeb/HTML/HTMLTrackElement.h +++ b/Libraries/LibWeb/HTML/HTMLTrackElement.h @@ -21,7 +21,7 @@ public: WebIDL::UnsignedShort ready_state(); - GC::Root track() { return m_track; } + GC::Ref track() { return *m_track; } private: HTMLTrackElement(DOM::Document&, DOM::QualifiedName);