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

Code before:
        next.remove_self(can_gc);
    }
}

impl VirtualMethods for HTMLElement {
    fn super_type(&self) -> Option<&dyn VirtualMethods> {
        Some(self.as_element() as &dyn VirtualMethods)
    }

    fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation, can_gc: CanGc) {
        self.super_type()
            .unwrap()
            .attribute_mutated(attr, mutation, can_gc);
        let element = self.as_element();
        match (attr.local_name(), mutation) {
            // https://html.spec.whatwg.org/multipage/#event-handler-attributes:event-handler-content-attributes-3
            (name, mutation)
                if name.starts_with("on") && EventTarget::is_content_event_handler(name) =>
            {
                let evtarget = self.upcast::<EventTarget>();
                let event_name = &name[2..];
                match mutation {
                    // https://html.spec.whatwg.org/multipage/#activate-an-event-handler
                    AttributeMutation::Set(_) => {
                        let source = &**attr.value();
                        let source_line = 1; // TODO(#9604) get current JS execution line
                        evtarget.set_event_handler_uncompiled(
                            self.owner_window().get_url(),
                            source_line,
                            event_name,
                            source,
                        );
                    },
                    // https://html.spec.whatwg.org/multipage/#deactivate-an-event-handler
                    AttributeMutation::Removed => {
                        evtarget.remove_event_listener(
                            event_name.into(),
                            evtarget.get_event_handler_common(event_name, can_gc),
                            EventListenerOptions { capture: false },
                        );
                    },
                }
            },

            (&local_name!("form"), mutation) if self.is_form_associated_custom_element() => {
                self.form_attribute_mutated(mutation, can_gc);
            },
            // Adding a "disabled" attribute disables an enabled form element.
            (&local_name!("disabled"), AttributeMutation::Set(_))
                if self.is_form_associated_custom_element() && element.enabled_state() =>
            {

Review comment (suggestion):
The test times out because it relies on setting `onanimationstart`, which is not listed in EventTarget::is_content_event_handler. It's defined in the spec at https://drafts.csswg.org/css-animations/#event-handlers-on-elements-document-objects-and-window-objects .

Code after:
        // Step 3: Replace data with node, node's data's length, 0, and next's data.
        let node_chars = node.downcast::<CharacterData>().expect("Node is Text");
        let next_chars = next.downcast::<CharacterData>().expect("Next node is Text");
        node_chars
            .ReplaceData(node_chars.Length(), 0, next_chars.Data())
            .expect("Got chars from Text");

        // Step 4:Remove next.
        next.remove_self(can_gc);
    }
}

impl VirtualMethods for HTMLElement {
    fn super_type(&self) -> Option<&dyn VirtualMethods> {
        Some(self.as_element() as &dyn VirtualMethods)
    }

    fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation, can_gc: CanGc) {
        self.super_type()
            .unwrap()
            .attribute_mutated(attr, mutation, can_gc);
        let element = self.as_element();
        match (attr.local_name(), mutation) {
            // https://html.spec.whatwg.org/multipage/#event-handler-attributes:event-handler-content-attributes-3
            (name, mutation)
                if name.starts_with("on") && EventTarget::is_content_event_handler(name) =>
            {
                let evtarget = self.upcast::<EventTarget>();
                let event_name = &name[2..];
                match mutation {
                    // https://html.spec.whatwg.org/multipage/#activate-an-event-handler
                    AttributeMutation::Set(_) => {
                        let source = &**attr.value();
                        let source_line = 1; // TODO(#9604) get current JS execution line
                        evtarget.set_event_handler_uncompiled(
                            self.owner_window().get_url(),
                            source_line,
                            event_name,
                            source,
                        );
                    },
                    // https://html.spec.whatwg.org/multipage/#deactivate-an-event-handler
                    AttributeMutation::Removed => {
                        evtarget.remove_event_listener(
                            event_name.into(),
                            evtarget.get_event_handler_common(event_name, can_gc),
                            EventListenerOptions { capture: false },
                        );
                    },
                }
            },