LibDevTools: Automatically set the "from" field for server responses

The "from" field is required in every response. It is the name of the
actor sending the message. This patch fills in the "from" field in the
Actor base class so that subclasses don't have to.
This commit is contained in:
Timothy Flynn 2025-03-11 08:15:23 -04:00 committed by Tim Flynn
commit 4ce10f3bf4
Notes: github-actions[bot] 2025-03-12 16:49:10 +00:00
19 changed files with 19 additions and 76 deletions

View file

@ -46,7 +46,6 @@ WalkerActor::~WalkerActor()
void WalkerActor::handle_message(StringView type, JsonObject const& message)
{
JsonObject response;
response.set("from"sv, name());
if (type == "children"sv) {
auto node = message.get_string("node"sv);
@ -99,11 +98,8 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
return;
}
if (auto self = weak_self.strong_ref()) {
JsonObject message;
message.set("from"sv, self->name());
self->send_message(move(message), move(block_token));
}
if (auto self = weak_self.strong_ref())
self->send_message({}, move(block_token));
});
return;
@ -138,11 +134,8 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
return;
}
if (auto self = weak_self.strong_ref()) {
JsonObject message;
message.set("from"sv, self->name());
self->send_message(move(message), move(block_token));
}
if (auto self = weak_self.strong_ref())
self->send_message({}, move(block_token));
});
return;
@ -199,7 +192,6 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
if (auto self = weak_self.strong_ref()) {
JsonObject message;
message.set("from"sv, self->name());
message.set("value"sv, html.release_value());
self->send_message(move(message), move(block_token));
}
@ -243,7 +235,6 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
}
JsonObject message;
message.set("from"sv, self->name());
message.set("newParents"sv, JsonArray {});
message.set("nodes"sv, move(nodes));
self->send_message(move(message), move(block_token));
@ -299,11 +290,8 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
return;
}
if (auto self = weak_self.strong_ref()) {
JsonObject message;
message.set("from"sv, self->name());
self->send_message(move(message), move(block_token));
}
if (auto self = weak_self.strong_ref())
self->send_message({}, move(block_token));
});
return;
@ -346,7 +334,6 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
if (auto self = weak_self.strong_ref()) {
JsonObject message;
message.set("from"sv, self->name());
message.set("value"sv, html.release_value());
self->send_message(move(message), move(block_token));
}
@ -445,7 +432,6 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
if (auto self = weak_self.strong_ref()) {
JsonObject message;
message.set("from"sv, self->name());
message.set("nextSibling"sv, move(next_sibling));
self->send_message(move(message), move(block_token));
}
@ -488,11 +474,8 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
return;
}
if (auto self = weak_self.strong_ref()) {
JsonObject message;
message.set("from"sv, self->name());
self->send_message(move(message), move(block_token));
}
if (auto self = weak_self.strong_ref())
self->send_message({}, move(block_token));
});
return;
@ -503,10 +486,7 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
response.set("node"sv, serialize_root());
send_message(move(response));
JsonObject message;
message.set("from"sv, name());
send_message(move(message));
send_message({});
return;
}
@ -772,7 +752,6 @@ void WalkerActor::new_dom_node_mutation(WebView::Mutation mutation)
return;
JsonObject message;
message.set("from"sv, name());
message.set("type"sv, "newMutations"sv);
send_message(move(message));