Devtools: refactor source actor state (#37528)

We currently store the source contents in both the SourceActor and the
ThreadActor’s SourceManager, which is redundant. We also currently send
the source contents in thread `sources` responses and watcher
`resources-available-array` messages, but in both cases this is
unnecessary (and ignored by the client).

This patch merges SourceData into SourceActor, making the latter the
single source of truth for source-related state. We also create a
SourceForm type, which represents the subset of source-related state
that gets sent in thread `sources` responses (and for now, watcher
`resources-available-array` messages).

Finally we rename `source_urls` → `source_actor_names` and `new_source`
→ `new_registered` for clarity.

Testing: no changes to client-facing behaviour, and this is covered by
tests

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
shuppy 2025-06-18 21:11:46 +10:00 committed by GitHub
parent 97011a53ac
commit 0896341285
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 61 deletions

View file

@ -7,7 +7,7 @@ use std::net::TcpStream;
use serde::Serialize;
use serde_json::{Map, Value};
use super::source::{SourceData, SourceManager, SourcesReply};
use super::source::{SourceManager, SourcesReply};
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::protocol::JsonPacketStream;
use crate::{EmptyReplyMsg, StreamId};
@ -124,17 +124,9 @@ impl Actor for ThreadActor {
// Client has attached to the thread and wants to load script sources.
// <https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#loading-script-sources>
"sources" => {
let sources: Vec<SourceData> = self
.source_manager
.source_urls
.borrow()
.iter()
.cloned()
.collect();
let msg = SourcesReply {
from: self.name(),
sources,
sources: self.source_manager.source_forms(registry),
};
let _ = stream.write_json_packet(&msg);
ActorMessageStatus::Processed