I were wondered to look into mechanism of event invocation, so as usual I went to whatwg specification.
For performing callback function of event's listener, spec does the following:
It would be simple to understand how dispatching mechanism works if inner invoke was called by once. But there is case that I can't understand and this case calls inner invoke twice. What is that case?
Part of whatwg spec invoke algorithm:
Let found be the result of running inner invoke with event, listeners, phase, invocationTargetInShadowTree, and legacyOutputDidListenersThrowFlag if given.
If found is false and event’s isTrusted attribute is true, then:
- Inner invoke with event, listeners, phase, invocationTargetInShadowTree, and legacyOutputDidListenersThrowFlag if given.
What is the sense of invocation inner invoke twice? I remind, inner invoke calls function callback of event's listener
CodePudding user response:
I remind, inner invoke calls function callback of event's listener
Only if it returns true
(found
is true
within inner invoke
), but Step 9 clearly only runs when the first call returned false
, meaning that Step 2 of inner invoke
didn't iterate even once (no listener matched "For each listener in listeners, whose removed is false"):
Let found be false.
For each listener in listeners, whose removed is false:
If event’s type attribute value is not listener’s type, then continue.
Set found to true.
...
- Return found.
(My emphasis)
Separately, in your quotes you've left out an important part of invoke
, which is that it changes the type
(Step 2) before the second call to inner invoke
. Which makes the sequence make a lot more sense: First it does an inner invoke
with the original type (for instance, animationend
), then if no listeners were found, it tries again with an adjusted type (for instance, webkitAnimationEnd
).