Re: [whatwg/dom] Missing machinery for associated Event data (Issue #1328)

domenic left a comment (whatwg/dom#1328)

Here is a start of a concrete proposal:

- All events have an "init properties" map. Its keys are properties of the event interface.
- We create a new Web IDL extended attribute, in the DOM spec, which auto-generates getter steps.
  - Maybe call it `[FromEventInit]`
  - The getter steps just return the appropriate value from the event's init properties map.
  - It's fine for non-Web IDL specs to create extended attributes. HTML does it a few times.
- [Fire an event](https://dom.spec.whatwg.org/#concept-event-fire) should be updated slightly:
  - Instead of "with its `detail` attribute initialized to 1", callers should say "with `detail` initialized to 1". (The important thing is to stop saying "attribute", since we're now talking about how we set the init properties map, instead of how we set the attribute.)
  - All talk of initializing attributes can be updated to talk about changing the init properties map.
- We should add a helper in DOM for setting values of the init properties map, just for brevity and better abstraction.
  - E.g. "**Initialize** _event_'s `detail` to 1 and its `screenX` to 5."
  - Again, avoid the word "attribute".
- We update everything in DOM which initializes attributes to use this new abstraction.
- We update every spec that defines, creates, dispatches, and fires events to use this new interface.
- Bonus: we can fix #600 like so:
  - Instead of step 2 of [create an event](https://dom.spec.whatwg.org/#concept-event-create) converting undefined, we can do something more complicated like looping through all the non-required members and converting undefined to their type.
  - We can add an assert in the `[FromEventInit]` getter steps that the init properties map entry exists. This assert basically fires if the spec author creates an event with required members in its event init dictionary, and fails to set the init properties map.

In this world, things like `ToggleEvent`'s `source` would *not* use `[FromEventInit]`, and would instead define custom getter steps which retarget this's init properties[`source`]. But otherwise, directly accessing the init properties map would be very rare.

The con of this approach is that it requires updating basically every spec that uses events. But I think that's kind of hard to avoid.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1328#issuecomment-2918414185
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1328/2918414185@github.com>

Received on Thursday, 29 May 2025 06:12:47 UTC