-
Notifications
You must be signed in to change notification settings - Fork 297
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
Update Event.timeStamp type to DOMHighResTimeStamp. #420
Conversation
Update text recommending use of high resolution event occurrence time where available. Add note in legacy section describing the change. Add necessary spec reference for Bikeshed to pick up new definitions.
dom.bs
Outdated
initialized to. If available, the attribute should be initialized with the high resolution time of | ||
the occurrence that the event is signaling, for example the moment when a particular user | ||
interaction occurred. Otherwise it should be initialized with the time representing the creation | ||
time of the <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.
Nit: "s/the time representing the creation time/the creation time"
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.
Done.
dom.bs
Outdated
<p class=XXX>This is highly likely to change and already does not reflect implementations well. | ||
Please see <a href=https://github.com/whatwg/dom/issues/23>dom #23</a> for more details. | ||
<p class=note>User agents are encouraged to make the high resolution time occurrence time | ||
available for as many events as possible in particular those related to user interaction. |
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.
Nit: comma after "as possible"
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.
Done
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 we have tests already?
dom.bs
Outdated
initialized to. If available, the attribute should be initialized with the high resolution time of | ||
the occurrence that the event is signaling, for example the moment when a particular user | ||
interaction occurred. Otherwise it should be initialized with the creation time of the | ||
<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.
What does "creation time" mean?
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 the same terminology that was used before. The way I read it was the time where the event instance was constructed which is what Chrome implementation was also using.
Put it another way this is IMHO step 1 in section 2.4. Perhaps it should link to 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.
The terminology before had specific instructions with respect to what the value should contain. "Creation time" by itself doesn't give me a number.
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.
Done. The wording now says When an <a>event</a> is created the attribute must be initialized with a {{DOMHighResTimeStamp}} representing the high resolution time in milliseconds that has passed since the <a>time origin</a>.
This is similar to previous text but with new time type and origin. This initial value may change in event creation algorithm which now have the wording about occurrence time etc.
dom.bs
Outdated
00:00:00 UTC on 1 January 1970, ignoring leap seconds. | ||
<!-- leap seconds are ignored by JavaScript too --> | ||
The <dfn attribute for=Event><code>timeStamp</code></dfn> attribute must return the value it was | ||
initialized to. If available, the attribute should be initialized with the high resolution time of |
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.
Can we enumerate when it's not?
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 seems that for synthetic events this would never be available.
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 do you mean by synthetic events? If you are referring to those constructed in Javascript then that is probably correct and what for example Chrome implementation does. (BTW, I think issue #76 is proposing to make timestamp a constructor argument in which case this is not true anymore)
There may be other implementation related restrictions that makes the precise occurrence time unavailable. For example on some platforms (e.g., older Windows) there is no cross-process monotonic clock which in browsers with multi-process architecture can mean we cannot use the original timestamp. Or sometimes the driver uses a different clock and timestamp is not reliable. In such cases we end up using the closest estimation we can get. I think falling back to "creation time" is acceptable here too.
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.
Yeah, a synthetic event is basically a "userland" event. It would be good if we were consistent in what value it would get there (and yes, maybe at some point we allow custom values there, but that would just end up being a branch there).
I'm not really sure how to best do it though. I only have a long term vision where user interaction events are defined in much more detail and they end up initializing this attribute properly (and by default it's just creation time, whatever that means).
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.
Done. I now have exact details on what to use for synthetic events (i.e., use construction time).
dom.bs
Outdated
<dd>Returns the creation time of <var>event</var> as the number of milliseconds that | ||
passed since 00:00:00 UTC on 1 January 1970. | ||
<dd>Returns the <var>event</var>'s timestamp as the number of milliseconds measured relative | ||
from the <a>time origin</a>. |
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 seems to me that this term is also important for the normative definition, yet it doesn't appear there.
No I have not upstreamed the test yet. I was thinking to have this PR first and gain some confidence that it is accurate and then refer to it when upstreaming the test. Also, hr-time spec has recommendation on limiting the minimum resolution of the clock exposed via performance.now() to prevent certain types of timing attacks. Given that synthetic events will use the same clock, they can be used to the same effect (e.g., repeatedly creating events and reading their timestamp). We have made sure to prevent this in Chrome. I think we should add some language to the spec (perhaps a note?) recommending the same thing. wdyt?
|
Yeah, a class=warning block that points there below the normative definition of the attribute seems good. |
Normative definition of timeStamp attribute: - Declare that it is initialized to equivalent of performance.now() on creation - Add warning about 5 microsends minimum resolution from hrtime spec Event creation: - Clarify that in this case, if available, occurence time should be used Event constructio and Document.createEvent - Clarify that in this case, the time that the method is invoked (i.e., construction) time should be used.
@annevk thanks for bearing with me on this. So I just added a new commit which I think should address your feedback. Here are the changes I made: Normative definition of timeStamp attribute now defines that it should be initialized to equivalent of performance.now() on creation. I also added warning about 5 microsends minimum resolution from hrtime spec and referenced that spec. I also added details on how this attribute should be initialized in each algorithm where we create or construct an Event.
** I actually feel that this may not be necessary since the attribute definition specifies the same but I followed the example of how |
As I mentioned in #76, there may be potential for simplifying this if we add timestamp to EventInit with a default value. But perhaps that is best done in a separate patch. |
@annevk I also have a Blink patch to upstream parts of our tests for this change. I will land those once this patch is lgtm'd. Please take a look there an let me know if you have any comments on the tests as well. |
I think the issue I mention in #76 also applies to this patch. |
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.
In general this looks reasonable, but I'm still a little unhappy with how sketchy some of it is.
Apologies for the delay in review. The main reason is that I've been away for 5+ weeks.
dom.bs
Outdated
<dd>Returns the creation time of <var>event</var> as the number of milliseconds that | ||
passed since 00:00:00 UTC on 1 January 1970. | ||
<dd>Returns the <var>event</var>'s timestamp as the number of milliseconds measured relative | ||
from the <a>time origin</a>. |
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.
relative to, no?
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.
Done.
dom.bs
Outdated
The <dfn attribute for=Event><code>timeStamp</code></dfn> attribute must return the value it was | ||
initialized to. When an <a>event</a> is created the attribute must be initialized with a | ||
{{DOMHighResTimeStamp}} representing the high resolution time in milliseconds that has passed | ||
since the <a>time origin</a>. |
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 seems we don't need to define what it is set to when the event is created as we already do that later separately, no?
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.
Removed. To be honest, I found it odd too but was cargo culting the definition of isTrusted
just above it.
dom.bs
Outdated
<p class=XXX>This is highly likely to change and already does not reflect implementations well. | ||
Please see <a href=https://github.com/whatwg/dom/issues/23>dom #23</a> for more details. | ||
<p class=warning> User agents are strongly encouraged to set minimum resolution of the | ||
{{Event/timeStamp}} attribute to 5 microseconds following existing <a>clock resolution</a> |
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.
the existing*
Doesn't read well otherwise.
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.
Done.
dom.bs
Outdated
@@ -875,6 +879,10 @@ must be run, given the arguments <var>type</var> and <var>eventInitDict</var>: | |||
|
|||
<li><p>Initialize <var>event</var>'s {{Event/type}} attribute to <var>type</var>. | |||
|
|||
<li><p>Initialize <var>event</var>'s {{Event/timeStamp}} attribute to a {{DOMHighResTimeStamp}} | |||
representing the <var>event</var>'s <dfn>construction time</dfn> which is the high resolution | |||
time from the <a>time origin</a> to the occurrence of the call to the <a>constructor</a>. |
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 is the benefit of the new <dfn>
here? Can we reword this without introducing a new <dfn>
?
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.
Done. Removed.
dom.bs
Outdated
<li><p>If available, set <var>event</var>'s {{Event/timeStamp}} attribute to a | ||
{{DOMHighResTimeStamp}} representing the <var>event</var>'s <dfn>occurence time</dfn> which is | ||
the high resolution time from the <a>time origin</a> to the occurrence that the event is | ||
signaling, for example the moment when a particular user interaction occurred. |
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 here.
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.
Also, if what is available? Should we not just make this a requirement and not allow user agents not to have this?
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 think we should also have a note here that gives a far more detailed example. E.g., the name of a particular system call on some OS that gives you the time we'd expect to see exposed here.
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 removed "If available". I was thinking of cases where there is not any high resolution time available on the underlying event, e.g., some older Windows devices don't have a high resolution clock or the clock is not usable across processes. In such cases, Chromium uses the timestamp when event was received by renderer process as the closest thing we can have to the "occurrence time".
I guess there is no need to have the spec special case this as the term "occurrence time" gives enough flexibility to user agents to handle such limitations. Also per your suggestion, I added an example (for macOs) which should help guide how occurrence time should be interpreted by implementations.
dom.bs
Outdated
which is the high resolution time from the <a>time origin</a> to the occurrence of the call to | ||
{{Document/createEvent()}}. | ||
|
||
|
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.
One newline too many as far as I can tell.
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 also seems ugly that we initialize it twice.
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.
Done.
As for duplicate initialization, I am not sure if I understand. The way I was reading the spec was that for non-synthetic events we do the 2.4 - concept-event-create
that does not require invoking 2.4. - concept-event-constructor
which is only needed for synthetic events.
- Grammatical corrections. - Remove unnecessary definition. - Add example for NSEvent on macOS and remove "If available" for the non-synthetic event case.
Not at all. Vacations are great 😄 and there is not particular rush for this. 👍 |
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.
Couple minor nits left. With respect to isTrusted I think we simply forgot to remove "When an event is created the attribute must be initialized to false." when we added the other bits. I'll create a pull request for that.
dom.bs
Outdated
|
||
<p class=note>User agents are encouraged to make the high resolution occurrence time available | ||
for as many events as possible, in particular those related to user interaction. | ||
<p class=note>For example, in macOs the occurrence time for input actions are available via 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.
macOS*
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.
Done.
dom.bs
Outdated
representing the high resolution time from the <a>time origin</a> to the occurrence that the | ||
event is signaling. | ||
|
||
<p class=note>For example, in macOs the occurrence time for input actions are available via 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.
macOS
dom.bs
Outdated
@@ -5154,6 +5170,10 @@ invoked, must run these steps: | |||
|
|||
<li><p>Initialize <var>event</var>'s {{Event/type}} attribute to the empty string. | |||
|
|||
<li><p>Initialize <var>event</var>'s {{Event/timeStamp}} attribute to a {{DOMHighResTimeStamp}} | |||
which is the high resolution time from the <a>time origin</a> to the occurrence of the call to | |||
{{Document/createEvent()}}. |
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 was what I was talking about with respect to duplication, but I guess that's also following the isTrusted precedent. Probably okay. Can this become "from the time origin to now"? It's a little weird for the algorithm to refer to itself this way.
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.
Replaced self-reference with "now".
Oh also, could you add an explicit pointer to the tests somewhere? I haven't been able to find them. |
Actually, it seems that for isTrusted we don't define anything in the constructor. So that's why it's slightly different with respect to that. |
Tests are here: https://codereview.chromium.org/2744553007/ |
Thanks, those look good to me. Do you want to add your name to the Acknowledgments section as well? With that we can land this I think. I'll go ahead and file a bug against Edge so that's covered as well. |
Absolutely. 🎖️ |
I will go ahead an upstream the tests now. |
dom.bs
Outdated
<li><p>Initialize <var>event</var>'s {{Event/isTrusted}} attribute to false. | ||
|
||
<li><p>Unset <var>event</var>'s <a>initialized flag</a>. | ||
|
||
<li><p>Return <var>event</var>. | ||
<li><p>Return <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.
Seems you added this by accident in the last commit.
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.
Ops! fixed.
This is in anticipation of DOM spec patch landing [1]. Upstreaming two tests: - verify constructed events get a high-resolution time from perfomance.now() - verify the minimum resolution is larger that 5µs. [1] whatwg/dom#23 [2] whatwg/dom#420 BUG=538600 Review-Url: https://codereview.chromium.org/2744553007 Cr-Commit-Position: refs/heads/master@{#485966}
This is in anticipation of DOM spec patch landing [1]. Upstreaming two tests: - verify constructed events get a high-resolution time from perfomance.now() - verify the minimum resolution is larger that 5µs. [1] whatwg/dom#23 [2] whatwg/dom#420 BUG=538600 Review-Url: https://codereview.chromium.org/2744553007 Cr-Commit-Position: refs/heads/master@{#485966}
This is in anticipation of DOM spec patch landing [1]. Upstreaming two tests: - verify constructed events get a high-resolution time from perfomance.now() - verify the minimum resolution is larger that 5µs. [1] whatwg/dom#23 [2] whatwg/dom#420 BUG=538600 Review-Url: https://codereview.chromium.org/2744553007 Cr-Commit-Position: refs/heads/master@{#485966}
Thanks! |
Update Event.timeStamp type to DOMHighResTimeStamp.
This fixes #23 and the commit contains the following changes:
available and otherwise event object creation time.
Preview | Diff