Repository: servo/servo
File: components/script/script_thread.rs (Rust)

Code before:
    was_interacting: bool,
    user_interaction_cell: Rc<Cell<bool>>,
}

impl ScriptUserInteractingGuard {
    fn new(user_interaction_cell: Rc<Cell<bool>>) -> Self {
        let was_interacting = user_interaction_cell.get();
        user_interaction_cell.set(true);
        Self {
            was_interacting,
            user_interaction_cell,
        }
    }
}

impl Drop for ScriptUserInteractingGuard {
    fn drop(&mut self) {
        self.user_interaction_cell.set(self.was_interacting)
    }
}

#[derive(JSTraceable)]
// ScriptThread instances are rooted on creation, so this is okay
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
pub struct ScriptThread {
    /// Weak Rc to itself or None if not yet initialized
    #[no_trace]
    this: Weak<ScriptThread>,

    /// <https://html.spec.whatwg.org/multipage/#last-render-opportunity-time>
    last_render_opportunity_time: Cell<Option<Instant>>,

    /// The documents for pipelines managed by this thread
    documents: DomRefCell<DocumentCollection>,
    /// The window proxies known by this thread
    window_proxies: Rc<ScriptWindowProxies>,
    /// A list of data pertaining to loads that have not yet received a network response
    incomplete_loads: DomRefCell<Vec<InProgressLoad>>,
    /// A vector containing parser contexts which have not yet been fully processed
    incomplete_parser_contexts: IncompleteParserContexts,
    /// An [`ImageCacheFactory`] to use for creating [`ImageCache`]s for all of the
    /// child `Pipeline`s.
    #[no_trace]
    image_cache_factory: Arc<dyn ImageCacheFactory>,

    /// A [`ScriptThreadReceivers`] holding all of the incoming `Receiver`s for messages
    /// to this [`ScriptThread`].
    receivers: ScriptThreadReceivers,

    /// A [`ScriptThreadSenders`] that holds all outgoing sending channels necessary to communicate
    /// to other parts of Servo.

Review comment (suggestion):
I think the expanded rustdoc is useful here:


```suggestion
    /// A reference to the currently operating `ScriptThread`. This should always be
    /// upgradable to an `Rc` as long as the `ScriptThread` is running.
```

Code after:
    was_interacting: bool,
    user_interaction_cell: Rc<Cell<bool>>,
}

impl ScriptUserInteractingGuard {
    fn new(user_interaction_cell: Rc<Cell<bool>>) -> Self {
        let was_interacting = user_interaction_cell.get();
        user_interaction_cell.set(true);
        Self {
            was_interacting,
            user_interaction_cell,
        }
    }
}

impl Drop for ScriptUserInteractingGuard {
    fn drop(&mut self) {
        self.user_interaction_cell.set(self.was_interacting)
    }
}

#[derive(JSTraceable)]
// ScriptThread instances are rooted on creation, so this is okay
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
pub struct ScriptThread {
    /// A reference to the currently operating `ScriptThread`. This should always be
    /// upgradable to an `Rc` as long as the `ScriptThread` is running.
    #[no_trace]
    this: Weak<ScriptThread>,

    /// <https://html.spec.whatwg.org/multipage/#last-render-opportunity-time>
    last_render_opportunity_time: Cell<Option<Instant>>,

    /// The documents for pipelines managed by this thread
    documents: DomRefCell<DocumentCollection>,
    /// The window proxies known by this thread
    window_proxies: Rc<ScriptWindowProxies>,
    /// A list of data pertaining to loads that have not yet received a network response
    incomplete_loads: DomRefCell<Vec<InProgressLoad>>,
    /// A vector containing parser contexts which have not yet been fully processed
    incomplete_parser_contexts: IncompleteParserContexts,
    /// An [`ImageCacheFactory`] to use for creating [`ImageCache`]s for all of the
    /// child `Pipeline`s.
    #[no_trace]
    image_cache_factory: Arc<dyn ImageCacheFactory>,

    /// A [`ScriptThreadReceivers`] holding all of the incoming `Receiver`s for messages
    /// to this [`ScriptThread`].
    receivers: ScriptThreadReceivers,

    /// A [`ScriptThreadSenders`] that holds all outgoing sending channels necessary to communicate