-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix event handler processing algorithm to match implementations #2398
Conversation
6d53911
to
8555352
Compare
Follows whatwg/html#2398; see also whatwg/html#2296.
FYI for anyone watching, this PR morphed from something about only the mouseover behavior to cover both mouseover and error and a number of editorial fixes; separate PRs ended up just being a bunch of conflicts. I've edited the OP to reflect this change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same nit twice, and I think that a test like https://github.com/w3c/web-platform-tests/pull/5014/files#r104584793 would be able to tease out whether the type matters or not.
No need to wait for more review if I'm just confused/wrong.
source
Outdated
handling</var> be false.</p> | ||
|
||
<p class="note">In this case, <var>E</var>'s <code data-x="dom-Event-type">type</code> will | ||
always be <code data-x="event-error">error</code>.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to figure out why this holds true. Synthetic events can reach this code path, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A synthetic event with a different name cannot trigger onerror
though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p class="note">The <span data-x="event handler IDL attributes">event handler IDL | ||
attribute</span>'s type is <code>OnBeforeUnloadEventHandler</code>, and the <var>return | ||
<p class="note">This can only occur when <var>E</var>'s <code | ||
data-x="dom-Event-type">type</code> is <code data-x="event-beforeunload">beforeunload</code> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too I don't see why this holds with synthetic events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't.
This should be checking the type of the callback, not the type of the event, if it wants the guarantees about return type.
I added a clarification commit and also updated the tests in response to review feedback. I'd appreciate a look at the clarification commit especially before merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, my confusion is now resolved. Seems obvious in hindsight, but I'm happy I've not been the only one to wonder.
Some minimal tweaking around "producing" perhaps, but no need to ask for another round of review if you're confident about it.
source
Outdated
|
||
<p class="note">In this case, <var>E</var>'s <code data-x="dom-Event-type">type</code> will | ||
always be <code data-x="event-error">error</code>, since the only <span data-x="event | ||
handlers">event handler</span> that produces <code>ErrorEvent</code> instances is <code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does it mean for an event handler to produce an ErrorEvent
instance? This bit I failed to notice before is that we're inside an algorithm that only applies to event handlers, where the event type is part of the name.
This and the other note would make perfect sense to me if only that connection is called out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Event handlers consume, not produce event instances. The thing that produces them is event constructors, and they can construct any event interface with any event type.
source
Outdated
data-x="dom-Event-type">type</code> is <code data-x="event-beforeunload">beforeunload</code> | ||
and when the <span data-x="event handler IDL attributes">event handler IDL attribute</span>'s | ||
type is <code>OnBeforeUnloadEventHandler</code>, since the only <span data-x="event | ||
handlers">event handler</span> that produces <code>BeforeUnloadEvent</code> instances is <code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too, it seems like something else is producing the instance:
https://html.spec.whatwg.org/#prompt-to-unload-a-document
Do you have a better word for the connection? I went with "producing" because it's not well-defined. Maybe "the only event handler that is called with BeforeUnloadEvent instances is..."? |
* Remove the special cancelation behavior for onmouseover. This was only ever implemented by Gecko. Fixes #423 in part. * Update the special cancelation and argument behavior for onerror to a reasonable set of intersection semantics among current implementations. This fixes #2296, and fixes the rest of #423. See especially #2296 (comment). * Editorial: links directly to Web IDL's definition of "invoke" instead of indirecting. * Editorial: clarifies that BeforeUnloadEvents always have type "beforeunload", instead of making that part of the conditional.
be3da0f
to
ce23bf2
Compare
handling</var> be false.</p> | ||
|
||
<p class="note">In this case, <var>E</var>'s <code data-x="dom-Event-type">type</code> will | ||
always be <code data-x="event-error">error</code>, since the only <span data-x="event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true. Simple testcase:
<script>
window.onclick = function() { alert('hey'); }
window.dispatchEvent(new ErrorEvent("click"));
</script>
There seems to be some confusion here between event types (which are intimately related to which on* attribute we're dealing with here) and event interfaces, which are completely unrelated.
You really do want to check for both ErrorEvent and the event type being "error" and the current target being the right sort, however you do that.
The way Gecko does this is that the "onerror" property has the type "OnErrorEventHandler" only on Window and WorkerGlobalScope, and the equivalent of this algorithm checks the type of the callback we have. Explicitly saying to check the current target and having it be OnErrorEventHandler everywhere is probably black-box identical to that, though.... That's worth double-checking.
source
Outdated
|
||
<p class="note">In this case, <var>E</var>'s <code data-x="dom-Event-type">type</code> will | ||
always be <code data-x="event-error">error</code>, since the only <span data-x="event | ||
handlers">event handler</span> that produces <code>ErrorEvent</code> instances is <code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Event handlers consume, not produce event instances. The thing that produces them is event constructors, and they can construct any event interface with any event type.
<p class="note">The <span data-x="event handler IDL attributes">event handler IDL | ||
attribute</span>'s type is <code>OnBeforeUnloadEventHandler</code>, and the <var>return | ||
<p class="note">This can only occur when <var>E</var>'s <code | ||
data-x="dom-Event-type">type</code> is <code data-x="event-beforeunload">beforeunload</code> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't.
This should be checking the type of the callback, not the type of the event, if it wants the guarantees about return type.
the value is instead used to determine whether or not to prompt about unloading the document.</p> | ||
<div class="note"> | ||
<p>The return value of the function affects whether the event is canceled or not: <span | ||
w-nodev>as described above, </span>if the return value is false, the event is canceled.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Span should end right after comma?
Argh. I just missed you merging this. :( Anyway, what got merged is totally nonsensical, unfortunately, @foolip was right. Please fix. |
@domenic see above. |
Thank you for your vigilance @bzbarsky. I'm really embarassed I missed this because we actually do have tests for the |
Right, the tests all make sense. It's the spec that doesn't. ;) |
I guess we don't have tests for the |
For the beforeunload case though, I can't find a counterexample, because it's impossible to create BeforeUnloadEvent instances. The UA is the only one that does so, and the only event handler that will see them is onbeforeunload. |
Follows whatwg/html#2398; see also whatwg/html#2296.
This is a follow-up to 7163372, which forgot about the case of new ErrorEvent("click", ...), as noted in #2398 (comment).
Oh, BeforeUnloadEvent has no constructor? I wonder why not. Do we want to depend on it not growing one? |
Probably because it's kind of an evil event? Meh, not a great reason. I'll update #2428 to check both but note that the check is technically redundant. |
Oh, wait, lol, createEvent("beforeunload") will work, I think... more tests to write. |
This is a follow-up to 7163372, which forgot about the case of ErrorEvents with a non-"error" event type, or BeforeUnloadEvents with a non-"beforeunload" event type, as noted in #2398 (comment).
Is this ready for review again? The use of "producing" is gone, so that issue's gone. |
It got merged, then fixed up in #2428 :) |
Oops, thanks :) |
This is a follow-up to 7163372, which forgot about the case of ErrorEvents with a non-"error" event type, or BeforeUnloadEvents with a non-"beforeunload" event type, as noted in whatwg#2398 (comment).
ever implemented by Gecko. Fixes Consider removing special cancellation behaviour for event handlers #423 in part.
reasonable set of intersection semantics among current
implementations. This fixes Sort out the OnErrorEventHandler mess #2296, and fixes the rest of Consider removing special cancellation behaviour for event handlers #423. See
especially
Sort out the OnErrorEventHandler mess #2296 (comment).
of indirecting.
"beforeunload", instead of making that part of the conditional.
/cc @jdm @bzbarsky
Tests: