Files
servo/components/devtools/actors/environment.rs
Narfinger 870576f948 devtools: Implement MallocSizeOf for DevtoolsInstance (#42478)
This implements MallocSizeOf for DevtoolsInstance. Major changes:
- Newtype for ActorRegistry because AtomicRefCell<HashMap<String,
Arc<dyn Actor>>> did not like mallocsizeof (even with trait bound on
Actor)
- Implement MallocSizeOf for BTreeSet.
- Implement MallocSizeOf of 0 for AtomicU32 and TcpStream
- Ignore a couple of MallocSizeof for http::Method, http::HeaderMap and
json::Value

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: Compilation is the test.
Fixes: Part of addressing https://github.com/servo/servo/issues/42453

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2026-02-10 17:32:47 +00:00

92 lines
2.6 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use malloc_size_of_derive::MallocSizeOf;
use serde::Serialize;
use serde_json::{Map, Value};
use crate::actor::{Actor, ActorEncode, ActorRegistry};
use crate::actors::object::ObjectActorMsg;
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub enum EnvironmentType {
Function,
_Block,
_Object,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub enum EnvironmentScope {
Function,
_Global,
}
#[derive(Serialize)]
struct EnvironmentBindings {
arguments: Vec<Value>,
variables: Map<String, Value>,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct EnvironmentFunction {
display_name: String,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct EnvironmentActorMsg {
actor: String,
#[serde(rename = "type")]
type_: EnvironmentType,
scope_kind: EnvironmentScope,
#[serde(skip_serializing_if = "Option::is_none")]
parent: Option<Box<EnvironmentActorMsg>>,
#[serde(skip_serializing_if = "Option::is_none")]
bindings: Option<EnvironmentBindings>,
/// Should be set if `type_` is `EnvironmentType::Function`
#[serde(skip_serializing_if = "Option::is_none")]
function: Option<EnvironmentFunction>,
/// Should be set if `type_` is `EnvironmentType::Object`
#[serde(skip_serializing_if = "Option::is_none")]
object: Option<ObjectActorMsg>,
}
/// Resposible for listing the bindings in an environment and assigning new values to them.
/// Referenced by `FrameActor` when replying to `getEnvironment` messages.
/// <https://searchfox.org/firefox-main/source/devtools/server/actors/environment.js>
#[derive(MallocSizeOf)]
pub(crate) struct EnvironmentActor {
pub name: String,
pub parent: Option<String>,
}
impl Actor for EnvironmentActor {
fn name(&self) -> String {
self.name.clone()
}
}
impl ActorEncode<EnvironmentActorMsg> for EnvironmentActor {
fn encode(&self, registry: &ActorRegistry) -> EnvironmentActorMsg {
let parent = self
.parent
.as_ref()
.map(|p| registry.find::<EnvironmentActor>(p))
.map(|p| Box::new(p.encode(registry)));
// TODO: Change hardcoded values.
EnvironmentActorMsg {
actor: self.name(),
type_: EnvironmentType::Function,
scope_kind: EnvironmentScope::Function,
parent,
bindings: None,
function: None,
object: None,
}
}
}