Skip to content

Commit 736c6e7

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. Tests: web-platform-tests/wpt#5569. Follow-up to define similar-origin window agents upon a less shaky foundation is #2528. 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 #851. 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 25a94f6 commit 736c6e7

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

source

Lines changed: 133 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>
@@ -88451,6 +88466,121 @@ import "https://example.com/foo/../module2.js";</pre>
8845188466
data-x="concept-module-script-module-record">module record</span>.</p></li>
8845288467
</ol>
8845388468

88469+
<h5>Integration with the JavaScript agent formalism</h5>
88470+
88471+
<p>JavaScript defines the concept of an <span>agent</span>. Until such a time that this standard
88472+
has a better handle on lifetimes, we define five types of <span data-x="agent">agents</span> that
88473+
user agents must allocate at the appropriate time.</p>
88474+
88475+
<p class="note">In the future, when this specification has a better handle on lifetimes, we hope
88476+
to define exactly when <span data-x="agent">agents</span> and <span data-x="agent cluster">agent
88477+
clusters</span> are created.</p>
88478+
88479+
<p class="&#x0058;&#x0058;&#x0058;">JavaScript is expected to define <span
88480+
data-x="agent">agents</span> in more detail; in particular that they hold a set of <span
88481+
data-x="concept-global-object-realm">realms</span>: <a
88482+
href="https://github.com/tc39/ecma262/issues/882">tc39/ecma262 issue #882</a>.</p>
88483+
88484+
<dl>
88485+
<dt><dfn data-export="">Similar-origin window agent</dfn></dt>
88486+
<dd>
88487+
<p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span
88488+
data-x="JavaScript realm">realms</span> consists of all <span
88489+
data-x="concept-global-object-realm">realms</span> of <code>Window</code> objects whose
88490+
<span>relevant settings object</span>'s <span>responsible browsing context</span> is in the same
88491+
<span>unit of related similar-origin browsing contexts</span>.</p>
88492+
88493+
<p class="note">Two <code>Window</code> objects that are <span>same origin</span> can be in
88494+
different <span data-x="similar-origin window agent">similar-origin window agents</span>, for
88495+
instance if they are each in their own <span>unit of related similar-origin browsing
88496+
contexts</span>.</p>
88497+
</dd>
88498+
88499+
<dt><dfn data-export="">Dedicated worker agent</dfn></dt>
88500+
<dd><p>An <span>agent</span> whose [[CanBlock]] is true and whose set of <span data-x="JavaScript
88501+
realm">realms</span> consists of a single <code>DedicatedWorkerGlobalScope</code> object's <span
88502+
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88503+
88504+
<dt><dfn data-export="">Shared worker agent</dfn></dt>
88505+
<dd><p>An <span>agent</span> whose [[CanBlock]] is true and whose set of <span data-x="JavaScript
88506+
realm">realms</span> consists a single <code>SharedWorkerGlobalScope</code> object's <span
88507+
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88508+
88509+
<dt><dfn data-export="">Service worker agent</dfn></dt>
88510+
<dd><p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span data-x="JavaScript
88511+
realm">realms</span> consists of a single <code>ServiceWorkerGlobalScope</code> object's <span
88512+
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88513+
88514+
<dt><dfn data-export="">Worklet agent</dfn></dt>
88515+
<dd>
88516+
<p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span
88517+
data-x="JavaScript realm">realms</span> consists of a single <code>WorkletGlobalScope</code>
88518+
object's <span data-x="concept-global-object-realm">Realm</span>.</p>
88519+
88520+
<p class="note">While conceptually it might be cleaner for worklets that end up with multiple
88521+
realms to put all those in the same agent, it is not observable in practice.</p>
88522+
</dd>
88523+
</dl>
88524+
88525+
<p>To determine the manifestation of JavaScript's <span>agent cluster</span> concept in user
88526+
agents, we define which <span data-x="agent">agents</span> <dfn>can share memory with</dfn>
88527+
another. Then all the <span data-x="agent">agents</span> that can <span>can share memory
88528+
with</span> each other form an <span>agent cluster</span>.</p>
88529+
88530+
<p class="note">The <span>can share memory with</span> relation is symmetric.</p>
88531+
88532+
<p>A <span>similar-origin window agent</span>, <span>dedicated worker agent</span>, <span>shared
88533+
worker agent</span>, or <span>service worker agent</span>, <var>agent</var>, <span>can share
88534+
memory with</span> any <span>dedicated worker agent</span> whose single <span data-x="JavaScript
88535+
realm">realm</span>'s <span data-x="concept-realm-global">global object</span>'s <span>owner
88536+
set</span> contains an item whose <span data-x="concept-relevant-realm">relevant Realm</span>
88537+
belongs to <var>agent</var>.</p>
88538+
88539+
<p class="note">We use item above as an <span>owner set</span> can contain <code>Document</code>
88540+
objects.</p>
88541+
88542+
<p class="&#x0058;&#x0058;&#x0058;">A <span>worklet agent</span> &hellip; currently worklets have
88543+
no clearly defined owner, see: <a
88544+
href="https://github.com/w3c/css-houdini-drafts/issues/224">w3c/css-houdini-drafts issue
88545+
#224</a>.</p>
88546+
88547+
<p>The <span>agent cluster</span> concept is crucial for defining the JavaScript memory model, and
88548+
in particular among which <span data-x="agent">agents</span> the backing data of
88549+
<code>SharedArrayBuffer</code> objects can be shared.</p>
88550+
88551+
<div class="example">
88552+
<p>The following pairs of global objects are each within the same <span>agent cluster</span>, and
88553+
thus can use <code>SharedArrayBuffer</code> instances to share memory with each other:</p>
88554+
88555+
<ul class="brief">
88556+
<li>A <code>Window</code> object and a dedicated worker that it created.</li>
88557+
88558+
<li>A worker (of any type) and a dedicated worker it created.</li>
88559+
88560+
<li>A <code>Window</code> object <var>A</var> and the <code>Window</code> object of an
88561+
<code>iframe</code> element that <var>A</var> created that could be <span>same
88562+
origin-domain</span> with <var>A</var>.</li>
88563+
88564+
<li>A <code>Window</code> object and a <span>same origin-domain</span> <code>Window</code>
88565+
object that opened it.</li>
88566+
</ul>
88567+
88568+
<p>The following pairs of global objects are <em>not</em> within the same <span>agent
88569+
cluster</span>, and thus cannot share memory:</p>
88570+
88571+
<ul class="brief">
88572+
<li>A <code>Window</code> object and a shared worker it created.</li>
88573+
88574+
<li>A worker (of any type) and a shared worker it created.</li>
88575+
88576+
<li>A <code>Window</code> object and a service worker it created.</li>
88577+
88578+
<li>A <code>Window</code> object <var></var> and the <code>Window</code> object of an
88579+
<code>iframe</code> element that <var>A</var> created that cannot be <span>same
88580+
origin-domain</span> with <var>A</var>.</li>
88581+
</ul>
88582+
</div>
88583+
8845488584
</div>
8845588585

8845688586

@@ -119795,6 +119925,9 @@ INSERT INTERFACES HERE
119795119925
<dt id="refsWHATWGWIKI">[WHATWGWIKI]</dt>
119796119926
<dd><cite><a href="https://wiki.whatwg.org/">The WHATWG Wiki</a></cite>. WHATWG.</dd>
119797119927

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

0 commit comments

Comments
 (0)