Skip to content

Commit e56c62d

Browse files
committed
Clean up the event loop and agent correspondence
This closes #5352, by making event loops and agents 1:1. It also adds an explicit explanation that event loops/agents and implementation threads are not necessarily 1:1, apart from the restrictions imposed by JavaScript's forward progress guarantee. This also closes #4213, as worklet event loops work fine in this architecture. This also closes #4674, as browsing contexts changing event loops is not a problem in this architecture, since they change agents at the same time. Finally, this guards one step in the event loop processing model that only made sense for window event loops.
1 parent 81affbe commit e56c62d

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

source

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
28242824
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-candidate-executions">candidate execution</dfn></li>
28252825
<li>The <dfn data-x-href="https://tc39.es/ecma262/#current-realm">current Realm Record</dfn></li>
28262826
<li><dfn data-x-href="https://tc39.es/ecma262/#early-error-rule">early error</dfn></li>
2827+
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-forward-progress">forward progress</dfn></li>
28272828
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-invariants-of-the-essential-internal-methods">invariants of the essential internal methods</dfn></li>
28282829
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-execution-contexts">JavaScript execution context</dfn></li>
28292830
<li><dfn data-x-href="https://tc39.es/ecma262/#execution-context-stack">JavaScript execution context stack</dfn></li>
@@ -88916,40 +88917,31 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
8891688917

8891788918
</div>
8891888919

88919-
<h4>Event loops</h4> <!-- <dfn>event loop</dfn> -->
88920+
<h4>Event loops</h4>
8892088921

8892188922
<h5 w-nodev>Definitions</h5>
8892288923

8892388924
<p>To coordinate events, user interaction, scripts, rendering, networking, and so forth, user
8892488925
agents must use <dfn data-x="event loop" data-lt="event loop" data-export="">event loops</dfn> as
88925-
described in this section. Each <span>agent</span> has an associated <span>event loop</span>.</p>
88926+
described in this section. Each <span>agent</span> has an associated <span>event loop</span>,
88927+
which is unique to that agent.</p>
8892688928

88927-
<p class="note">In the future, this standard hopes to define exactly when <span data-x="event
88928-
loop">event loops</span> can be created or reused.</p>
88929+
<p>The <span>event loop</span> of a <span>similar-origin window agent</span> is known as a
88930+
<dfn>window event loop</dfn>. The <span>event loop</span> of a <span>dedicated worker
88931+
agent</span>, <span>shared worker agent</span>, or <span>service worker agent</span> is known as a
88932+
<dfn>worker event loop</dfn>. And the <span>event loop</span> of a <span>worklet agent</span> is
88933+
known as a <dfn>worklet event loop</dfn>.</p>
8892988934

88930-
<p>A <dfn>window event loop</dfn> is the <span>event loop</span> used by <span
88931-
data-x="similar-origin window agent">similar-origin window agents</span>. User agents may share an
88932-
<span>event loop</span> across <span data-x="similar-origin window agent">similar-origin window
88933-
agents</span>.</p>
88934-
<!-- Ideally user agents process-isolate similar-origin window agents from each other that are not
88935-
same site. However, this is not the reality in 2019. -->
88936-
88937-
<p class="note">This specification does not currently describe how to handle the complications
88938-
arising from <span data-x="navigate">navigating</span> between <span data-x="similar-origin window
88939-
agent">similar-origin window agents</span>. E.g., when a <span>browsing context</span> <span
88940-
data-x="navigate">navigates</span> from <code data-x="">https://example.com/</code> to <code
88941-
data-x="">https://shop.example/</code>.</p>
88942-
88943-
<p>A <dfn>worker event loop</dfn> is the <span>event loop</span> used by <span data-x="dedicated
88944-
worker agent">dedicated worker agents</span>, <span data-x="shared worker agent">shared worker
88945-
agents</span>, and <span data-x="service worker agent">service worker agents</span>. There must be
88946-
one <span>worker event loop</span> per such <span>agent</span>.</p>
88947-
88948-
<p>A <dfn>worklet event loop</dfn> is the <span>event loop</span> used by <span data-x="worklet
88949-
agent">worklet agents</span>.</p>
88935+
<div class="note">
88936+
<p><span data-x="event loop">Event loops</span> do not necessarily correspond to implementation
88937+
threads. For example, multiple <span data-x="window event loop">window event loops</span> could
88938+
be cooperatively scheduled in a single thread.</p>
8895088939

88951-
<p class="XXX">As detailed in <a href="https://github.com/whatwg/html/issues/4213">issue #4213</a>
88952-
the situation for worklets is more complicated.</p>
88940+
<p>However, because the various worker <span data-x="agent">agents</span> are allocated with
88941+
[[CanBlock]] set to true, the JavaScript specification does place requirements on them regarding
88942+
<span>forward progress</span>, which effectively amount to requiring dedicated per-agent threads
88943+
in those cases.</p>
88944+
</div>
8895388945

8895488946
<div w-nodev>
8895588947

@@ -89386,8 +89378,8 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
8938689378
</li>
8938789379

8938889380
<li>
89389-
<p>Report the duration of the <span>update the rendering</span> step by performing the
89390-
following steps:</p>
89381+
<p>If this a <span>window event loop</span>, then report the duration of the <span>update the
89382+
rendering</span> step by performing the following steps:</p>
8939189383

8939289384
<ol>
8939389385
<li><p>Let <var>rendering end time</var> be the <span>current high resolution

0 commit comments

Comments
 (0)