Home > Net >  Invoke calls Inner Invoke twice
Invoke calls Inner Invoke twice

Time:09-05

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:

  1. dispatch
  2. invoke
  3. inner invoke

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:

  1. Let found be the result of running inner invoke with event, listeners, phase, invocationTargetInShadowTree, and legacyOutputDidListenersThrowFlag if given.

  2. If found is false and event’s isTrusted attribute is true, then:

    1. 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"):

  1. Let found be false.

  2. For each listener in listeners, whose removed is false:

    1. If event’s type attribute value is not listener’s type, then continue.

    2. Set found to true.

...

  1. 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).

  • Related