LibDevTools: Add a helper to acquire required message parameters

This is just to help make the message handlers a bit briefer. I had
considered adding a TRY-like macro to auto-return when the lookup fails,
but since statement expressions cannot return references, that would
result in a copy of all e.g. object and array lookups.
This commit is contained in:
Timothy Flynn 2025-03-11 09:05:01 -04:00 committed by Tim Flynn
commit e1ed8722e0
Notes: github-actions[bot] 2025-03-12 16:49:03 +00:00
12 changed files with 85 additions and 121 deletions

View file

@ -65,11 +65,9 @@ void RootActor::handle_message(StringView type, JsonObject const& message)
}
if (type == "getProcess"sv) {
auto id = message.get_integer<u64>("id"sv);
if (!id.has_value()) {
send_missing_parameter_error("id"sv);
auto id = get_required_parameter<u64>(message, "id"sv);
if (!id.has_value())
return;
}
for (auto const& actor : devtools().actor_registry()) {
auto const* process_actor = as_if<ProcessActor>(*actor.value);
@ -87,11 +85,9 @@ void RootActor::handle_message(StringView type, JsonObject const& message)
}
if (type == "getTab"sv) {
auto browser_id = message.get_integer<u64>("browserId"sv);
if (!browser_id.has_value()) {
send_missing_parameter_error("browserId"sv);
auto browser_id = get_required_parameter<u64>(message, "browserId"sv);
if (!browser_id.has_value())
return;
}
for (auto const& actor : devtools().actor_registry()) {
auto const* tab_actor = as_if<TabActor>(*actor.value);