Bug 234254 - Automatically generate event handler content attribute maps so they are easier to maintain
Summary: Automatically generate event handler content attribute maps so they are easie...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-12-13 11:10 PST by Darin Adler
Modified: 2021-12-15 13:04 PST (History)
14 users (show)

See Also:


Attachments
Patch (31.15 KB, patch)
2021-12-13 13:59 PST, Darin Adler
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (31.16 KB, patch)
2021-12-13 14:33 PST, Darin Adler
ashvayka: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (31.24 KB, patch)
2021-12-13 18:22 PST, Darin Adler
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2021-12-13 11:10:57 PST
Automatically generate event handler content attribute maps so they are easier to maintain
Comment 1 Darin Adler 2021-12-13 13:59:09 PST Comment hidden (obsolete)
Comment 2 Darin Adler 2021-12-13 14:33:37 PST
Created attachment 447067 [details]
Patch
Comment 3 Alexey Shvayka 2021-12-13 14:41:25 PST
Comment on attachment 447061 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=447061&action=review

Thank you for addressing this issue, Darin!

> Source/WebCore/html/HTMLElement.cpp:64
> +#include "JSHTMLElement.h"

Currently, we have event handler name map on HTMLElement, which is not quite right. GlobalEventHandlers are shared beyond HTML, like for example `SVGElement includes GlobalEventHandlers`. Moving the handlers down to JSHTMLElement.h doesn't seem like a direction I would prefer. It doesn't feel right to store them on any wrapper.

Do you think generating them into a separate file in preprocess-idls.pl would be more preferred approach? It would also let us avoid adding extended attributes like GenerateForEachEventHandlerContentAttribute.
Comment 4 Darin Adler 2021-12-13 14:57:02 PST
(In reply to Alexey Shvayka from comment #3)
> Currently, we have event handler name map on HTMLElement, which is not quite
> right. GlobalEventHandlers are shared beyond HTML, like for example
> `SVGElement includes GlobalEventHandlers`. Moving the handlers down to
> JSHTMLElement.h doesn't seem like a direction I would prefer. It doesn't
> feel right to store them on any wrapper.
> 
> Do you think generating them into a separate file in preprocess-idls.pl
> would be more preferred approach?

Sure, I suppose it would be OK, but adding more generated files will be more complex. We might even need to change the IDL parser around.

I think you, or someone else, should feel free to move this later, but I chose what I thought would be expedient, and I feel good about my choice. My patch is much smaller because I took advantage of what we already have.

I have a hard time finding any practical problem with this solution, or advantage to a more correct one. But if there is one I would welcome the improvement.

> It would also let us avoid adding extended
> attributes like GenerateForEachEventHandlerContentAttribute.

But it would do that by requiring that we hard code the name GlobalEventHandlers somewhere?

One of the good things in practice about what I did is how easy it was to reuse for HTMLBodyElement and the window event handlers.
Comment 5 Alexey Shvayka 2021-12-13 15:43:37 PST
Comment on attachment 447067 [details]
Patch

(In reply to Darin Adler from comment #4)
> (In reply to Alexey Shvayka from comment #3)
> > It would also let us avoid adding extended
> > attributes like GenerateForEachEventHandlerContentAttribute.
> 
> But it would do that by requiring that we hard code the name
> GlobalEventHandlers somewhere?

Yes, and I would argue that is a good thing. Currently, GenerateForEachEventHandlerContentAttribute considers all EventHandlers to be of GlobalEventHandlers & DocumentAndElementEventHandlers. In practice that's fine because SVGElement / MathMLElement are consistent.

> One of the good things in practice about what I did is how easy it was to
> reuse for HTMLBodyElement and the window event handlers.

preprocess-idls.pl solution would just gather all [WindowEventHandler] handlers when looping through interfaces, avoiding a bit weird call stacks like HTMLFrameSetElement::parseAttribute() => HTMLBodyElement::eventNameForWindowEventHandlerAttribute() => JSHTMLBodyElement::forEachEventHandlerContentAttribute().

> (In reply to Alexey Shvayka from comment #3)
> > Currently, we have event handler name map on HTMLElement, which is not quite
> > right. GlobalEventHandlers are shared beyond HTML, like for example
> > `SVGElement includes GlobalEventHandlers`. Moving the handlers down to
> > JSHTMLElement.h doesn't seem like a direction I would prefer. It doesn't
> > feel right to store them on any wrapper.
> > 
> > Do you think generating them into a separate file in preprocess-idls.pl
> > would be more preferred approach?
> 
> Sure, I suppose it would be OK, but adding more generated files will be more
> complex. We might even need to change the IDL parser around.
> 
> I think you, or someone else, should feel free to move this later, but I
> chose what I thought would be expedient, and I feel good about my choice. My
> patch is much smaller because I took advantage of what we already have.
> 
> I have a hard time finding any practical problem with this solution, or
> advantage to a more correct one. But if there is one I would welcome the
> improvement.

All true points, preprocess-idls.pl solution is a different time contribution w/o added practical benefit, only slightly improving visual similarity of our code with the spec.
Comment 6 Darin Adler 2021-12-13 17:16:46 PST
Oops, not passing tests. I need to check!
Comment 7 Darin Adler 2021-12-13 18:08:54 PST
(In reply to Alexey Shvayka from comment #5)
> > But it would do that by requiring that we hard code the name
> > GlobalEventHandlers somewhere?
> 
> Yes, and I would argue that is a good thing. Currently,
> GenerateForEachEventHandlerContentAttribute considers all EventHandlers to
> be of GlobalEventHandlers & DocumentAndElementEventHandlers. In practice
> that's fine because SVGElement / MathMLElement are consistent.

Sure, that sounds fine. I suppose GlobalEventHandlers can be in a list just like all the element classes are in a list, in the build system, but sad that we already have to have so many special lists like that.

> preprocess-idls.pl solution would just gather all [WindowEventHandler]
> handlers when looping through interfaces, avoiding a bit weird call stacks
> like HTMLFrameSetElement::parseAttribute() =>
> HTMLBodyElement::eventNameForWindowEventHandlerAttribute() =>
> JSHTMLBodyElement::forEachEventHandlerContentAttribute().

Sure, avoiding the strange call stacks is good. But collecting all [WindowEventHandler] from all IDL files sounds very strange. If this doesn’t come from a particular named interface, like GlobalEventHandlers, then it seems like we’d want some logic about which interfaces we’d look at, and why. Doesn’t make sense that if we labeled something with [WindowEventHandler] in another interface that HTMLBodyElement and HTMLFrameSetElement would just both sprout content event handlers for those automatically.

> All true points, preprocess-idls.pl solution is a different time
> contribution w/o added practical benefit, only slightly improving visual
> similarity of our code with the spec.

I think it’s fine to improve later. Glad you are OK with me landing this now (once I debug it and figure out why it’s doing the wrong thing). I could even write a FIXME about how this is slightly illogical but expedient.
Comment 8 Darin Adler 2021-12-13 18:22:45 PST
Created attachment 447092 [details]
Patch
Comment 9 EWS 2021-12-14 02:30:38 PST
Committed r287019 (245224@main): <https://commits.webkit.org/245224@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 447092 [details].
Comment 10 Radar WebKit Bug Importer 2021-12-14 02:31:17 PST
<rdar://problem/86458873>
Comment 11 Sam Weinig 2021-12-15 13:04:24 PST
Very nice.