-
Notifications
You must be signed in to change notification settings - Fork 294
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
Add window.event as a legacy compat requirement #407
Conversation
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 looks good. I think I'd prefer adding all the Microsoft extensions at the same time, so we have only one bug report per browser (if needed). Landing them quickly one after another seems okay though.
dom.bs
Outdated
@@ -570,6 +571,9 @@ algorithm below. | |||
<dt><code><var>event</var> . {{Event/target}}</code> | |||
<dd>Returns the object to which <var>event</var> is <a>dispatched</a>. | |||
|
|||
<dt><code><var>event</var> . {{Event/srcElement}}</code> | |||
<dd>Returns <var>event</var>'s {{Event/target}} attribute value. |
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.
No need to add it here since developers can just use target.
dom.bs
Outdated
@@ -642,6 +646,9 @@ attributes must return the values they were initialized to. When an | |||
<a>event</a> is created the attributes must be | |||
initialized to null. | |||
|
|||
The <dfn attribute for=Event><code>srcElement</code></dfn> | |||
attribute must return the {{Event/target}} attribute value. |
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'd prefer to define it together with target. So "The target and srcElement attributes must return X".
That cool. I'll use this PR to add in the other bits and update the title accordingly. |
48b006f
to
522acb5
Compare
@annevk I guess HTML is already overloading https://html.spec.whatwg.org/multipage/browsers.html#the-beforeunloadevent-interface |
I don't think so. @domenic would know. The current text looks good to me, but it's also starting to show that we don't use internal slots to back the event attributes. As now we have to initialize two attributes rather than a single slot that backs both of them. You're still planning on adding |
No need to do anything else, yeah. |
Thats a perfect sort of thing |
Yeah, just doing commits + tests piecemeal. That's next. |
dom.bs
Outdated
attribute must be initialized to true when an <a>event</a> is created. | ||
When the attribute is set to false it must set the <a>canceled flag</a> if the | ||
{{Event/cancelable}} attribute value is true and the | ||
<a>in passive listener flag</a> is unset. |
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.
Do implementations update returnValue if the event gets canceled by e.g. preventDefault()?
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 notification got swallowed by my inbox, will look into this tomorrow)
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.
@domenic yeah, Safari, Chrome and Edge do:
https://miketaylr.com/bzla/canceled-returnValue.html
So we need to add a getter that returns if the canceled flag is set, and false otherwise.
0c8d9b9
to
e7cdac7
Compare
@annevk @hayatoito could you check the Thanks. |
e7cdac7
to
449ddb7
Compare
@hayatoito @annevk how does 449ddb7 look? Is it OK to leave inner invoke algorithm alone and define |
449ddb7
to
5cc3243
Compare
dom.bs
Outdated
is the <var>event</var> passed to <a>inner invoke</a>. If <var>event</var>'s {{Event/target}} <a for=tree>root</a> | ||
is a <a for=/>shadow root</a>, the <a>current event</a> is undefined. | ||
|
||
<p class="note no-backref">Authors <span class=allow-2119>should</span> explicitly pass in the |
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.
Make this "Developers are strongly encouraged" instead of using "authors" and "should".
dom.bs
Outdated
<dfn attribute for=Window><code>event</code></dfn> attribute that always returns the <a>current event</a> | ||
during <a>dispatch</a>, and is otherwise undefined. The <dfn type=dfn id=concept-current-event>current event</dfn> | ||
is the <var>event</var> passed to <a>inner invoke</a>. If <var>event</var>'s {{Event/target}} <a for=tree>root</a> | ||
is a <a for=/>shadow root</a>, the <a>current event</a> is undefined. |
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 will need to become an imperative definition where we manipulate the internal slot that the attribute reflects from the dispatch algorithm. Declarative definitions often lead to subtle edge cases becoming undefined over time.
dom.bs
Outdated
@@ -587,7 +603,8 @@ return the value it was initialized to. When an | |||
<a>event</a> is created the attribute must be | |||
initialized to the empty string. | |||
|
|||
The <dfn attribute for=Event><code>target</code></dfn> and | |||
The <dfn attribute for=Event><code>target</code></dfn>, | |||
<dfn attribute for=Event><code>srcElement</code></dfn> and |
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.
Oxford comma.
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.
Fixed.
dom.bs
Outdated
@@ -731,7 +755,7 @@ To <dfn export for=Event id=concept-event-initialize>initialize</dfn> an | |||
<a>canceled flag</a>. | |||
<li>Set the {{Event/isTrusted}} attribute | |||
to false. | |||
<li>Set the {{Event/target}} attribute to | |||
<li>Set the {{Event/target}} and {{Event/srcElement}} attributes to |
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.
An alternative might be that we actually define Event's "target" as a concept and set that here and than have the target and srcElement attributes reflect that.
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.
Filed a follow up issue for that: #570
5cc3243
to
393f447
Compare
done.
oops. |
I noticed you signed up as an individual. Do you no longer work for Mozilla (or another company in the field of web technologies)? If you still work for Mozilla, then you'll want to get in touch with @dbaron and get invited to https://github.com/mozilla-standards instead. |
@miketaylr is now part of @mozilla-standards |
Awesome. He'll just need to make his affiliation public, then the checker will be satisfied. (All that said, I imagine this PR will need to wait until @annevk is back from vacation.) |
Done, thanks.
Yeah, no worries. There still a few things to address -- I'll manually ping for review when ready. |
393f447
to
979c442
Compare
OK,
edit: working on some feedback from tests, hang tight. |
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 decided to review anyway to allow for parallel addressing of comments. Hope that helps.
dom.bs
Outdated
@@ -499,6 +505,15 @@ list of tuples, each of which consists of an <b>item</b> (an {{EventTarget}} obj | |||
object). A tuple is formatted as (<b>item</b>, <b>target</b>, <b>relatedTarget</b>). A <a | |||
for=Event>path</a> is initially the empty list.</p> | |||
|
|||
For web compatibility, the <a>current global object</a> has an |
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.
All new/changed paragraphs should start with <p>
.
This paragraph should be reworded and moved done I think. It makes more sense to me to define this extension to the Window
object at the end of this section since it's also at the end of the IDL.
Furthermore, we shouldn't give the reason in the description of the feature. That can go into a note if it's important.
dom.bs
Outdated
|
||
<p class="note no-backref">Authors <span class=allow-2119>should</span> explicitly pass in the | ||
event object to event listener callbacks, rather than rely on a global <code>window.event</code> | ||
object. |
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 wouldn't use should here. Just say "strongly encouraged".
dom.bs
Outdated
@@ -684,6 +700,13 @@ The <dfn attribute for=Event><code>bubbles</code></dfn> and | |||
<dfn attribute for=Event><code>cancelable</code></dfn> attributes | |||
must return the values they were initialized to. | |||
|
|||
The <dfn attribute for=Event><code>returnValue</code></dfn> | |||
attribute must be initialized to true when an <a>event</a> is created. |
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 don't think this makes sense. You want to instead describe this as a getter and a setter. The default value is already evident from the default value of the canceled flag after all.
See https://url.spec.whatwg.org/#dom-url-protocol for an example of defining a getter and a setter.
dom.bs
Outdated
@@ -1357,6 +1380,9 @@ with <var>event</var>, <var>listeners</var>, and an optional | |||
<li><p>If <var>listener</var>'s <b>passive</b> is true, then set <var>event</var>'s | |||
<a>in passive listener flag</a>. | |||
|
|||
<li><p>If <var>event</var>'s {{Event/target}} <a for=tree>root</a> is not a | |||
<a for=/>shadow root</a>, set the <a>current event</a> to <var>event</var>. |
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.
then set*
dom.bs
Outdated
For web compatibility, the <a>current global object</a> has an | ||
<dfn attribute for=Window><code>event</code></dfn> attribute that returns the | ||
<dfn export id=concept-current-event>current event</dfn>, which is initially | ||
set to undefined. |
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.
You also need to define what current event is associated with. Also, we should probably test that this quirk is not present in workers? And ensure the algorithms work in a worker context as well, since events don't just dispatch inside a window.
Is this PR in a state that I should try to write Gecko code for? |
@hsivonen I had another look and while I thought I only had nits, I think one problem with
|
Yeah, this definitely. Should also make the implementation faster, at least in Gecko. But why is the check based on target and not currentTarget? I would have expected window.event to be null/undefined whenever an event listener in shadow DOM tries to access it. I think that makes the feature easier to understand - it works only in light DOM, and scripts in shadow DOM can't use it. |
I've now updated this PR to use the suggestion from @yuki3 to take the global from the listener's callback. So now it's evaluated on a per-listener basis rather than on a per-event-target basis. Apologies for the delay. I'll next update the tests and file implementation bugs. |
Bugs:
If someone could give this and the tests a final review pass that'd much appreciated! |
Spec updates LGTM. |
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790
…shadow tree https://bugs.webkit.org/show_bug.cgi?id=186266 Reviewed by Ryosuke Niwa. LayoutTests/imported/w3c: Re-sync dom/events web-platform-tests from 59d4a411a8e to gain test coverage. * web-platform-tests/dom/events/Event-returnValue-expected.txt: * web-platform-tests/dom/events/Event-returnValue.html: * web-platform-tests/dom/events/event-global-expected.txt: Added. * web-platform-tests/dom/events/event-global-extra.window.js: Added. (async_test.t.frame.onload.t.step_func_done): * web-platform-tests/dom/events/event-global.html: Added. * web-platform-tests/dom/events/event-global.worker-expected.txt: Added. * web-platform-tests/dom/events/event-global.worker.html: Added. * web-platform-tests/dom/events/event-global.worker.js: Added. * web-platform-tests/dom/events/relatedTarget.window.js: Added. (test): (test.t.input.oninput.t.step_func): * web-platform-tests/dom/events/resources/event-global-extra-frame.html: Added. * web-platform-tests/dom/events/resources/w3c-import.log: Added. * web-platform-tests/dom/events/w3c-import.log: Source/WebCore: Stop exposing window.event to Shadow DOM by not setting window.event if the event's target is a Node inside a shadow tree. This is as per the latest DOM specification: - whatwg/dom#407 This aligns our behavior with Blink as well: - https://bugs.chromium.org/p/chromium/issues/detail?id=779461 Tests: imported/w3c/web-platform-tests/dom/events/event-global.html imported/w3c/web-platform-tests/dom/events/event-global.worker.html * bindings/js/JSEventListener.cpp: (WebCore::JSEventListener::handleEvent): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@233489 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Automatic update from web-platform-testsTest self.event in workers To compliment #10329. Needed for whatwg/dom#407. -- wpt-commits: 3543c82551c1c1c152885844b00b0af0d0e38864 wpt-pr: 10382 wpt-commits: 3543c82551c1c1c152885844b00b0af0d0e38864 wpt-pr: 10382 UltraBlame original commit: 3838ac80516e937da4487e484094587ad3483348
Automatic update from web-platform-testsTest self.event in workers To compliment #10329. Needed for whatwg/dom#407. -- wpt-commits: 3543c82551c1c1c152885844b00b0af0d0e38864 wpt-pr: 10382 wpt-commits: 3543c82551c1c1c152885844b00b0af0d0e38864 wpt-pr: 10382 UltraBlame original commit: 3838ac80516e937da4487e484094587ad3483348
Automatic update from web-platform-testsTest self.event in workers To compliment #10329. Needed for whatwg/dom#407. -- wpt-commits: 3543c82551c1c1c152885844b00b0af0d0e38864 wpt-pr: 10382 wpt-commits: 3543c82551c1c1c152885844b00b0af0d0e38864 wpt-pr: 10382 UltraBlame original commit: 3838ac80516e937da4487e484094587ad3483348
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790 UltraBlame original commit: 2f6df5e484b27039d7c56fe74e8e9ad7eee437a8
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790 UltraBlame original commit: f27248fd9a0c66d1e8b87085365f4de286491691
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790 UltraBlame original commit: 2f6df5e484b27039d7c56fe74e8e9ad7eee437a8
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790 UltraBlame original commit: f27248fd9a0c66d1e8b87085365f4de286491691
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790 UltraBlame original commit: 2f6df5e484b27039d7c56fe74e8e9ad7eee437a8
Automatic update from web-platform-testsAdd tests for window.event For whatwg/dom#334 and whatwg/dom#407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790 UltraBlame original commit: f27248fd9a0c66d1e8b87085365f4de286491691
srcElement and returnValue were specified in [1] and have WPTs in [2]. cancelBubble is documented in [3] and has a WPT which passes in all browsers in [4]. [1] whatwg/dom#407 [2] web-platform-tests/wpt#10258 [3] https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelBubble [4] https://wpt.fyi/results/dom/events/Event-cancelBubble.html Fixed: 692695 Change-Id: Ia7113a9996a0e272829a3e81bf751412444e9ba8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610947 Reviewed-by: Mason Freed <masonfreed@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/master@{#840397}
srcElement and returnValue were specified in [1] and have WPTs in [2]. cancelBubble is documented in [3] and has a WPT which passes in all browsers in [4]. [1] whatwg/dom#407 [2] web-platform-tests/wpt#10258 [3] https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelBubble [4] https://wpt.fyi/results/dom/events/Event-cancelBubble.html Fixed: 692695 Change-Id: Ia7113a9996a0e272829a3e81bf751412444e9ba8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610947 Reviewed-by: Mason Freed <masonfreed@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/master@{#840397} GitOrigin-RevId: 3de46b6619a24531b2277b243ac39484a8ca5505
From what I can tell, the warning on MDN is a bit misleading, since this MSIE extension is still technically part of the standard*, although its use is discouraged. This API will likely never go away. See this issue** on MDN content. Note that this uses a different approach for getting the inner window. * https://dom.spec.whatwg.org/#interface-window-extensions ** mdn/content#21848 Spec PR: whatwg/dom#407 Spec discussion: whatwg/dom#334 Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=218415
From what I can tell, the warning on MDN is a bit misleading, since this MSIE extension is still technically part of the standard*, although its use is discouraged. This API will also likely never go away. See this issue** on MDN content. Note that this uses a different approach for getting the inner window. * https://dom.spec.whatwg.org/#interface-window-extensions ** mdn/content#21848 Spec PR: whatwg/dom#407 Spec discussion: whatwg/dom#334 Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=218415
This MSIE extension is still technically part of the standard*, although its use is discouraged. This API will also likely never go away based on some comments at this issue on MDN content**. Note that this uses a different approach for getting the inner window. * https://dom.spec.whatwg.org/#interface-window-extensions ** mdn/content#21848 Spec PR: whatwg/dom#407 Spec discussion: whatwg/dom#334 Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=218415
This MSIE extension is still technically part of the standard*, although its use is discouraged. This API will also likely never go away based on some comments at this issue on MDN content**. Note that this uses a different approach for getting the inner window. * https://dom.spec.whatwg.org/#interface-window-extensions ** mdn/content#21848 Spec PR: whatwg/dom#407 Spec discussion: whatwg/dom#334 Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=218415
cf. #334
@annevk is this sufficient? Or should I add
srcElement
everywhere thattarget
is mentioned (feels a bit redundant after a while...)I'll have a related wpt PR tomorrow at some point.
Preview | Diff