Skip to content

Commit 415d683

Browse files
committed
Define agents and agent clusters
Define the infrastructure for SharedArrayBuffer. This also clarifies along which boundaries a browser implementation can use processes and threads. shaky foundation. Because of that, similar-origin window agents are the best place to store state that would formerly go on unit of related similar-origin browsing contexts. tc39/ecma262#882 is follow-up to define agents in more detail; in particular make their implicit realms slot explicit. w3c/css-houdini-drafts#224 is follow-up to define worklet ownership better which is needed to define how they relate to agent (sub)clusters. Fixes part of #2260. Fixes w3c/ServiceWorker#1115. Fixes most of w3c/css-houdini-drafts#380 (no tests and no nice grouping of multiple realms in a single agent as that is not needed).
1 parent 77c694e commit 415d683

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

source

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
28552855

28562856
<ul class="brief">
28572857
<li><dfn data-x-href="https://tc39.github.io/ecma262/#active-function-object">active function object</dfn></li>
2858+
<li><dfn data-x-href="https://tc39.github.io/ecma262/#sec-agents">agent</dfn> and
2859+
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-agent-clusters">agent cluster</dfn></li>
28582860
<li><dfn data-x-href="https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion">automatic semicolon insertion</dfn></li>
28592861
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#current-realm">current Realm Record</dfn></li>
28602862
<li><dfn data-x-href="https://tc39.github.io/ecma262/#early-error-rule">early error</dfn></li>
@@ -2936,6 +2938,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
29362938
<li>The <dfn data-x="js-abstract-equality" data-x-href="https://tc39.github.io/ecma262/#sec-abstract-equality-comparison">Abstract Equality Comparison</dfn> algorithm</li>
29372939
<li>The <dfn data-x="js-strict-equality" data-x-href="https://tc39.github.io/ecma262/#sec-strict-equality-comparison">Strict Equality Comparison</dfn> algorithm</li>
29382940
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-date-objects"><code>Date</code></dfn> class</li>
2941+
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-sharedarraybuffer-objects"><code>SharedArrayBuffer</code></dfn> class</li>
29392942
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror"><code>TypeError</code></dfn> class</li>
29402943
<li>The <dfn data-x="js-RangeError" data-x-href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror"><code>RangeError</code></dfn> class</li>
29412944
<li>The <dfn data-x="js-typeof" data-x-href="https://tc39.github.io/ecma262/#sec-typeof-operator"><code>typeof</code></dfn> operator</li>
@@ -3780,6 +3783,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
37803783
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#dfn-serviceworker-link">serviceworker link</dfn></li>
37813784
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#serviceworker"><code>ServiceWorker</code></dfn> interface</li>
37823785
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#serviceworkercontainer"><code>ServiceWorkerContainer</code></dfn> interface</li>
3786+
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope"><code>ServiceWorkerGlobalScope</code></dfn> interface</li>
37833787
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#dfn-use-cache">use cache</dfn></li>
37843788
</ul>
37853789

@@ -3905,6 +3909,17 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
39053909
</ul>
39063910
</dd>
39073911

3912+
<dt>Worklets</dt>
3913+
3914+
<dd>
3915+
<p>The following feature is defined in the <cite>Worklets</cite> specification: <ref
3916+
spec=WORKLETS></p>
3917+
3918+
<ul class="brief">
3919+
<li><dfn data-x-href="https://drafts.css-houdini.org/worklets/#workletglobalscope"><code>WorkletGlobalScope</code></dfn></li>
3920+
</ul>
3921+
</dd>
3922+
39083923
</dl>
39093924

39103925
<hr>
@@ -88475,6 +88490,139 @@ import "https://example.com/foo/../module2.js";</pre>
8847588490
data-x="concept-module-script-module-record">module record</span>.</p></li>
8847688491
</ol>
8847788492

