Skip to content

Automatically generate list of all implemented event handler attribute names #43611

@jdm

Description

@jdm

static CONTENT_EVENT_HANDLER_NAMES: LazyLock<FxHashSet<&str>> = LazyLock::new(|| {

It feels like there is an easy footgun of implementing a unique event handler in some interface and forgetting to update the list.

We should be able to add a new entry to

for name, filename in [
that generates that list for us instead. We would need to:

  1. Iterate over all descriptors
  2. Ignore any descriptor without isInterface()
  3. Iterate over descriptor.interface.members
  4. Ignore any member that is not isAttr()
  5. Ignore any member where member.type is not isInterface() or member.type.identifier.name is not EventHandler
  6. Add member.identifier.name to the list of content event handlers

After all descriptors have been checked generate identical code to the hand-written code, and use the generated code from eventtarget.rs.

and
def DomTypeHolder(descriptors: list[Descriptor],
are examples of how similar code generation is implemented.

Metadata

Metadata

Assignees

Labels

A-content/bindingsThe DOM bindingsE-more-complexVariable effort required; may require a mentor. Recommended solution is clearly described in the issL-pythonPython is required

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions