05:58
<sideshowbarker>

Why does the HTML spec fire some events without their defined constructor?

What I means is: When specifying firing of events, in some places in the spec it states the event constructor with “using”, like this:

fire an event named hashchange at document's relevant global object, using HashChangeEvent

…and in other places it’s stated without “using”

fire an event named input at the element, with the bubbles and composed attributes initialized to true.

So given that, when that input event is fired, the Event constructor is used — because the caller doesn’t have a “using” statement.

But the input event have an InputEvent constructor defined in the UI Events spec at https://w3c.github.io/uievents/#inputevent. Why doesn’t the HTML spec state that constructor must be used when firing the input event?

06:53
<Ms2ger>
sideshowbarker: the default is Event - are you sure these cases use InputEvent in practice? (https://dom.spec.whatwg.org/#firing-events)
07:38
<zcorpan>
sideshowbarker: https://software.hixie.ch/utilities/js/live-dom-viewer/saved/13038 - I suppose InputEvent is used for inputting text, and Event is used for other cases
07:48
<sideshowbarker>

No, I wasn’t sure — it just seemed odd that https://html.spec.whatwg.org/#text-(type=text)-state-and-search-state-(type=search):user-interaction-task-source has this:

Queue an element task on the user interaction task source given the element to fire an event named input at the element, with the bubbles and composed attributes initialized to true.

…where input is a link to the UI events definition of an input event with an InputEvent. But then despite that, the spec doesn’t state the event must be constructed with that InputEvent interface

07:50
<Ms2ger>
Ugh, that's needlessly confusing. https://html.spec.whatwg.org/multipage/indices.html#events-2 does say it uses Event, though
07:51
<Ms2ger>
Seems worth an issue
09:02
<arai>
https://html.spec.whatwg.org/#fetching-and-processing-a-resource-from-a-link-element says "They also have linked resource fetch setup steps which ..., but unless explicitly stated, they use the default fetch and process the linked resource algorithm.". How can I see which (or what kind of) case uses the "default" one and which case doesn't? Is there a list of "non-default" cases? I'm currently trying to figure out how <link rel="stylesheet" ...> interacts with cache, and investigating how things work in general as a first step.
09:05
<arai>
oh, looks like clicking the " linked resource fetch setup steps" text shows a popup with references, and there are 3 cases (icon/manifest/stylesheet) listed. is that all? or can there be any other cases?
09:06
<annevk>
arai: that should be exhaustive
09:07
<arai>
okay, thank you :D
09:27
<sideshowbarker>

So I notice that the Event code in WebKit sets isTrusted (to true by default) in the Event constructor — despite the DOM spec making a clear distinction between the “constructing an event” operation and the “creating an event” operation. And the spec states that that isTrusted is set to true in the “creating an event” operation, not in the “constructing an event” operation.

Nevertheless, it’d seem like the observable behavior in WebKit must be conforming to the spec — since WebKit passes whatever the relevant tests in WPT are.

So… Is it actually expected that setting isTrusted in the Event constructor will have the same observable effect at setting in the implementation of the “create an event” operation? And if so, the separation about where isTrusted is set is something that exists in the spec for some reason but doesn’t actually get exercised in practice by all calling operations?

09:28
<sideshowbarker>
Relevant part of the DOM spec is https://dom.spec.whatwg.org/#constructing-events
09:31
<sideshowbarker>
I ask this because I have found that in writing a new implementation, it‘s a lot easier, implementation-wise, to set isTrusted in the code for the Event::Event constructor than it is to set in and Event::create code (“create an event” operation) — which I can imagine is the reason why WebKit implemented that way
09:33
<sideshowbarker>
Though I can also imagine it was implemented that way in WebKit in a time long ago — and maybe before this separation between the operations existed in the DOM spec, which perhaps got added later
09:36
<zcorpan>
I think it's not observable
09:36
<sideshowbarker>
OK
09:37
<annevk>
https://software.hixie.ch/utilities/js/live-dom-viewer/?%3Cscript%3E%0Aw(new%20Event(%27x%27).isTrusted)%0A%3C%2Fscript%3E shows it as false, so I suspect what WebKit does is a bit more involved.
09:37
<sideshowbarker>
It’s false for synthetic events
09:38
<sideshowbarker>
So in cases where it‘s false in WebKit, the calling code must be setting it to false when constructing
09:38
<annevk>
Not sure what you mean by constructor if that case doesn't cover it.
09:42
<sideshowbarker>
I guess I could step through it in a debugger in a WebKit build and see
09:46
<sideshowbarker>
But to put more a bit more context on why I’m asking: For Ladybird, because the project has a policy that the spec requirements should be followed as closely as possible: I’m trying to decide if I should try to implement it strictly the way the spec states it happens — in the “create an event” operation — whether there’s some observable benefit to implementing it that way vs the additional cost/complication which comes from following the spec strictly in this case
09:52
<sideshowbarker>
And I mean, assuming I figure out how to get new Event('x') to end up setting isTrusted to false, the way WebKit manages to
09:54
<annevk>
static Ref<Event> create(const AtomString& type, const EventInit&, IsTrusted = IsTrusted::No); What makes you think it defaults to true?
10:41
<sideshowbarker>

Because in the constructor code at https://github.com/WebKit/WebKit/blob/e4d6852ee20ff3dfcd3a59fe241d84f662abb234/Source/WebCore/dom/Event.cpp#L45-L55 I see:

, m_isTrusted { isTrusted == IsTrusted::Yes }

…and the create signatures I see are:

Ref<Event> Event::create(const AtomString& type, CanBubble canBubble, IsCancelable isCancelable, IsComposed isComposed)
{
    return adoptRef(*new Event(EventInterfaceType::Event, type, canBubble, isCancelable, isComposed));
}

…so if that’s called, then it defaults to IsTrusted::Yes

And then the other create signature is:

Ref<Event> Event::create(const AtomString& type, const EventInit& initializer, IsTrusted isTrusted)
{
    return adoptRef(*new Event(EventInterfaceType::Event, type, initializer, isTrusted));
}

…for callers that need to set IsTrusted::No

11:08
<annevk>
There are indeed various defaults so it depends which internal constructor you call. However, note that m_isTrusted { isTrusted == IsTrusted::Yes } is not setting a default. It just sets m_isTrusted to whatever the value of isTrusted is. It's a way to convert from a class enum to a boolean.
11:19
<sideshowbarker>
I see
16:39
<Domenic>
Luca Casonato: regarding https://github.com/whatwg/html/pull/10593 , how does tihs interact with the closebehavior/closedby etc. proposed for https://github.com/whatwg/html/issues/9373 ?
16:39
<Domenic>
I guess I should ask this question on the issue since I am about to go to lunch
18:52
<Dominic Farolino>
Domenic: I've got a question about this line right here: https://streams.spec.whatwg.org/#readable-stream-from-iterable:~:text=Let%20nextPromise%20be%20a%20promise%20resolved%20with%20nextResult.%5B%5BValue%5D%5D. nextResult.[[Value]] is expected to be a Promise, right? But we wrap it in a Promise just in case it's not a Promise, so that reacting to it is always async? Is that right?
19:06
<Domenic>
I believe that's right. That sort of wrapping is pretty pervasive when dealing with potentially-user code.