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

Code before:
    fn contributes_a_script_blocking_style_sheet(
        &self,
        element: &HTMLElement,
        owner: &dyn StylesheetOwner,
        document: &Document,
    ) -> bool {
        // el was created by that Document's parser.
        owner.parser_inserted()
        // el is either a style element or a link element that was an external resource link that
        // contributes to the styling processing model when the el was created by the parser.
        && element.downcast::<HTMLLinkElement>().is_none_or(|link|
            self.contributes_to_the_styling_processing_model(element)
            // el's style sheet was enabled when the element was created by the parser.
            && !link.is_effectively_disabled()
        )
        // el's media attribute's value matches the environment.
        && element.media_attribute_matches_media_environment()
        // The last time the event loop reached step 1, el's root was that Document.
        && *element.owner_document() == *document
        // The user agent hasn't given up on loading that particular style sheet yet.
        // A user agent may give up on loading a style sheet at any time.
        //
        // This might happen when we time out a resource, but that happens in `fetch` instead
    }

    fn decrement_load_and_render_blockers(self, document: &Document) {
        if self.is_script_blocking {
            document.decrement_script_blocking_stylesheet_count();
        }

        if self.is_render_blocking {
            document.decrement_render_blocking_element_count();
        }

        document.finish_load(LoadType::Stylesheet(self.url), CanGc::note());
    }

    fn do_post_parse_tasks(self, success: bool, stylesheet: Arc<Stylesheet>) {
        let element = self.element.root();
        let document = self.document.root();
        let owner = element
            .upcast::<Element>()
            .as_stylesheet_owner()
            .expect("Stylesheet not loaded by <style> or <link> element!");

        match &self.source {
            // https://html.spec.whatwg.org/multipage/#link-type-stylesheet%3Aprocess-the-linked-resource
            StylesheetContextSource::LinkElement => {
                let link = element
                    .downcast::<HTMLLinkElement>()
                    .expect("Should be HTMLinkElement due to StylesheetContextSource");

Review comment (suggestion):
```suggestion
    fn decrement_load_and_render_blockers_and_finish_load(self, document: &Document) {
```

Code after:
    fn contributes_a_script_blocking_style_sheet(
        &self,
        element: &HTMLElement,
        owner: &dyn StylesheetOwner,
        document: &Document,
    ) -> bool {
        // el was created by that Document's parser.
        owner.parser_inserted()
        // el is either a style element or a link element that was an external resource link that
        // contributes to the styling processing model when the el was created by the parser.
        && element.downcast::<HTMLLinkElement>().is_none_or(|link|
            self.contributes_to_the_styling_processing_model(element)
            // el's style sheet was enabled when the element was created by the parser.
            && !link.is_effectively_disabled()
        )
        // el's media attribute's value matches the environment.
        && element.media_attribute_matches_media_environment()
        // The last time the event loop reached step 1, el's root was that Document.
        && *element.owner_document() == *document
        // The user agent hasn't given up on loading that particular style sheet yet.
        // A user agent may give up on loading a style sheet at any time.
        //
        // This might happen when we time out a resource, but that happens in `fetch` instead
    }

    fn decrement_blockers_and_finish_load(self, document: &Document) {
        if self.is_script_blocking {
            document.decrement_script_blocking_stylesheet_count();
        }

        if self.is_render_blocking {
            document.decrement_render_blocking_element_count();
        }

        document.finish_load(LoadType::Stylesheet(self.url), CanGc::note());
    }

    fn do_post_parse_tasks(self, success: bool, stylesheet: Arc<Stylesheet>) {
        let element = self.element.root();
        let document = self.document.root();
        let owner = element
            .upcast::<Element>()
            .as_stylesheet_owner()
            .expect("Stylesheet not loaded by <style> or <link> element!");

        match &self.source {
            // https://html.spec.whatwg.org/multipage/#link-type-stylesheet%3Aprocess-the-linked-resource
            StylesheetContextSource::LinkElement => {
                let link = element
                    .downcast::<HTMLLinkElement>()
                    .expect("Should be HTMLinkElement due to StylesheetContextSource");