Open Bug 1845422 Opened 1 year ago Updated 1 year ago

Reverse the order of the calls to IsEventAttributeName and GetEventNameForAttr, to simplify some code

Categories

(Core :: DOM: Events, task)

task

Tracking

()

People

(Reporter: mstange, Unassigned)

Details

In EventNameList.h, we list some events solely so that <div onblah="..."> passes the "attribute is event handler" check:

https://searchfox.org/mozilla-central/rev/3c7b40d1d74c26a82486f38b5828c3f3a43e05da/dom/events/EventNameList.h#529-542

#ifndef MESSAGE_TO_EVENT
// These are only here so that IsEventAttributeName() will return the right
// thing for these events.  We could probably remove them if we used
// Element::GetEventNameForAttr on the input to IsEventAttributeName before
// looking it up in the hashtable...
EVENT(webkitanimationend, eUnidentifiedEvent, EventNameType_All,
      eAnimationEventClass)
EVENT(webkitanimationiteration, eUnidentifiedEvent, EventNameType_All,
      eAnimationEventClass)
EVENT(webkitanimationstart, eUnidentifiedEvent, EventNameType_All,
      eAnimationEventClass)
EVENT(webkittransitionend, eUnidentifiedEvent, EventNameType_All,
      eTransitionEventClass)
#endif

https://searchfox.org/mozilla-central/rev/3c7b40d1d74c26a82486f38b5828c3f3a43e05da/dom/html/nsGenericHTMLElement.cpp#714-724

void nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
                                        const nsAttrValue* aValue,
                                        const nsAttrValue* aOldValue,
                                        nsIPrincipal* aMaybeScriptedPrincipal,
                                        bool aNotify) {
  if (aNamespaceID == kNameSpaceID_None) {
    if (IsEventAttributeName(aName) && aValue) {
      MOZ_ASSERT(aValue->Type() == nsAttrValue::eString,
                 "Expected string value for script body");
      SetEventHandler(GetEventNameForAttr(aName), aValue->GetStringValue());
    } else if (aNotify && aName == nsGkAtoms::spellcheck) {

This bug is for making the change suggested in the comment: First, check if the attribute name starts with "on". If it does, call GetEventNameForAttr to map it to an event name. Then, call IsEventAttributeName, which at that point it should be renamed to IsEventTypeAtom.

This pattern is used in a bunch of different places.

You need to log in before you can comment on or make changes to this bug.