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

Code before:
                } else {
                    // Return a failure if we are still waiting for previous ForceGC results.
                    if self.pending_force_gc.is_some() {
                        let _ = callback.send(false);
                        return;
                    }

                    self.pending_force_gc = Some((count, callback));
                    for event_loop in event_loops {
                        let _ = event_loop.send(ScriptThreadMessage::ForceGC);
                    }
                }
            },
            ScriptToConstellationMessage::ForceGCCompleted => {
                let current = self.pending_force_gc.take();

                if let Some((count, callback)) = current {
                    let remaining = count - 1;
                    if remaining == 0 {
                        let _ = callback.send(true);
                    } else {
                        self.pending_force_gc = Some((remaining, callback.clone()));
                    }
                } else {
                    error!("Unexpected ForceGCCompleted message!");
                }
            },
        }
    }

    /// Check the origin of a message against that of the pipeline it came from.
    /// Note: this is still limited as a security check,
    /// see <https://github.com/servo/servo/issues/11722>
    fn check_origin_against_pipeline(
        &self,
        pipeline_id: &PipelineId,
        origin: &ImmutableOrigin,
    ) -> Result<(), ()> {
        let pipeline_origin = match self.pipelines.get(pipeline_id) {
            Some(pipeline) => pipeline.load_data.url.origin(),
            None => {
                warn!("Received message from closed or unknown pipeline.");
                return Err(());
            },
        };
        if &pipeline_origin == origin {
            return Ok(());
        }
        Err(())
    }


Review comment (suggestion):
```suggestion
                let Some(current) = self.pending_force_gc.take() else {
                    warn!("Unexpected ForceGCCompleted message!");
                    return;
                }
                let remaining = count - 1;
                if remaining == 0 {
                    let _ = callback.send(true);
                    return;
                }
                self.pending_force_gc = Some((remaining, callback.clone()));
```

Code after:
        &self,
        pipeline_id: &PipelineId,
        origin: &ImmutableOrigin,
    ) -> Result<(), ()> {
        let pipeline_origin = match self.pipelines.get(pipeline_id) {
            Some(pipeline) => pipeline.load_data.url.origin(),
            None => {
                warn!("Received message from closed or unknown pipeline.");
                return Err(());
            },
        };
        if &pipeline_origin == origin {
            return Ok(());
        }
        Err(())
    }

    #[servo_tracing::instrument(skip_all)]
    #[cfg(feature = "webgpu")]
    fn handle_wgpu_request(
        &mut self,
        source_pipeline_id: PipelineId,
        browsing_context_id: BrowsingContextId,
        request: ScriptToConstellationMessage,
    ) {
        use webgpu::start_webgpu_thread;

        let browsing_context_group_id = match self.browsing_contexts.get(&browsing_context_id) {
            Some(bc) => &bc.bc_group_id,
            None => return warn!("Browsing context not found"),
        };
        let Some(source_pipeline) = self.pipelines.get(&source_pipeline_id) else {
            return warn!("{source_pipeline_id}: ScriptMsg from closed pipeline");
        };
        let Some(host) = registered_domain_name(&source_pipeline.url) else {
            return warn!("Invalid host url");
        };
        let browsing_context_group = if let Some(bcg) = self
            .browsing_context_group_set
            .get_mut(browsing_context_group_id)
        {
            bcg
        } else {
            return warn!("Browsing context group not found");
        };
        let webgpu_chan = match browsing_context_group.webgpus.entry(host) {
            Entry::Vacant(v) => start_webgpu_thread(
                self.paint_proxy.cross_process_paint_api.clone(),
                self.webrender_wgpu
                    .webrender_external_image_id_manager
                    .clone(),