LibDevTools: Implement a real actor for DOM nodes

The DevTools client will now send requests to the node actor, rather
than just sending messages to other actors on the node's behalf.

This exposed a slight issue in the way we assign actor IDs. Node actors
are created in the walker actor constructor, which executes before the
actor ID is incremented. So we must be sure to increment the actor ID
before invoking any actor constructors. Otherwise, the walker actor and
the first node actor have the same numeric ID.
This commit is contained in:
Timothy Flynn 2025-02-21 15:19:35 -05:00 committed by Tim Flynn
commit c56bf8ac93
Notes: github-actions[bot] 2025-02-24 17:06:54 +00:00
7 changed files with 83 additions and 6 deletions

View file

@ -6,8 +6,10 @@
#include <AK/JsonArray.h>
#include <AK/StringUtils.h>
#include <LibDevTools/Actors/NodeActor.h>
#include <LibDevTools/Actors/TabActor.h>
#include <LibDevTools/Actors/WalkerActor.h>
#include <LibDevTools/DevToolsServer.h>
#include <LibWeb/DOM/NodeType.h>
namespace DevTools {
@ -276,11 +278,12 @@ Optional<JsonObject const&> WalkerActor::find_node_by_selector(JsonObject const&
void WalkerActor::populate_dom_tree_cache(JsonObject& node, JsonObject const* parent)
{
auto& node_actor = devtools().register_actor<NodeActor>(*this);
m_dom_node_to_parent_map.set(&node, parent);
auto actor = MUST(String::formatted("{}-node{}", name(), m_dom_node_count++));
m_actor_to_dom_node_map.set(actor, &node);
node.set("actor"sv, actor);
m_actor_to_dom_node_map.set(node_actor.name(), &node);
node.set("actor"sv, node_actor.name());
auto children = node.get_array("children"sv);
if (!children.has_value())