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

Code before:
        // > If observer’s internal [[QueuedEntries]] slot is empty, continue.
        if self.queued_entries.borrow().is_empty() {
            return;
        }

        // Step 2-3
        // We trivially moved the entries and root them.
        let queued_entries = self
            .queued_entries
            .take()
            .iter_mut()
            .map(|entry| entry.as_rooted())
            .collect();

        // Step 4-5
        let _ = self.callback.Call_(
            self,
            queued_entries,
            self,
            ExceptionHandling::Report,
            can_gc,
        );
    }

    /// Connect the observer itself into owner doc if it is unconnected.
    /// We check if we are already connected
    fn connect_to_owner(&self) {
        if !self.is_connected.get() {
            self.owner_doc.add_intersection_observer(self);
            self.is_connected.set(true);
        }
    }

    /// Disconnect the observer itself from owner doc.
    /// We we were already disconnected from the observer
    fn disconnect_from_owner(&self) {
        if self.is_connected.get() {
            self.owner_doc.remove_intersection_observer(self);
        }
    }

    /// > The root intersection rectangle for an IntersectionObserver is
    /// > the rectangle we’ll use to check against the targets.
    ///
    /// <https://w3c.github.io/IntersectionObserver/#intersectionobserver-root-intersection-rectangle>
    pub(crate) fn root_intersection_rectangle(
        &self,
        document: &Document,
    ) -> Option<Rect<Au, CSSPixel>> {
        let window = document.window();
        let intersection_rectangle = match &self.root {

Review comment (suggestion):
```suggestion
    /// If the [`IntersectionObserver`] is already connected, do nothing.
```

Code after:
        // > If observer’s internal [[QueuedEntries]] slot is empty, continue.
        if self.queued_entries.borrow().is_empty() {
            return;
        }

        // Step 2-3
        // We trivially moved the entries and root them.
        let queued_entries = self
            .queued_entries
            .take()
            .iter_mut()
            .map(|entry| entry.as_rooted())
            .collect();

        // Step 4-5
        let _ = self.callback.Call_(
            self,
            queued_entries,
            self,
            ExceptionHandling::Report,
            can_gc,
        );
    }

    /// Connect the observer itself into owner doc if it is unconnected.
    /// If the [`IntersectionObserver`] is already connected, do nothing.
    fn connect_to_owner(&self) {
        if !self.connected_to_document.get() {
            self.owner_doc.add_intersection_observer(self);
            self.connected_to_document.set(true);
        }
    }

    /// Disconnect the observer itself from owner doc.
    /// If not connected to a [`Document`], do nothing.
    fn disconnect_from_owner(&self) {
        if self.connected_to_document.get() {
            self.owner_doc.remove_intersection_observer(self);
        }
    }

    /// > The root intersection rectangle for an IntersectionObserver is
    /// > the rectangle we’ll use to check against the targets.
    ///
    /// <https://w3c.github.io/IntersectionObserver/#intersectionobserver-root-intersection-rectangle>
    pub(crate) fn root_intersection_rectangle(
        &self,
        document: &Document,
    ) -> Option<Rect<Au, CSSPixel>> {
        let window = document.window();
        let intersection_rectangle = match &self.root {