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

Code before:

        // 3. If subject's node document is not fully active, then throw an "InvalidStateError" DOMException.
        if !subject.owner_document().is_fully_active() {
            return Err(Error::InvalidState(None));
        }

        // 4. If subject is not connected, then throw an "InvalidStateError" DOMException.
        if !subject.is_connected() {
            return Err(Error::InvalidState(None));
        }

        // TODO 5. If subject is in the popover showing state, then throw an "InvalidStateError" DOMException.

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

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

        // 8. If subject is not connected, then return.
        if !subject.is_connected() {
            return Ok(());
        }

        // TODO 9. If subject is in the popover showing state, then return.

        // TODO 10. Queue a dialog toggle event task given subject, "closed", "open", and source.

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

        // TODO 12. Assert: subject's close watcher is not null.

        // 13. Set is modal of subject to true.
        self.is_modal.set(true);


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

Code after:

        // Step 3. If subject's node document is not fully active, then throw an "InvalidStateError" DOMException.
        if !subject.owner_document().is_fully_active() {
            return Err(Error::InvalidState(None));
        }

        // Step 4. If subject is not connected, then throw an "InvalidStateError" DOMException.
        if !subject.is_connected() {
            return Err(Error::InvalidState(None));
        }

        // TODO: Step 5. If subject is in the popover showing state, then throw an "InvalidStateError" DOMException.

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

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

        // Step 8. If subject is not connected, then return.
        if !subject.is_connected() {
            return Ok(());
        }

        // TODO: Step 9. If subject is in the popover showing state, then return.

        // TODO: Step 10. Queue a dialog toggle event task given subject, "closed", "open", and source.

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

        // TODO: Step 12. Assert: subject's close watcher is not null.

        // Step 13. Set is modal of subject to true.
        self.is_modal.set(true);