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

Code before:
        // TODO

        // Step 4. If container is an iframe element, then queue an element task
        // on the DOM manipulation task source given container to run the iframe load event steps given container.
        //
        // Note: this will also result in the "iframe-load-event-steps" being run.
        // https://html.spec.whatwg.org/multipage/#iframe-load-event-steps
        self.notify_constellation_load();

        // Step 5. Otherwise, if container is non-null, then queue an element task on the DOM manipulation task source
        // given container to fire an event named load at container.
        // TODO

        // Step 13 of https://html.spec.whatwg.org/multipage/#shared-declarative-refresh-steps
        //
        // At least time seconds have elapsed since document's completely loaded time,
        // adjusted to take into account user or user agent preferences.
        if let Some(DeclarativeRefresh::PendingLoad { url, time }) =
            &*self.declarative_refresh.borrow()
        {
            self.window.as_global_scope().schedule_callback(
                OneshotTimerCallback::RefreshRedirectDue(RefreshRedirectDue {
                    window: DomRoot::from_ref(self.window()),
                    url: url.clone(),
                }),
                Duration::from_secs(*time),
            );
        }
    }

    /// Step 9 of <https://html.spec.whatwg.org/multipage/#the-end>
    fn queue_document_completion(&self) {
        self.loader.borrow_mut().inhibit_events();

        // The rest will ever run only once per document.

        // Step 9. Queue a global task on the DOM manipulation task source given
        // the Document's relevant global object to run the following steps:
        debug!("Document loads are complete.");
        let document = Trusted::new(self);
        self.owner_global()
            .task_manager()
            .dom_manipulation_task_source()
            .queue(task!(fire_load_event: move || {
                let document = document.root();
                // Step 9.3. Let window be the Document's relevant global object.
                let window = document.window();
                if !window.is_alive() {
                    return;
                }


Review comment (suggestion):
Per https://github.com/servo/servo/issues/41972#issuecomment-3867074855 we should instead fix the logic for the `LoadBlocker` of an iframe. I have made the first steps on that, but will need to continue that in a follow-up PR.

Code after:
        // Step 4. If container is an iframe element, then queue an element task
        // on the DOM manipulation task source given container to run the iframe load event steps given container.
        //
        // Note: this will also result in the "iframe-load-event-steps" being run.
        // https://html.spec.whatwg.org/multipage/#iframe-load-event-steps
        self.notify_constellation_load();

        // Step 5. Otherwise, if container is non-null, then queue an element task on the DOM manipulation task source
        // given container to fire an event named load at container.
        // TODO

        // Step 13 of https://html.spec.whatwg.org/multipage/#shared-declarative-refresh-steps
        //
        // At least time seconds have elapsed since document's completely loaded time,
        // adjusted to take into account user or user agent preferences.
        if let Some(DeclarativeRefresh::PendingLoad { url, time }) =
            &*self.declarative_refresh.borrow()
        {
            self.window.as_global_scope().schedule_callback(
                OneshotTimerCallback::RefreshRedirectDue(RefreshRedirectDue {
                    window: DomRoot::from_ref(self.window()),
                    url: url.clone(),
                }),
                Duration::from_secs(*time),
            );
        }
    }

    /// Step 9 of <https://html.spec.whatwg.org/multipage/#the-end>
    fn queue_document_completion(&self) {
        self.loader.borrow_mut().inhibit_events();

        // The rest will ever run only once per document.

        // Step 9. Queue a global task on the DOM manipulation task source given
        // the Document's relevant global object to run the following steps:
        debug!("Document loads are complete.");
        let document = Trusted::new(self);
        self.owner_global()
            .task_manager()
            .dom_manipulation_task_source()
            .queue(task!(fire_load_event: move || {
                let document = document.root();
                // Step 9.3. Let window be the Document's relevant global object.
                let window = document.window();
                if !window.is_alive() {
                    return;
                }

                // Step 9.1. Update the current document readiness to "complete".
                document.set_ready_state(DocumentReadyState::Complete, CanGc::note());