88493+
<h5>Integration with the JavaScript agent formalism</h5>
88494+
88495+
<p>JavaScript defines the concept of an <span>agent</span>. Until such a time that this standard
88496+
has a better handle on lifetimes, we define five types of <span data-x="agent">agents</span> that
88497+
user agents must allocate at the appropriate time.</p>
88498+
88499+
<p class="note">In the future, when this specification has a better handle on lifetimes, we hope
88500+
to define exactly when <span data-x="agent">agents</span> and <span data-x="agent cluster">agent
88501+
clusters</span> are created.</p>
88502+
88503+
<dl>
88504+
<dt><dfn data-export="">Similar-origin window agent</dfn></dt>
88505+
<dd>
88506+
<p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span
88507+
data-x="JavaScript realm">realms</span> consists of all <span
88508+
data-x="concept-global-object-realm">realms</span> of <code>Window</code> objects whose
88509+
<span>relevant settings object</span>'s <span>responsible browsing context</span> is in the same
88510+
<span>unit of related similar-origin browsing contexts</span>.</p>
88511+
88512+
<p class="note">Two <code>Window</code> objects that are <span>same origin</span> can be in
88513+
different <span data-x="similar-origin window agent">similar-origin window agents</span>, for
88514+
instance iif they are each in their own <span>top-level browsing context</span>.</p>
88515+
</dd>
88516+
88517+
<dt><dfn data-export="">Dedicated worker agent</dfn></dt>
88518+
<dd><p>An <span>agent</span> whose [[CanBlock]] is true and whose set of <span data-x="JavaScript
88519+
realm">realms</span> consists of a single <code>DedicatedWorkerGlobalScope</code> object's <span
88520+
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88521+
88522+
<dt><dfn data-export="">Shared worker agent</dfn></dt>
88523+
<dd><p>An <span>agent</span> whose [[CanBlock]] is true and whose set of <span data-x="JavaScript
88524+
realm">realms</span> consists a single <code>SharedWorkerGlobalScope</code> object's <span
88525+
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88526+
88527+
<dt><dfn data-export="">Service worker agent</dfn></dt>
88528+
<dd><p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span data-x="JavaScript
88529+
realm">realms</span> consists of a single <code>ServiceWorkerGlobalScope</code> object's <span
88530+
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88531+
88532+
<dt><dfn data-export="">Worklet agent</dfn></dt>
88533+
<dd>
88534+
<p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span
88535+
data-x="JavaScript realm">realms</span> consists of a single <code>WorkletGlobalScope</code>
88536+
object's <span data-x="concept-global-object-realm">Realm</span>.</p>
88537+
88538+
<p class="note">While conceptually it might be cleaner for worklets that end up with multiple
88539+
realms to put all those in the same agent, it is not observable in practice.</p>
88540+
</dd>
88541+
</dl>
88542+
88543+
<p>For convenience in what follows, for all <span data-x="agent">agents</span> that are not <span
88544+
data-x="similar-origin window agent">similar-origin window agents</span>, we define <dfn
88545+
data-x="concept-agent-realm">the agent's realm</dfn> to be the single <span data-x="JavaScript
88546+
realm">realm</span> in its set of realms, and <dfn data-x="concept-agent-global">the agent's
88547+
global object</dfn> to be <span data-x="concept-agent-realm">the agent's realm</span>'s <span
88548+
data-x="concept-realm-global">global object</span>.</p>
88549+
88550+
<p>To determine the manifestation of JavaScript's <span>agent cluster</span> concept in user
88551+
agents, we first define an <dfn>agent subcluster</dfn> for a given <span>agent</span>
88552+
<var>agent</var>, based on its type:</p>
88553+
88554+
<dl class="switch">
88555+
<dt><span>Similar-origin window agent</span></dt>
88556+
<dd><p>The set containing <var>agent</var> and any <span>dedicated worker agent</span> whose
88557+
<span data-x="concept-agent-global">global object</span>'s <span>owner set</span> contains a
88558+
<code>Document</code> object whose <span data-x="concept-relevant-realm">relevant Realm</span>
88559+
belongs to <var>agent</var>.</p></dd>
88560+
88561+
<dt><span>Dedicated worker agent</span></dt>
88562+
<dd>
88563+
<p>The set containing:
88564+
88565+
<ul>
88566+
<li><var>agent</var>,</li>
88567+
<li>any <span>agent</span> with a <span data-x="JavaScript realm">realm</span> whose <span
88568+
data-x="concept-realm-global">global object</span> is in <var>agent</var>'s <span
88569+
data-x="concept-agent-global">global object</span>'s <span>owner set</span>, and</li>
88570+
<li>any <span>dedicated worker agent</span> whose <span data-x="concept-agent-global">global
88571+
object</span> is in <var>agent</var>'s <span data-x="concept-agent-global">global
88572+
object</span>'s <span>worker set</span>.
88573+
</ul>
88574+
</dd>
88575+
88576+
<dt><span>Worklet agent</span></dt>
88577+
<dd><p class="&#x0058;&#x0058;&#x0058;">Currently worklets have no clearly defined owner, see: <a
88578+
href="https://github.com/w3c/css-houdini-drafts/issues/224">w3c/css-houdini-drafts issue
88579+
#224</a>.</p></dd>
88580+
88581+
<dt><span>Shared worker agent</span></dt>
88582+
<dt><span>Service worker agent</span></dt>
88583+
<dd><p>The set containing <var>agent</var> and any <span>dedicated worker agent</span> whose
88584+
<span data-x="concept-agent-global">global object</span> is in <var>agent</var>'s <span
88585+
data-x="concept-agent-global">global object</span>'s <span>worker set</span>.</p></dd>
88586+
</dl>
88587+
88588+
<p>Then, the transitive closure of <span data-x="agent subcluster">agent subclusters</span> is an
88589+
<span>agent cluster</span>.</p>
88590+
88591+
<p class="note">The <span>agent cluster</span> concept is crucial for defining the JavaScript
88592+
memory model, and in particular among which <span data-x="agent">agents</span> the backing data of
88593+
<code>SharedArrayBuffer</code> objects can be shared.</p>
88594+
88595+
<div class="example">
88596+
<p>The following pairs of global objects are each within the same <span>agent cluster</span>, and
88597+
thus can use <code>SharedArrayBuffer</code> instances to share memory with each other:</p>
88598+
88599+
<ul class="brief">
88600+
<li>A <code>Window</code> and a dedicated worker that it created</li>
88601+
88602+
<li>A worker (of any type) and a dedicated worker it creates</li>
88603+
88604+
<li>A <code>Window</code> and the <code>Window</code> of an <code>iframe</code> element that
88605+
could be <span>same origin-domain</span></li>
88606+
88607+
<li>A <code>Window</code> and the <code>Window</code> that opened it</li>
88608+
</ul>
88609+
88610+
<p>The following pairs of global objects are <em>not</em> within the same <span>agent
88611+
cluster</span>, and thus cannot share memory:</p>
88612+
88613+
<ul class="brief">
88614+
<li>A <code>Window</code> and a shared worker it creates</li>
88615+
88616+
<li>A worker (of any type) and a shared worker it creates</li>
88617+
88618+
<li>A <code>Window</code> and a service worker it creates</li>
88619+
88620+
<li>A <code>Window</code> and the <code>Window</code> of an <code>iframe</code> element that
88621+
cannot be <span>same origin-domain</span></li>
88622+
</ul>
88623+
88624+
</div>
88625+
8847888626
</div>
8847988627

8848088628

@@ -119778,6 +119926,9 @@ INSERT INTERFACES HERE
119778119926
<dt id="refsWHATWGWIKI">[WHATWGWIKI]</dt>
119779119927
<dd><cite><a href="https://wiki.whatwg.org/">The WHATWG Wiki</a></cite>. WHATWG.</dd>
119780119928

119929+
<dt id="refsWORKLETS">[WORKLETS]</dt>
119930+
<dd><cite><a href="https://drafts.css-houdini.org/worklets/">Worklets</a></cite>. I. Kilpatrick. W3C.</dd>
119931+
119781119932
<dt id="refsWSP">[WSP]</dt>
119782119933
<dd><cite><a href="https://tools.ietf.org/html/rfc6455">The WebSocket protocol</a></cite>, I. Fette, A. Melnikov. IETF.</dd>
119783119934

0 commit comments

Comments
 (0)