Skip to content

Commit 688fbea

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. 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 edf19e2 commit 688fbea

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>
@@ -88912,40 +88913,31 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
8891288913

8891388914
</div>
8891488915

88915-
<h4>Event loops</h4> <!-- <dfn>event loop</dfn> -->
88916+
<h4>Event loops</h4>
8891688917

8891788918
<h5 w-nodev>Definitions</h5>
8891888919

8891988920
<p>To coordinate events, user interaction, scripts, rendering, networking, and so forth, user
8892088921
agents must use <dfn data-x="event loop" data-lt="event loop" data-export="">event loops</dfn> as
88921-
described in this section. Each <span>agent</span> has an associated <span>event loop</span>.</p>
88922-
88923-
<p class="note">In the future, this standard hopes to define exactly when <span data-x="event
88924-
loop">event loops</span> can be created or reused.</p>
88925-
88926-
<p>A <dfn>window event loop</dfn> is the <span>event loop</span> used by <span
88927-
data-x="similar-origin window agent">similar-origin window agents</span>. User agents may share an
88928-
<span>event loop</span> across <span data-x="similar-origin window agent">similar-origin window
88929-
agents</span>.</p>
88930-
<!-- Ideally user agents process-isolate similar-origin window agents from each other that are not
88931-
same site. However, this is not the reality in 2019. -->
88932-
88933-
<p class="note">This specification does not currently describe how to handle the complications
88934-
arising from <span data-x="navigate">navigating</span> between <span data-x="similar-origin window
88935-
agent">similar-origin window agents</span>. E.g., when a <span>browsing context</span> <span
88936-
data-x="navigate">navigates</span> from <code data-x="">https://example.com/</code> to <code
88937-
data-x="">https://shop.example/</code>.</p>
88938-
88939-
<p>A <dfn>worker event loop</dfn> is the <span>event loop</span> used by <span data-x="dedicated
88940-
worker agent">dedicated worker agents</span>, <span data-x="shared worker agent">shared worker
88941-
agents</span>, and <span data-x="service worker agent">service worker agents</span>. There must be
88942-
one <span>worker event loop</span> per such <span>agent</span>.</p>
88943-
88944-
<p>A <dfn>worklet event loop</dfn> is the <span>event loop</span> used by <span data-x="worklet
88945-
agent">worklet agents</span>.</p>
88946-
88947-
<p class="XXX">As detailed in <a href="https://github.com/whatwg/html/issues/4213">issue #4213</a>
88948-
the situation for worklets is more complicated.</p>
88922+
described in this section. Each <span>agent</span> has an associated <span>event loop</span>,
88923+
which is unique to that agent.</p>
88924+
88925+
<p>The <span>event loop</span> of a <span>similar-origin window agent</span> is known as a
88926+
<dfn>window event loop</dfn>. The <span>event loop</span> of a <span>dedicated worker
88927+
agent</span>, <span>shared worker agent</span>, or <span>service worker agent</span> is known as a
88928+
<dfn>worker event loop</dfn>. And the <span>event loop</span> of a <span>worklet agent</span> is
88929+
known as a <dfn>worklet event loop</dfn>.</p>
88930+
88931+
<div class="note">
88932+
<p><span data-x="event loop">Event loops</span> do not necessarily correspond to implementation
88933+
threads. For example, multiple <span data-x="window event loop">window event loops</span> could
88934+
be cooperatively scheduled in a single thread.</p>
88935+
88936+
<p>However, because the various worker <span data-x="agent">agents</span> are allocated with
88937+
[[CanBlock]] set to true, the JavaScript specification does place requirements on them regarding
88938+
<span>forward progress</span>, which effectively amount to requiring dedicated per-agent threads
88939+
in those cases.</p>
88940+
</div>
8894988941

8895088942
<div w-nodev>
8895188943

0 commit comments

Comments
 (0)