Repository: servo/servo
File: components/constellation/constellation.rs (Rust)

Code before:
    pub webrender_api_sender: RenderApiSender,

    /// Webrender external images
    pub webrender_external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,

    /// Entry point to create and get channels to a WebGLThread.
    pub webgl_threads: Option<WebGLThreads>,

    /// The XR device registry
    pub webxr_registry: Option<webxr_api::Registry>,

    /// User agent string to report in network requests.
    pub user_agent: Cow<'static, str>,

    #[cfg(feature = "webgpu")]
    pub wgpu_image_map: WGPUImageMap,
}

/// Data needed for EvaluateJavaScript
struct EvaluateJavaScriptData {
    /// Embedders can run arbitrary javascript via messages to the constellation.
    /// We forward these messages to the script thread but need to store the callback function.
    pub(crate) callbacks: HashMap<embedder_traits::ScriptId, fn(Result<JSValue, JSValueError>)>,

    /// An Atomic Counter to assign callbacks to javascript execution
    pub counter: Mutex<embedder_traits::ScriptId>,
}

impl EvaluateJavaScriptData {
    fn new() -> EvaluateJavaScriptData {
        EvaluateJavaScriptData {
            callbacks: HashMap::new(),
            counter: Mutex::new(0),
        }
    }
}

/// Data needed for webdriver
struct WebDriverData {
    load_channel: Option<(PipelineId, IpcSender<WebDriverLoadStatus>)>,
    resize_channel: Option<IpcSender<Size2D<f32, CSSPixel>>>,
}

impl WebDriverData {
    fn new() -> WebDriverData {
        WebDriverData {
            load_channel: None,
            resize_channel: None,
        }
    }
}

Review comment (suggestion):
You could use an `Atomic` type or a newtype wrapper around an atomic type. No need for a lock.

Code after:
    /// Entry point to create and get channels to a WebGLThread.
    pub webgl_threads: Option<WebGLThreads>,

    /// The XR device registry
    pub webxr_registry: Option<webxr_api::Registry>,

    #[cfg(feature = "webgpu")]
    pub wgpu_image_map: WGPUImageMap,

    /// User content manager
    pub user_content_manager: UserContentManager,
}

/// Data needed for webdriver
struct WebDriverData {
    load_channel: Option<(PipelineId, IpcSender<WebDriverLoadStatus>)>,
    resize_channel: Option<IpcSender<Size2D<f32, CSSPixel>>>,
}

impl WebDriverData {
    fn new() -> WebDriverData {
        WebDriverData {
            load_channel: None,
            resize_channel: None,
        }
    }
}

/// When we are running reftests, we save an image to compare against a reference.
/// This enum gives the possible states of preparing such an image.
#[derive(Debug, PartialEq)]
enum ReadyToSave {
    NoTopLevelBrowsingContext,
    PendingChanges,
    DocumentLoading,
    EpochMismatch,
    PipelineUnknown,
    Ready,
}

/// When we are exiting a pipeline, we can either force exiting or not.
/// A normal exit waits for the compositor to update its state before
/// exiting, and delegates layout exit to script. A forced exit does
/// not notify the compositor, and exits layout without involving script.
#[derive(Clone, Copy, Debug)]
enum ExitPipelineMode {
    Normal,
    Force,
}

/// The number of warnings to include in each crash report.