Repository: servo/servo
File: components/devtools/actors/console.rs (Rust)

Code before:
    helper_result: Value,
}

#[derive(Serialize)]
struct EvaluateJSAsyncReply {
    from: String,
    #[serde(rename = "resultID")]
    result_id: String,
}

#[derive(Serialize)]
struct SetPreferencesReply {
    from: String,
    updated: Vec<String>,
}

pub(crate) enum Root {
    BrowsingContext(String),
    DedicatedWorker(String),
}

pub(crate) struct ConsoleActor {
    pub name: String,
    pub root: Root,
    pub cached_events: AtomicRefCell<HashMap<UniqueId, Vec<ConsoleResource>>>,
    pub only_cache: AtomicBool,
}

impl ConsoleActor {
    fn script_chan(&self, registry: &ActorRegistry) -> GenericSender<DevtoolScriptControlMsg> {
        match &self.root {
            Root::BrowsingContext(browsing_context) => registry
                .find::<BrowsingContextActor>(browsing_context)
                .script_chan
                .clone(),
            Root::DedicatedWorker(worker) => {
                registry.find::<WorkerActor>(worker).script_chan.clone()
            },
        }
    }

    fn current_unique_id(&self, registry: &ActorRegistry) -> UniqueId {
        match &self.root {
            Root::BrowsingContext(browsing_context) => UniqueId::Pipeline(
                registry
                    .find::<BrowsingContextActor>(browsing_context)
                    .pipeline_id(),
            ),
            Root::DedicatedWorker(worker) => {
                UniqueId::Worker(registry.find::<WorkerActor>(worker).worker_id)
            },

Review comment (suggestion):
Is it possible to add some documentation about this field? I'm not sure exactly what its purpose is. I notice that it is initially set to `true` which means that message are no sent. Then went a "console-message" or "error-message" is received it becomes `false`.

Code after:
    helper_result: Value,
}

#[derive(Serialize)]
struct EvaluateJSAsyncReply {
    from: String,
    #[serde(rename = "resultID")]
    result_id: String,
}

#[derive(Serialize)]
struct SetPreferencesReply {
    from: String,
    updated: Vec<String>,
}

pub(crate) enum Root {
    BrowsingContext(String),
    DedicatedWorker(String),
}

pub(crate) struct ConsoleActor {
    pub name: String,
    pub root: Root,
    pub cached_events: AtomicRefCell<HashMap<UniqueId, Vec<ConsoleResource>>>,
    /// Used to control whether to send resource array messages from
    /// `handle_console_resource`. It starts being false, and it only gets
    /// activated after the client requests `console-message` or `error-message`
    /// resources for the first time. Otherwise we would be sending messages
    /// before the client is ready to receive them.
    pub client_ready_to_receive_messages: AtomicBool,
}

impl ConsoleActor {
    fn script_chan(&self, registry: &ActorRegistry) -> GenericSender<DevtoolScriptControlMsg> {
        match &self.root {
            Root::BrowsingContext(browsing_context) => registry
                .find::<BrowsingContextActor>(browsing_context)
                .script_chan
                .clone(),
            Root::DedicatedWorker(worker) => {
                registry.find::<WorkerActor>(worker).script_chan.clone()
            },
        }
    }

    fn current_unique_id(&self, registry: &ActorRegistry) -> UniqueId {
        match &self.root {
            Root::BrowsingContext(browsing_context) => UniqueId::Pipeline(
                registry
                    .find::<BrowsingContextActor>(browsing_context)