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

Code before:
        Ok(())
    }

    /// <https://html.spec.whatwg.org/multipage/#close-the-dialog>
    pub fn close_the_dialog(
        &self,
        result: Option<DOMString>,
        source: Option<DomRoot<Element>>,
        can_gc: CanGc,
    ) {
        let subject = self.upcast::<Element>();
        // Step 1. If subject does not have an open attribute, then return.
        if !subject.has_attribute(&local_name!("open")) {
            return;
        }

        // Step 2. Fire an event named beforetoggle, using ToggleEvent, with the oldState attribute initialized to "open", the newState attribute initialized to "closed", and the source attribute initialized to source at subject.
        let event = ToggleEvent::new(
            &self.owner_window(),
            atom!("beforetoggle"),
            EventBubbles::DoesNotBubble,
            EventCancelable::NotCancelable,
            DOMString::from("open"),
            DOMString::from("closed"),
            source.borrow().clone(),
            CanGc::note(),
        );
        let event = event.upcast::<Event>();
        event.fire(self.upcast::<EventTarget>(), CanGc::note());

        // Step 3. If subject does not have an open attribute, then return.
        if !subject.has_attribute(&local_name!("open")) {
            return;
        }

        // Step 4. Queue a dialog toggle event task given subject, "open", "closed", and source.
        self.queue_dialog_toggle_event_task(
            DOMString::from("open"),
            DOMString::from("closed"),
            source,
        );

        // Step 5. Remove subject's open attribute.
        subject.remove_attribute(&ns!(), &local_name!("open"), can_gc);

        // TODO: Step 6. If is modal of subject is true, then request an element to be removed from the top layer given subject.

        // TODO: Step 7. Let wasModal be the value of subject's is modal flag.

        // Step 8. Set is modal of subject to false.
        self.is_modal.set(false);

Review comment (suggestion):
Always pass in the `can_gc` from the calling method. It is rare that you would need to call `CanGc::note()` manually.

```suggestion
            can_gc,
```

Code after:
        Ok(())
    }

    /// <https://html.spec.whatwg.org/multipage/#close-the-dialog>
    pub fn close_the_dialog(
        &self,
        result: Option<DOMString>,
        source: Option<DomRoot<Element>>,
        can_gc: CanGc,
    ) {
        let subject = self.upcast::<Element>();
        // Step 1. If subject does not have an open attribute, then return.
        if !subject.has_attribute(&local_name!("open")) {
            return;
        }

        // Step 2. Fire an event named beforetoggle, using ToggleEvent, with the oldState attribute initialized to "open", the newState attribute initialized to "closed", and the source attribute initialized to source at subject.
        let event = ToggleEvent::new(
            &self.owner_window(),
            atom!("beforetoggle"),
            EventBubbles::DoesNotBubble,
            EventCancelable::NotCancelable,
            DOMString::from("open"),
            DOMString::from("closed"),
            source.borrow().clone(),
            can_gc,
        );
        let event = event.upcast::<Event>();
        event.fire(self.upcast::<EventTarget>(), can_gc);

        // Step 3. If subject does not have an open attribute, then return.
        if !subject.has_attribute(&local_name!("open")) {
            return;
        }

        // Step 4. Queue a dialog toggle event task given subject, "open", "closed", and source.
        self.queue_dialog_toggle_event_task(
            DOMString::from("open"),
            DOMString::from("closed"),
            source,
        );

        // Step 5. Remove subject's open attribute.
        subject.remove_attribute(&ns!(), &local_name!("open"), can_gc);

        // TODO: Step 6. If is modal of subject is true, then request an element to be removed from the top layer given subject.

        // TODO: Step 7. Let wasModal be the value of subject's is modal flag.

        // Step 8. Set is modal of subject to false.
        self.is_modal.set(false);