Skip to content

Commit

Permalink
Specify how timeOrigin is computed
Browse files Browse the repository at this point in the history
The time origin, which is the epoch for all performance timeline APIs,
was previously defined [here](https://w3c.github.io/hr-time/#dfn-time-origin).

This PR makes its computation explicity, without changing its current
definition and behavior.

- `time origin` becomes an `environment settings object` algorithm,
  computed differently for windows vs. worker scopes

- The 4 places where this timestamp is set are creation of an
`about:blank` context, beginning of navigation, confirmation of an
unload prompt, and creating a worker.

- The timestamp is a `shared monotonic clock` value, which is defined
in HR-TIME (and internally in ECMAScript).

As part of this PR, also refactored unload prompts to return a result
rather than rely on a somewhat hand-wavy "refused to allow" property.

See w3c/hr-time#131
and w3c/navigation-timing#166
  • Loading branch information
noamr committed Nov 15, 2021
1 parent 54bff73 commit 57df614
Showing 1 changed file with 88 additions and 31 deletions.
119 changes: 88 additions & 31 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<p><cite>High Resolution Time</cite> provides the <dfn
data-x-href="https://w3c.github.io/hr-time/#dfn-current-high-resolution-time">current high
resolution time</dfn> and the <dfn
resolution time</dfn>, the <dfn
data-x-href="https://w3c.github.io/hr-time/#dfn-shared-monotonic-clock">shared monotonic
clock</dfn>, and the <dfn
data-x-href="https://w3c.github.io/hr-time/#dom-domhighrestimestamp"><code>DOMHighResTimeStamp</code></dfn>
typedef. <ref spec=HRT></p>
</dd>
Expand Down Expand Up @@ -9605,6 +9607,9 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
data-x="struct item">items</span>:</p>

<dl>
<dt><dfn export for="document load timing info">navigation start time</dfn> (default 0)</dt>
<dd>A number</dd>

<dt><dfn export for="document load timing info">DOM interactive time</dfn> (default 0)</dt>
<dt><dfn export for="document load timing info">DOM content loaded event start time</dfn>
(default 0)</dt>
Expand Down Expand Up @@ -79426,6 +79431,10 @@ popup4.close();</code></pre></div>
<ol>
<li><p>Let <var>browsingContext</var> be a new <span>browsing context</span>.</p></li>

<li><p>Let <var>blankLoadTimingInfo</var> be a new <span>document load timing info</span> with
its <span>navigation start time</span> set to the value of the
<span>shared monotonic clock</span>.</p></li>

<li id="creator-browsing-context"><p>If <var>creator</var> is non-null, then set
<var>browsingContext</var>'s <span>creator origin</span> to return <var>creator</var>'s <span
data-x="concept-document-origin">origin</span>, <var>browsingContext</var>'s <span>creator
Expand Down Expand Up @@ -79498,7 +79507,8 @@ popup4.close();</code></pre></div>
sandboxing flag set</span> is <var>sandboxFlags</var>, <span
data-x="concept-document-permissions-policy">permissions policy</span> is
<var>permissionsPolicy</var>, <span data-x="concept-document-coop">cross-origin opener
policy</span> is <var>coop</var>,
policy</span> is <var>coop</var>, <span>load timing info</span> is
<var>blankLoadTimingInfo</var>,
<span data-x="concept-document-navigation-id">navigation id</span> is null, and which is
<span>ready for post-load tasks</span>.</p></li>

Expand Down Expand Up @@ -81638,8 +81648,8 @@ dictionary <dfn dictionary>WindowPostMessageOptions</dfn> : <span>StructuredSeri
<p>To <dfn>close a browsing context</dfn> <var>browsingContext</var>, run these steps:</p>

<ol>
<li><p><span>Prompt to unload</span> <var>browsingContext</var>'s <span>active document</span>.
If the user <span>refused to allow the document to be unloaded</span>, then return.</p></li>
<li><p>If the result of calling <span>prompt to unload</span> with <var>browsingContext</var>'s
<span>active document</span> is "<code data-x="">refuse</code>", then return.</p></li>

<li><p><span data-x="unload a document">Unload</span> <var>browsingContext</var>'s <span>active
document</span>.</p></li>
Expand Down Expand Up @@ -85306,9 +85316,9 @@ interface <dfn interface>History</dfn> {
entry</var>, then run these substeps:</p>

<ol>
<li><p><span>Prompt to unload</span> the <span>active document</span> of the <var>specified
browsing context</var>. If the user <span>refused to allow the document to be
unloaded</span>, then return.</p></li>
<li><p>If the result of calling <span>prompt to unload</span> with the
<span>active document</span> of the <var>specified browsing context</var> is
"<code data-x="">refuse</code>", then return.</p></li>

<li><p><span data-x="unload a document">Unload</span> the <span>active document</span> of the
<var>specified browsing context</var>.</p></li>
Expand Down Expand Up @@ -86677,6 +86687,9 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
<dt><dfn data-x="navigation-params-has-cross-origin-redirects">has cross-origin
redirects</dfn></dt>
<dd>a boolean</dd>

<dt><dfn data-x="navigation-params-start-time">start time</dfn></dt>
<dd>a number, representing a value of the <span>shared monotonic clock</span></dd>
</dl>

<p class="note">Once a <span>navigation params</span> struct is created, this standard does not
Expand Down Expand Up @@ -86728,6 +86741,9 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
<dfn data-x="navigation-navigationid"><var>navigationId</var></dfn> (default null):</p>

<ol>
<li><p>Let <var>navigationStartTime</var>be the value of the
<span>shared monotonic clock</span>.</p></li>

<li><p>If <var>resource</var> is a <span>URL</span>, then set <var>resource</var> to a new <span
data-x="concept-request">request</span> whose <span data-x="concept-request-url">URL</span> is
<var>resource</var>.</p></li>
Expand Down Expand Up @@ -86839,17 +86855,23 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
later.)</p></li>

<li>
<p><span>Prompt to unload</span> the <span>active document</span> of <var>browsingContext</var>.
If the user <span>refused to allow the document to be unloaded</span>, then return a new
<span>WebDriver BiDi navigation status</span> whose <span data-x="navigation-status-id">id</span>
is <var>navigationId</var> and <span data-x="navigation-status-status">status</span> is "<code
data-x="navigation-status-canceled">canceled</code>".</p>
<p>Let <var>unloadPromptResult</var> be the result of calling
<span>prompt to unload</span> with the <span>active document</span> of
<var>browsingContext</var>.</p>

<p>If this instance of the <span data-x="navigate">navigation</span> algorithm gets canceled
while this step is running, the <span>prompt to unload</span> algorithm must nonetheless be run
to completion.</p>
</li>

<li><p>If <var>unloadPromptResult</var> is "<code data-x="">refuse</code>", then return a new
<span>WebDriver BiDi navigation status</span> whose <span data-x="navigation-status-id">id</span>
is <var>navigationId</var> and <span data-x="navigation-status-status">status</span> is
"<code data-x="navigation-status-canceled">canceled</code>".</p>

<li><p>Otherwise, if <var>unloadPromptResult</var> is "<code data-x="">confirm</code>", then set
<var>navigationStartTime</var> to the value of the <span>shared monotonic clock</span>.</p></li>

<li><p><span data-x="abort a document">Abort</span> the <span>active document</span> of
<var>browsingContext</var>.</p></li>

Expand Down Expand Up @@ -86950,7 +86972,8 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
data-x="navigation-params-reserved-environment">reserved environment</span> is null, <span
data-x="navigation-params-browsing-context">browsing context</span> is
<var>browsingContext</var>, <span data-x="navigation-params-hh">history handling</span> is
<var>historyHandling</var>, and <span
<var>historyHandling</var>, <span data-x="navigation-params-start-time">start time</span> is
<var>navigationStartTime</var>, and <span
data-x="navigation-params-has-cross-origin-redirects">has cross-origin redirects</span> is
false.</p></li>

Expand Down Expand Up @@ -87740,6 +87763,10 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
data-x="navigation-params-request">request</span>'s <span
data-x="concept-request-current-url">current URL</span>.</p></li>

<li><p>Let <var>previousTimeOrigin</var> be <var>browsingContext</var>'s <span>active
document</span>'s <span>relevant settings object</span>'s
<span data-x="concept-settings-object-time-origin">time origin</span>.</p></li>

<li>
<p>If <var>browsingContext</var> is <span>still on its initial <code>about:blank</code>
<code>Document</code></span>, and <var>navigationParams</var>'s <span
Expand Down Expand Up @@ -87819,6 +87846,10 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
create gets a new <code>Window</code> to go along with it.</p>
</li>

<li><p>Let <var>loadTimingInfo</var> be a new <span>document load timing info</span> with its
<span>navigation start time</span> set to <var>navigationParams</var>'s
<span data-x="navigation-params-start-time">start time</span>.</p></li>

<li>
<p>Let <var>document</var> be a new <code>Document</code>, whose <span
data-x="concept-document-type">type</span> is <var>type</var>, <span
Expand All @@ -87832,7 +87863,8 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
<var>navigationParams</var>'s <span data-x="navigation-params-sandboxing">final sandboxing flag
set</span>, and <span data-x="concept-document-coop">cross-origin opener policy</span> is
<var>navigationParams</var>'s <span data-x="navigation-params-coop">cross-origin opener
policy</span>, and <span data-x="concept-document-navigation-id">navigation id</span> is
policy</span>, <span>load timing info</span> is <var>loadTimingInfo</var>, and
<span data-x="concept-document-navigation-id">navigation id</span> is
<var>navigationParams</var>'s <span data-x="navigation-params-id">id</span>.</p>

<p class="note">The new <code>Window</code>'s <span
Expand Down Expand Up @@ -87876,9 +87908,6 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
</ol>
</li>

<li><p>Set <var>document</var>'s <span>load timing info</span> to a new <span>document load
timing info</span>.</p></li>

<li><p>Let <var>historyHandling</var> be <var>navigationParams</var>'s
<span data-x="navigation-params-hh">history handling</span>.</p></li>

Expand Down Expand Up @@ -87911,7 +87940,7 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
data-x="concept-response-timing-info">timing info</span>,
<span data-x="navigation-params-response">response</span>'s <span
data-x="concept-response-service-worker-timing-info">service worker timing info</span>,
<var>redirectCount</var>, and <var>navigationType</var>.</p></li>
<var>redirectCount</var>, <var>navigationType</var>, and <var>previousTimeOrigin</var>.</p></li>

<li>
<p>If <var>navigationParams</var>'s <span data-x="navigation-params-response">response</span>
Expand Down Expand Up @@ -89151,6 +89180,8 @@ dictionary <dfn dictionary>PageTransitionEventInit</dfn> : <span>EventInit</span
<li><p>Decrease the <span>event loop</span>'s <span>termination nesting level</span> by
1.</p></li>

<li><p>Let <var>result</var> be "<code data-x="">no-prompt</code>".

<li>
<p>If all of the following are true:</p>

Expand Down Expand Up @@ -89178,8 +89209,8 @@ dictionary <dfn dictionary>PageTransitionEventInit</dfn> : <span>EventInit</span
<p>If the user agent asks the user for confirmation, it must <span>pause</span> while waiting
for the user's response.</p>

<p>If the user did not confirm the page navigation, then the user agent <dfn>refused to allow
the document to be unloaded</dfn>.</p>
<p>If the user confirmed the page navigation, then set <var>result</var> to
"<code data-x="">confirm</code>"; otherwise return "<code data-x="">refuse</code>".</p>
</li>

<li>
Expand All @@ -89193,18 +89224,24 @@ dictionary <dfn dictionary>PageTransitionEventInit</dfn> : <span>EventInit</span
<p>For each <var>browsingContext</var> in <var>descendants</var>:</p>

<ol>
<li><p><span>Prompt to unload</span> <var>browsingContext</var>'s <span>active
document</span> with the <var>recursiveFlag</var> set.</p></li>
<li><p>Let <var>internalResult</var> be the result of calling <span>prompt to unload</span>
for <var>browsingContext</var>'s <span>active document</span> with the
<var>recursiveFlag</var> set.</p></li>

<li><p>If <var>internalResult</var> is "<code data-x="">refuse</code>", then return
<var>internalResult</var>.</p></li>

<li><p>Otherwise, if <var>internalResult</var> is "<code data-x="">confirm</code>", set
<var>result</var> to <var>internalResult</var>.</p></li>

<li><p>If the user <span>refused to allow the document to be unloaded</span>, then the user
implicitly also <span data-x="refused to allow the document to be unloaded">refused to allow
<var>document</var> to be unloaded</span>; <span>break</span>.</p></li>
</ol>
</li>
</ol>
</li>

<li><p>Decrease the <var>document</var>'s <span>unload counter</span> by 1.</p></li>

<li><p>Return <var>result</var>.</p></li>
</ol>

<p>To <dfn export data-x="unload a document" data-lt="unload a document">unload</dfn> a
Expand Down Expand Up @@ -90131,6 +90168,13 @@ interface <dfn interface>BeforeUnloadEvent</dfn> : <span>Event</span> {

<dd><p>A boolean representing whether scripts that use this <span>environment settings
object</span> are allowed to use APIs that require cross-origin isolation.</p></dd>

<dt>A <dfn data-x="concept-settings-object-time-origin" export
for="environment settings object">time origin</dfn></dt>

<dd>A number representing the <span>shared monotonic clock</span> value, which is used as a
baseline for performance timeline entries. <ref spec=HRT></dd>

</dl>

<p>An <span>environment settings object</span> also has an <dfn>outstanding rejected promises
Expand Down Expand Up @@ -102031,6 +102075,10 @@ interface <dfn interface>WorkerGlobalScope</dfn> : <span>EventTarget</span> {
data-x="concept-WorkerGlobalScope-cross-origin-isolated-capability">cross-origin isolated
capability</dfn> boolean. It is initially false.</p>

<p>A <code>WorkerGlobalScope</code> object has an associated <dfn export for="WorkerGlobalScope"
data-x="concept-WorkerGlobalScope-creation-time">creation time</dfn> number. It is initially
zero.</p>

</div>

<dl class="domintro">
Expand Down Expand Up @@ -102349,13 +102397,12 @@ interface <dfn interface>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope
nested dedicated worker), then set <var>parent worker global scope</var> to
<var>owner</var>.</p></li>

<li>
<p>Let <var>agent</var> be the result of <span data-x="obtain a dedicated/shared worker
agent">obtaining a dedicated/shared worker agent</span> given <var>outside settings</var> and
<var>is shared</var>. Run the rest of these steps in that agent.</p>
<li><p>Let <var>workerCreationTime</var> be the value of the
<span>shared monotonic clock</span>.</p></li>

<p id="worker-processing-model-top">For the purposes of timing APIs, this is the <dfn
export>official moment of creation</dfn> of the worker.</p> </li>
<li><p>Let <var>agent</var> be the result of <span data-x="obtain a dedicated/shared worker
agent">obtaining a dedicated/shared worker agent</span> given <var>outside settings</var> and
<var>is shared</var>. Run the rest of these steps in that agent.</p></li>

<li>
<p>Let <var>realm execution context</var> be the result of <span>creating a new JavaScript
Expand All @@ -102376,6 +102423,10 @@ interface <dfn interface>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope
<code>SharedWorkerGlobalScope</code> object created in the previous step.</p>
</li>

<li><p>Set <var>worker global scope</var>'s
<span data-x="concept-WorkerGlobalScope-creation-time">creation time</span> to
<var>workerCreationTime</var>.</p><li>

<li><p><span>Set up a worker environment settings object</span> with <var>realm execution
context</var> and <var>outside settings</var>, and let <var>inside settings</var> be the
result.</p></li>
Expand Down Expand Up @@ -102788,6 +102839,12 @@ interface <dfn interface>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope
<dd><p>Return <var>worker global scope</var>'s <span
data-x="concept-WorkerGlobalScope-cross-origin-isolated-capability">cross-origin isolated
capability</span>.</p></dd>

<dt>The <span data-x="concept-settings-object-time-origin">time origin</span></dt>
<dd>
<p>Return <var>worker global scope</var>'s <span
data-x="concept-WorkerGlobalScope-creation-time">creation time</span>.</p>
</dd>
</dl>
</li>

Expand Down

0 comments on commit 57df614

Please sign in to comment.