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

Code before:
    pub(crate) fn deferred_fetches(&self) -> Vec<QueuedDeferredFetchRecord> {
        self.fetch_group
            .borrow()
            .deferred_fetch_records
            .values()
            .cloned()
            .collect()
    }

    pub(crate) fn deferred_fetch_record_for_id(
        &self,
        deferred_fetch_record_id: &DeferredFetchRecordId,
    ) -> QueuedDeferredFetchRecord {
        self.fetch_group
            .borrow()
            .deferred_fetch_records
            .get(deferred_fetch_record_id)
            .expect("Should always use a generated fetch_record_id instead of passing your own")
            .clone()
    }

    /// <https://fetch.spec.whatwg.org/#process-deferred-fetches>
    pub(crate) fn process_deferred_fetches(&self) {
        // Step 1. For each deferred fetch record deferredRecord of fetchGroup’s
        // deferred fetch records, process a deferred fetch deferredRecord.
        for deferred_fetch in self.deferred_fetches() {
            deferred_fetch.process();
        }
    }

    pub(crate) fn import_map(&self) -> Ref<'_, ImportMap> {
        self.import_map.borrow()
    }

    pub(crate) fn import_map_mut(&self) -> RefMut<'_, ImportMap> {
        self.import_map.borrow_mut()
    }

    pub(crate) fn resolved_module_set(&self) -> Ref<'_, HashSet<ResolvedModule>> {
        self.resolved_module_set.borrow()
    }

    pub(crate) fn resolved_module_set_mut(&self) -> RefMut<'_, HashSet<ResolvedModule>> {
        self.resolved_module_set.borrow_mut()
    }

    /// <https://html.spec.whatwg.org/multipage/#add-module-to-resolved-module-set>
    pub(crate) fn add_module_to_resolved_module_set(
        &self,
        base_url: &str,
        specifier: &str,

Review comment (suggestion):
Here also I would call into an internal method of the mutable fetchgroup. Since there is no `CanGC`, you can process each deferred fetch while holding a mutable borrow. 

Code after:
    pub(crate) fn deferred_fetches(&self) -> Vec<QueuedDeferredFetchRecord> {
        self.fetch_group
            .borrow()
            .deferred_fetch_records
            .values()
            .cloned()
            .collect()
    }

    pub(crate) fn deferred_fetch_record_for_id(
        &self,
        deferred_fetch_record_id: &DeferredFetchRecordId,
    ) -> QueuedDeferredFetchRecord {
        self.fetch_group
            .borrow()
            .deferred_fetch_records
            .get(deferred_fetch_record_id)
            .expect("Should always use a generated fetch_record_id instead of passing your own")
            .clone()
    }

    /// <https://fetch.spec.whatwg.org/#process-deferred-fetches>
    pub(crate) fn process_deferred_fetches(&self) {
        // Step 1. For each deferred fetch record deferredRecord of fetchGroup’s
        // deferred fetch records, process a deferred fetch deferredRecord.
        for deferred_fetch in self.deferred_fetches() {
            deferred_fetch.process(self);
        }
    }

    pub(crate) fn import_map(&self) -> Ref<'_, ImportMap> {
        self.import_map.borrow()
    }

    pub(crate) fn import_map_mut(&self) -> RefMut<'_, ImportMap> {
        self.import_map.borrow_mut()
    }

    pub(crate) fn resolved_module_set(&self) -> Ref<'_, HashSet<ResolvedModule>> {
        self.resolved_module_set.borrow()
    }

    pub(crate) fn resolved_module_set_mut(&self) -> RefMut<'_, HashSet<ResolvedModule>> {
        self.resolved_module_set.borrow_mut()
    }

    /// <https://html.spec.whatwg.org/multipage/#add-module-to-resolved-module-set>
    pub(crate) fn add_module_to_resolved_module_set(
        &self,
        base_url: &str,
        specifier: &str,