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

Code before:
    /// <https://html.spec.whatwg.org/multipage/#dom-dialog-show>
    fn Show(&self, can_gc: CanGc) -> ErrorResult {
        let element = self.upcast::<Element>();
        // 1. If this has an open attribute and is modal of this is false, then return.
        if element.has_attribute(&local_name!("open")) && !self.is_modal.get() {
            return Ok(());
        }

        // 2. If this has an open attribute, then throw an "InvalidStateError" DOMException.
        if element.has_attribute(&local_name!("open")) {
            return Err(Error::InvalidState(None));
        }

        // 3. If the result of firing an event named beforetoggle, using ToggleEvent, with the cancelable attribute initialized to true, the oldState attribute initialized to "closed", and the newState attribute initialized to "open" at this is false, then return.
        let event = ToggleEvent::new(
            &self.owner_window(),
            atom!("beforetoggle"),
            EventBubbles::DoesNotBubble,
            EventCancelable::Cancelable,
            DOMString::from("closed"),
            DOMString::from("open"),
            None,
            CanGc::note(),
        );
        let event = event.upcast::<Event>();
        if !event.fire(self.upcast::<EventTarget>(), CanGc::note()) {
            return Ok(());
        }

        // 4. If this has an open attribute, then return.
        if element.has_attribute(&local_name!("open")) {
            return Ok(());
        }

        // TODO: 5. Queue a dialog toggle event task given this, "closed", "open", and null.

        // 6. Add an open attribute to this, whose value is the empty string.
        element.set_bool_attribute(&local_name!("open"), true, can_gc);

        // TODO: 7. Set this's previously focused element to the focused element.

        // TODO: 8. Let document be this's node document.

        // TODO: 9. Let hideUntil be the result of running topmost popover ancestor given this, document's showing hint popover list, null, and false.

        // TODO: 10. If hideUntil is null, then set hideUntil to the result of running topmost popover ancestor given this, document's showing auto popover list, null, and false.

        // TODO: 11. If hideUntil is null, then set hideUntil to document.

        // TODO: 12. Run hide all popovers until given hideUntil, false, and true.


Review comment (suggestion):
```suggestion
        if !event.fire(self.upcast::<EventTarget>(), can_gc) {
```

Code after:
    /// <https://html.spec.whatwg.org/multipage/#dom-dialog-show>
    fn Show(&self, can_gc: CanGc) -> ErrorResult {
        let element = self.upcast::<Element>();
        // Step 1. If this has an open attribute and is modal of this is false, then return.
        if element.has_attribute(&local_name!("open")) && !self.is_modal.get() {
            return Ok(());
        }

        // Step 2. If this has an open attribute, then throw an "InvalidStateError" DOMException.
        if element.has_attribute(&local_name!("open")) {
            return Err(Error::InvalidState(None));
        }

        // Step 3. If the result of firing an event named beforetoggle, using ToggleEvent, with the cancelable attribute initialized to true, the oldState attribute initialized to "closed", and the newState attribute initialized to "open" at this is false, then return.
        let event = ToggleEvent::new(
            &self.owner_window(),
            atom!("beforetoggle"),
            EventBubbles::DoesNotBubble,
            EventCancelable::Cancelable,
            DOMString::from("closed"),
            DOMString::from("open"),
            None,
            can_gc,
        );
        let event = event.upcast::<Event>();
        if !event.fire(self.upcast::<EventTarget>(), can_gc) {
            return Ok(());
        }

        // Step 4. If this has an open attribute, then return.
        if element.has_attribute(&local_name!("open")) {
            return Ok(());
        }

        // TODO: Step 5. Queue a dialog toggle event task given this, "closed", "open", and null.

        // Step 6. Add an open attribute to this, whose value is the empty string.
        element.set_bool_attribute(&local_name!("open"), true, can_gc);

        // TODO: Step 7. Set this's previously focused element to the focused element.

        // TODO: Step 8. Let document be this's node document.

        // TODO: Step 9. Let hideUntil be the result of running topmost popover ancestor given this, document's showing hint popover list, null, and false.

        // TODO: Step 10. If hideUntil is null, then set hideUntil to the result of running topmost popover ancestor given this, document's showing auto popover list, null, and false.

        // TODO: Step 11. If hideUntil is null, then set hideUntil to document.

        // TODO: Step 12. Run hide all popovers until given hideUntil, false, and true.