Skip to content
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

Merged
merged 3 commits into from
Mar 9, 2017

Conversation

domenic
Copy link
Member

@domenic domenic commented Feb 24, 2017

/cc @jdm @bzbarsky

Tests:

domenic added a commit to web-platform-tests/wpt that referenced this pull request Feb 24, 2017
@domenic domenic changed the title Remove special cancelation behavior for mouseover Fix event handler processing algorithm to match implementations Feb 24, 2017
domenic added a commit to web-platform-tests/wpt that referenced this pull request Feb 24, 2017
@domenic
Copy link
Member Author

domenic commented Feb 24, 2017

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.

Copy link
Member

@foolip foolip left a 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>
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do distinctly remember asking myself the same question @foolip asked, and then only later rediscovering that the reason was because of what @annevk said. In fact I think I did that multiple times. Let me try to make it clearer in both notes.

<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>
Copy link
Member

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.

Copy link
Contributor

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.

@domenic
Copy link
Member Author

domenic commented Mar 7, 2017

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.

Copy link
Member

@foolip foolip left a 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
Copy link
Member

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.

Copy link
Contributor

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
Copy link
Member

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

@domenic
Copy link
Member Author

domenic commented Mar 8, 2017

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.
@domenic domenic merged commit 7163372 into master Mar 9, 2017
@domenic domenic deleted the rm-special-mouseover branch March 9, 2017 19:30
domenic added a commit to web-platform-tests/wpt that referenced this pull request Mar 9, 2017
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
Copy link
Contributor

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
Copy link
Contributor

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>
Copy link
Contributor

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>
Copy link
Contributor

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?

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

Argh. I just missed you merging this. :(

Anyway, what got merged is totally nonsensical, unfortunately, @foolip was right. Please fix.

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

@domenic see above.

@domenic
Copy link
Member Author

domenic commented Mar 9, 2017

Thank you for your vigilance @bzbarsky. I'm really embarassed I missed this because we actually do have tests for the new Event("error", ...) case in web-platform-tests/wpt#5014.

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

Right, the tests all make sense. It's the spec that doesn't. ;)

@domenic
Copy link
Member Author

domenic commented Mar 9, 2017

I guess we don't have tests for the new ErrorEvent("click", ...) case. I'll be sure to do those as a follow-up.

@domenic
Copy link
Member Author

domenic commented Mar 9, 2017

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.

domenic added a commit to web-platform-tests/wpt that referenced this pull request Mar 9, 2017
domenic added a commit that referenced this pull request Mar 9, 2017
This is a follow-up to 7163372, which
forgot about the case of new ErrorEvent("click", ...), as noted in
#2398 (comment).
@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

Oh, BeforeUnloadEvent has no constructor? I wonder why not. Do we want to depend on it not growing one?

@domenic
Copy link
Member Author

domenic commented Mar 9, 2017

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.

@domenic
Copy link
Member Author

domenic commented Mar 9, 2017

Oh, wait, lol, createEvent("beforeunload") will work, I think... more tests to write.

domenic added a commit that referenced this pull request Mar 15, 2017
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).
@foolip
Copy link
Member

foolip commented Mar 21, 2017

Is this ready for review again? The use of "producing" is gone, so that issue's gone.

@domenic
Copy link
Member Author

domenic commented Mar 21, 2017

It got merged, then fixed up in #2428 :)

@foolip
Copy link
Member

foolip commented Mar 21, 2017

Oops, thanks :)

alice pushed a commit to alice/html that referenced this pull request Jan 8, 2019
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Sort out the OnErrorEventHandler mess Consider removing special cancellation behaviour for event handlers
4 participants