Search code examples
javascripteventsdom-eventsspecificationsw3c

How to understand the event which not dispatched by task queue in event loop of spec?


In the spec:

Not all events are dispatched using the task queue, many are dispatched during other tasks.

I want to know the "many" and the "other tasks" above refer to what?


Solution

  • If you search the HTML spec for the phrase “fire an event”, you’ll see cases it says “queue a task to fire an event” and places it just says ”fire an event“ without “queue a task”. For example:

    Each document has a current document readiness. … When the value is set, the user agent must fire an event named readystatechange at the Document object.

    Compare that language above to the language in the following spec excerpt:

    … the user agent must, if the loads were successful, queue a task to fire an event named load at the link element

    So when the spec instead of saying “queue a task to fire an event” just says “fire an event”, then the event doesn’t go into the task queue but instead must essentially be fired synchronously.