Skip to content

Commit cd59059

Browse files
authored
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. Other problems remain around communication between agents (see e.g. #3691), and some of that communication is event-loop mediated, but the specific note discussed there is no longer relevant.
1 parent 71d44d0 commit cd59059

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

source

Lines changed: 21 additions & 29 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>
@@ -88888,40 +88889,31 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
8888888889

8888988890
</div>
8889088891

88891-
<h4>Event loops</h4> <!-- <dfn>event loop</dfn> -->
88892+
<h4>Event loops</h4>
8889288893

8889388894
<h5 w-nodev>Definitions</h5>
8889488895

8889588896
<p>To coordinate events, user interaction, scripts, rendering, networking, and so forth, user
8889688897
agents must use <dfn data-x="event loop" data-lt="event loop" data-export="">event loops</dfn> as
88897-
described in this section. Each <span>agent</span> has an associated <span>event loop</span>.</p>
88898-
88899-
<p class="note">In the future, this standard hopes to define exactly when <span data-x="event
88900-
loop">event loops</span> can be created or reused.</p>
88901-
88902-
<p>A <dfn>window event loop</dfn> is the <span>event loop</span> used by <span
88903-
data-x="similar-origin window agent">similar-origin window agents</span>. User agents may share an
88904-
<span>event loop</span> across <span data-x="similar-origin window agent">similar-origin window
88905-
agents</span>.</p>
88906-
<!-- Ideally user agents process-isolate similar-origin window agents from each other that are not
88907-
same site. However, this is not the reality in 2019. -->
88908-
88909-
<p class="note">This specification does not currently describe how to handle the complications
88910-
arising from <span data-x="navigate">navigating</span> between <span data-x="similar-origin window
88911-
agent">similar-origin window agents</span>. E.g., when a <span>browsing context</span> <span
88912-
data-x="navigate">navigates</span> from <code data-x="">https://example.com/</code> to <code
88913-
data-x="">https://shop.example/</code>.</p>
88914-
88915-
<p>A <dfn>worker event loop</dfn> is the <span>event loop</span> used by <span data-x="dedicated
88916-
worker agent">dedicated worker agents</span>, <span data-x="shared worker agent">shared worker
88917-
agents</span>, and <span data-x="service worker agent">service worker agents</span>. There must be
88918-
one <span>worker event loop</span> per such <span>agent</span>.</p>
88919-
88920-
<p>A <dfn>worklet event loop</dfn> is the <span>event loop</span> used by <span data-x="worklet
88921-
agent">worklet agents</span>.</p>
88922-
88923-
<p class="XXX">As detailed in <a href="https://github.com/whatwg/html/issues/4213">issue #4213</a>
88924-
the situation for worklets is more complicated.</p>
88898+
described in this section. Each <span>agent</span> has an associated <span>event loop</span>,
88899+
which is unique to that agent.</p>
88900+
88901+
<p>The <span>event loop</span> of a <span>similar-origin window agent</span> is known as a
88902+
<dfn>window event loop</dfn>. The <span>event loop</span> of a <span>dedicated worker
88903+
agent</span>, <span>shared worker agent</span>, or <span>service worker agent</span> is known as a
88904+
<dfn>worker event loop</dfn>. And the <span>event loop</span> of a <span>worklet agent</span> is
88905+
known as a <dfn>worklet event loop</dfn>.</p>
88906+
88907+
<div class="note">
88908+
<p><span data-x="event loop">Event loops</span> do not necessarily correspond to implementation
88909+
threads. For example, multiple <span data-x="window event loop">window event loops</span> could
88910+
be cooperatively scheduled in a single thread.</p>
88911+
88912+
<p>However, for the various worker <span data-x="agent">agents</span> that are allocated with
88913+
[[CanBlock]] set to true, the JavaScript specification does place requirements on them regarding
88914+
<span>forward progress</span>, which effectively amount to requiring dedicated per-agent threads
88915+
in those cases.</p>
88916+
</div>
8892588917

8892688918
<div w-nodev>
8892788919

0 commit comments

Comments
 (0)