Skip to content

Formalize the concept of "If any event listeners were triggered" #3646

@gterzian

Description

@gterzian

Problem:

Both unload(see step 9) and prompt to unload(see step 7) mention "If any event listeners were triggered by the earlier dispatch step, then set document's salvageable state to false.", without further specifying what "any event listeners were triggered" means or how it fits in other parts of the (DOM)spec.

This creates some uncertainty around implementing "unload" and "prompt to unload", because it seems unclear how, and when, an event is to be "marked as handled" in some way so as to allow the salvageable state of the document to be determined. It seems to requires a kind of "hack" as part of https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke (see for example: servo/servo#20329 (comment))

It also seems that implementations require some sort of 'handled' flag in practice, for example in servo, we ended up with a canceled attribute of Event that can be either Allowed, Prevented, or Handled, which seems to conflate the concept of the 'canceled' flag with an unspecified 'handled' flag.

Proposed solution:

I propose to clarify, and simplify, this with a new handled flag on event, that could be added to the current list at https://dom.spec.whatwg.org/#canceled-flag, and which would be set after step 2.7 of https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke (or perhaps as a final step 6 of https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm) (I'll refile in https://github.com/whatwg/dom/ if this makes sense)

Then unload(step 9) could read "If the unload's event handled flag is set..."

and prompt to unload(step 7) "If the beforeunload's event handled flag is set..."

(or perhaps "If the event dispatched in the previous step <dfn>was handled</dfn>..." with a link to the DOM spec explaining the concept(the handled flag being set)?

If this is too heavy handed, perhaps at least add a non-normative section explaining the concept of "any event listeners were triggered" and referring to the DOM for hints of how the concept can be implemented?

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions