Skip to content

Commit 048b51e

Browse files
trflynn89gmta
authored andcommitted
WebContent: Add a JS visitor to WebDriver's IPC connection
We've added a few JS::Handle members to this class over time. Let's avoid creating a new GC root for each of these, and explicitly add a visitation method.
1 parent 022e2b8 commit 048b51e

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Userland/Services/WebContent/PageClient.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ void PageClient::visit_edges(JS::Cell::Visitor& visitor)
7777
{
7878
Base::visit_edges(visitor);
7979
visitor.visit(m_page);
80+
81+
if (m_webdriver)
82+
m_webdriver->visit_edges(visitor);
8083
}
8184

8285
ConnectionFromClient& PageClient::client() const

Userland/Services/WebContent/WebDriverConnection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ WebDriverConnection::WebDriverConnection(NonnullOwnPtr<Core::LocalSocket> socket
199199
set_current_top_level_browsing_context(page_client.page().top_level_browsing_context());
200200
}
201201

202+
void WebDriverConnection::visit_edges(JS::Cell::Visitor& visitor)
203+
{
204+
visitor.visit(m_current_browsing_context);
205+
visitor.visit(m_current_parent_browsing_context);
206+
visitor.visit(m_current_top_level_browsing_context);
207+
visitor.visit(m_action_executor);
208+
}
209+
202210
// https://w3c.github.io/webdriver/#dfn-close-the-session
203211
void WebDriverConnection::close_session()
204212
{

Userland/Services/WebContent/WebDriverConnection.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class WebDriverConnection final
3434
static ErrorOr<NonnullRefPtr<WebDriverConnection>> connect(Web::PageClient& page_client, ByteString const& webdriver_ipc_path);
3535
virtual ~WebDriverConnection() = default;
3636

37+
void visit_edges(JS::Cell::Visitor&);
38+
3739
private:
3840
WebDriverConnection(NonnullOwnPtr<Core::LocalSocket> socket, Web::PageClient& page_client);
3941

@@ -106,10 +108,10 @@ class WebDriverConnection final
106108

107109
void set_current_browsing_context(Web::HTML::BrowsingContext&);
108110
Web::HTML::BrowsingContext& current_browsing_context() { return *m_current_browsing_context; }
109-
JS::GCPtr<Web::HTML::BrowsingContext> current_parent_browsing_context() { return m_current_parent_browsing_context.ptr(); }
111+
JS::GCPtr<Web::HTML::BrowsingContext> current_parent_browsing_context() { return m_current_parent_browsing_context; }
110112

111113
void set_current_top_level_browsing_context(Web::HTML::BrowsingContext&);
112-
JS::GCPtr<Web::HTML::BrowsingContext> current_top_level_browsing_context() { return m_current_top_level_browsing_context.ptr(); }
114+
JS::GCPtr<Web::HTML::BrowsingContext> current_top_level_browsing_context() { return m_current_top_level_browsing_context; }
113115

114116
ErrorOr<void, Web::WebDriver::Error> ensure_current_browsing_context_is_open();
115117
ErrorOr<void, Web::WebDriver::Error> ensure_current_top_level_browsing_context_is_open();
@@ -147,15 +149,15 @@ class WebDriverConnection final
147149
Web::WebDriver::TimeoutsConfiguration m_timeouts_configuration;
148150

149151
// https://w3c.github.io/webdriver/#dfn-current-browsing-context
150-
JS::Handle<Web::HTML::BrowsingContext> m_current_browsing_context;
152+
JS::GCPtr<Web::HTML::BrowsingContext> m_current_browsing_context;
151153

152154
// https://w3c.github.io/webdriver/#dfn-current-parent-browsing-context
153-
JS::Handle<Web::HTML::BrowsingContext> m_current_parent_browsing_context;
155+
JS::GCPtr<Web::HTML::BrowsingContext> m_current_parent_browsing_context;
154156

155157
// https://w3c.github.io/webdriver/#dfn-current-top-level-browsing-context
156-
JS::Handle<Web::HTML::BrowsingContext> m_current_top_level_browsing_context;
158+
JS::GCPtr<Web::HTML::BrowsingContext> m_current_top_level_browsing_context;
157159

158-
JS::Handle<JS::Cell> m_action_executor;
160+
JS::GCPtr<JS::Cell> m_action_executor;
159161
};
160162

161163
}

0 commit comments

Comments
 (0)