Skip to content

Commit

Permalink
Clean up the event loop and agent correspondence
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
domenic authored Mar 26, 2020
1 parent 71d44d0 commit cd59059
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2824,6 +2824,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-candidate-executions">candidate execution</dfn></li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#current-realm">current Realm Record</dfn></li>
<li><dfn data-x-href="https://tc39.es/ecma262/#early-error-rule">early error</dfn></li>
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-forward-progress">forward progress</dfn></li>
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-invariants-of-the-essential-internal-methods">invariants of the essential internal methods</dfn></li>
<li><dfn data-x-href="https://tc39.es/ecma262/#sec-execution-contexts">JavaScript execution context</dfn></li>
<li><dfn data-x-href="https://tc39.es/ecma262/#execution-context-stack">JavaScript execution context stack</dfn></li>
Expand Down Expand Up @@ -88888,40 +88889,31 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {

</div>

<h4>Event loops</h4> <!-- <dfn>event loop</dfn> -->
<h4>Event loops</h4>

<h5 w-nodev>Definitions</h5>

<p>To coordinate events, user interaction, scripts, rendering, networking, and so forth, user
agents must use <dfn data-x="event loop" data-lt="event loop" data-export="">event loops</dfn> as
described in this section. Each <span>agent</span> has an associated <span>event loop</span>.</p>

<p class="note">In the future, this standard hopes to define exactly when <span data-x="event
loop">event loops</span> can be created or reused.</p>

<p>A <dfn>window event loop</dfn> is the <span>event loop</span> used by <span
data-x="similar-origin window agent">similar-origin window agents</span>. User agents may share an
<span>event loop</span> across <span data-x="similar-origin window agent">similar-origin window
agents</span>.</p>
<!-- Ideally user agents process-isolate similar-origin window agents from each other that are not
same site. However, this is not the reality in 2019. -->

<p class="note">This specification does not currently describe how to handle the complications
arising from <span data-x="navigate">navigating</span> between <span data-x="similar-origin window
agent">similar-origin window agents</span>. E.g., when a <span>browsing context</span> <span
data-x="navigate">navigates</span> from <code data-x="">https://example.com/</code> to <code
data-x="">https://shop.example/</code>.</p>

<p>A <dfn>worker event loop</dfn> is the <span>event loop</span> used by <span data-x="dedicated
worker agent">dedicated worker agents</span>, <span data-x="shared worker agent">shared worker
agents</span>, and <span data-x="service worker agent">service worker agents</span>. There must be
one <span>worker event loop</span> per such <span>agent</span>.</p>

<p>A <dfn>worklet event loop</dfn> is the <span>event loop</span> used by <span data-x="worklet
agent">worklet agents</span>.</p>

<p class="XXX">As detailed in <a href="https://github.com/whatwg/html/issues/4213">issue #4213</a>
the situation for worklets is more complicated.</p>
described in this section. Each <span>agent</span> has an associated <span>event loop</span>,
which is unique to that agent.</p>

<p>The <span>event loop</span> of a <span>similar-origin window agent</span> is known as a
<dfn>window event loop</dfn>. The <span>event loop</span> of a <span>dedicated worker
agent</span>, <span>shared worker agent</span>, or <span>service worker agent</span> is known as a
<dfn>worker event loop</dfn>. And the <span>event loop</span> of a <span>worklet agent</span> is
known as a <dfn>worklet event loop</dfn>.</p>

<div class="note">
<p><span data-x="event loop">Event loops</span> do not necessarily correspond to implementation
threads. For example, multiple <span data-x="window event loop">window event loops</span> could
be cooperatively scheduled in a single thread.</p>

<p>However, for the various worker <span data-x="agent">agents</span> that are allocated with
[[CanBlock]] set to true, the JavaScript specification does place requirements on them regarding
<span>forward progress</span>, which effectively amount to requiring dedicated per-agent threads
in those cases.</p>
</div>

<div w-nodev>

Expand Down

0 comments on commit cd59059

Please sign in to comment.