Skip to content

Commit 760880f

Browse files
committed
Make all agent allocation imperative
Closes #5210. Closes #4339 by removing the explicit phrasing of a parallel execution environment, instead relying on the agent infrastructure. Closes #4988 by reintroducing a definition for "similar-origin window agent", separate from its creation algorithm. Like the definition of all agent types, it is now informal, just stating what globals are contained in the agent. Relocates the site-related definitions to the "Origin" section of the spec, adjacent to the "schemelessly same site" and "same site" definitions. Exposes some of the higher-level concepts here to the dev edition.
1 parent 6df77c2 commit 760880f

File tree

1 file changed

+136
-114
lines changed

1 file changed

+136
-114
lines changed

source

Lines changed: 136 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
29272927

29282928
<li>The <dfn data-x="js-abstract-equality" data-x-href="https://tc39.es/ecma262/#sec-abstract-equality-comparison">Abstract Equality Comparison</dfn> algorithm</li>
29292929
<li>The <dfn data-x="js-strict-equality" data-x-href="https://tc39.es/ecma262/#sec-strict-equality-comparison">Strict Equality Comparison</dfn> algorithm</li>
2930+
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-atomics-object"><code>Atomics</code></dfn> object</li>
29302931
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-date-objects"><code>Date</code></dfn> class</li>
29312932
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-regexp-regular-expression-objects"><code>RegExp</code></dfn> class</li>
29322933
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-sharedarraybuffer-objects"><code>SharedArrayBuffer</code></dfn> class</li>
@@ -79174,6 +79175,31 @@ interface <dfn>BarProp</dfn> {
7917479175
</table>
7917579176
</div>
7917679177

79178+
<h4>Sites</h4>
79179+
79180+
<p>A <dfn data-export="">scheme-and-registrable-domain</dfn> is a <span>tuple</span> of a <span
79181+
data-x="concept-url-scheme">scheme</span> and a <span data-x="concept-domain">domain</span>.</p>
79182+
79183+
<p>A <dfn data-export="">site</dfn> is an <span data-x="concept-origin-opaque">opaque
79184+
origin</span>, a <span data-x="concept-origin-tuple">tuple origin</span> whose <span
79185+
data-x="concept-origin-host">host</span>'s <span>registrable domain</span> is null, or a
79186+
<span>scheme-and-registrable-domain</span>.</p>
79187+
79188+
<p>To <dfn data-export="">obtain a site</dfn>, given an origin <var>origin</var>, run these
79189+
steps:</p>
79190+
79191+
<ol>
79192+
<li><p>If <var>origin</var> is an <span data-x="concept-origin-opaque">opaque origin</span>, then
79193+
return <var>origin</var>.</p></li>
79194+
79195+
<li><p>If <var>origin</var>'s <span data-x="concept-origin-host">host</span>'s <span>registrable
79196+
domain</span> is null, then return <var>origin</var>.</p></li>
79197+
79198+
<li><p>Return (<var>origin</var>'s <span data-x="concept-origin-scheme">scheme</span>,
79199+
<var>origin</var>'s <span data-x="concept-origin-host">host</span>'s <span>registrable
79200+
domain</span>).</p></li>
79201+
</ol>
79202+
7917779203
<p>Two <span data-x="origin">origins</span>, <var>A</var> and <var>B</var>, are said to be <dfn
7917879204
data-export="">schemelessly same site</dfn> if the following algorithm returns true:</p>
7917979205

@@ -88345,79 +88371,73 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8834588371
<li><p>Return « Record { [[Key]]: "url", [[Value]]: <var>urlString</var> } ».</p></li>
8834688372
</ol>
8834788373

88374+
</div>
88375+
8834888376
<h5>Integration with the JavaScript agent formalism</h5>
8834988377

8835088378
<p>JavaScript defines the concept of an <span>agent</span>. This section gives the mapping of that
8835188379
language-level concept on to the web platform.</p>
8835288380

88353-
<p class="XXX">JavaScript is expected to define <span data-x="agent">agents</span> in more detail,
88354-
in particular that <span data-x="JavaScript realm">realms</span> have a pointer to their agent.
88355-
See <a href="https://github.com/tc39/ecma262/issues/1357">tc39/ecma262 issue #1357</a>. The
88356-
algorithms which allocate new realms that belong to <span data-x="similar-origin window
88357-
agent">similar-origin window agents</span> include this pointer. For other realms, the following
88358-
section describes the relationship.</p>
88359-
8836088381
<div class="note">
8836188382
<p>Conceptually, the <span>agent</span> concept is an architecture-independent, idealized
8836288383
"thread" in which JavaScript code runs. Such code can involve multiple globals/<span
8836388384
data-x="concept-global-object-realm">realms</span> that can synchronously access each other, and
8836488385
thus needs to run in a single execution thread.</p>
8836588386

88366-
<p>Two <code>Window</code> objects having the same <span>agent</span> does not indicate they can
88367-
directly access all objects created in each other's realms. They would have to be <span>same
88368-
origin-domain</span>; see <span>IsPlatformObjectSameOrigin</span>.</p>
88387+
<p w-nodev>Two <code>Window</code> objects having the same <span>agent</span> does not indicate
88388+
they can directly access all objects created in each other's realms. They would have to be
88389+
<span>same origin-domain</span>; see <span>IsPlatformObjectSameOrigin</span>.</p>
8836988390
</div>
8837088391

88371-
<p>To <dfn data-export="" data-lt="similar-origin window agent" data-x="similar-origin window
88372-
agent">create a similar-origin window agent</dfn>:</p>
88373-
88374-
<ol>
88375-
<li><p>Let <var>signifier</var> be a new unique internal value.</p></li>
88392+
<p>The following types of agents exist on the web platform:</p>
8837688393

88377-
<li><p>Let <var>candidateExecution</var> be a new <span>candidate execution</span>.</p></li>
88378-
88379-
<li><p>Return a new <span>agent</span> whose [[CanBlock]] is true, [[Signifier]] is
88380-
<var>signifier</var>, [[CandidateExecution]] is <var>candidateExecution</var>, and
88381-
[[IsLockFree1]], [[IsLockFree2]], and [[LittleEndian]] are set at the implementation's
88382-
discretion.</p></li>
88383-
</ol>
88384-
88385-
<p class="note">All global objects that use this agent all have a similar <span>origin</span> and
88386-
are allocated via the <span data-x="obtain-similar-origin-window-agent">obtain similar-origin
88387-
window agent</span> algorithm.</p>
88394+
<dl>
88395+
<dt><dfn data-export="">Similar-origin window agent</dfn></dt>
88396+
<dd>
88397+
<p>Contains various <code>Window</code> objects which can potentially reach each other, either
88398+
directly or by using <code data-x="dom-document-domain">document.domain</code>.</p>
8838888399

88389-
<p>In addition to the above definition for <span>similar-origin window agent</span>, until such a
88390-
time that this standard has a better handle on lifetimes, it defines the following other types of
88391-
<span data-x="agent">agents</span> that user agents must allocate at the appropriate time.</p>
88400+
<p class="note">Two <code>Window</code> objects that are <span>same origin</span> can be in
88401+
different <span data-x="similar-origin window agent">similar-origin window agents</span>, for
88402+
instance if they are each in their own <span>browsing context group</span>.</p>
88403+
</dd>
8839288404

88393-
<dl>
8839488405
<dt><dfn data-export="">Dedicated worker agent</dfn></dt>
88395-
<dd><p>An <span>agent</span> whose [[CanBlock]] is true and whose set of <span data-x="JavaScript
88396-
realm">realms</span> consists of a single <code>DedicatedWorkerGlobalScope</code> object's <span
88397-
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88406+
<dd><p>Contains a single <code>DedicatedWorkerGlobalScope</code>.</p></dd>
8839888407

8839988408
<dt><dfn data-export="">Shared worker agent</dfn></dt>
88400-
<dd><p>An <span>agent</span> whose [[CanBlock]] is true and whose set of <span data-x="JavaScript
88401-
realm">realms</span> consists a single <code>SharedWorkerGlobalScope</code> object's <span
88402-
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88409+
<dd><p>Contains a single <code>SharedWorkerGlobalScope</code>.</p></dd>
8840388410

8840488411
<dt><dfn data-export="">Service worker agent</dfn></dt>
88405-
<dd><p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span data-x="JavaScript
88406-
realm">realms</span> consists of a single <code>ServiceWorkerGlobalScope</code> object's <span
88407-
data-x="concept-global-object-realm">Realm</span>.</p></dd>
88412+
<dd><p>Contains a single <code>ServiceWorkerGlobalScope</code>.</p></dd>
8840888413

8840988414
<dt><dfn data-export="">Worklet agent</dfn></dt>
8841088415
<dd>
88411-
<p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span
88412-
data-x="JavaScript realm">realms</span> consists of a single <code>WorkletGlobalScope</code>
88413-
object's <span data-x="concept-global-object-realm">Realm</span>.</p>
88416+
<p>Contains a single <code>WorkletGlobalScope</code> object.</p>
8841488417

8841588418
<p class="note">Although a given worklet can have multiple realms, each such realm needs its own
8841688419
agent, as each realm can be executing code independently and at the same time as the others.</p>
8841788420
</dd>
8841888421
</dl>
8841988422

88420-
<hr>
88423+
<p>Only <span data-x="shared worker agent">shared</span> and <span data-x="dedicated worker
88424+
agent">dedicated worker agents</span> allow the use of JavaScript <code>Atomics</code> APIs to
88425+
potentially <span data-x="forward progress">block</span>.</p>
88426+
88427+
<div w-nodev>
88428+
88429+
<p>To <dfn>create an agent</dfn>, given a boolean <var>canBlock</var>:</p>
88430+
88431+
<ol>
88432+
<li><p>Let <var>signifier</var> be a new unique internal value.</p></li>
88433+
88434+
<li><p>Let <var>candidateExecution</var> be a new <span>candidate execution</span>.</p></li>
88435+
88436+
<li><p>Return a new <span>agent</span> whose [[CanBlock]] is <var>canBlock</var>, [[Signifier]] is
88437+
<var>signifier</var>, [[CandidateExecution]] is <var>candidateExecution</var>, and
88438+
[[IsLockFree1]], [[IsLockFree2]], and [[LittleEndian]] are set at the implementation's
88439+
discretion.</p></li>
88440+
</ol>
8842188441

8842288442
<p>The <dfn data-export="">relevant agent</dfn> for a <span>platform object</span>
8842388443
<var>platformObject</var> is the <span>agent</span> whose set of <span data-x="JavaScript
@@ -88427,14 +88447,15 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8842788447
<p class="note">The agent equivalent of the <span>current Realm Record</span> is the
8842888448
<span>surrounding agent</span>.</p>
8842988449

88450+
</div>
88451+
8843088452
<h5>Integration with the JavaScript agent cluster formalism</h5>
8843188453

8843288454
<p>JavaScript also defines the concept of an <span>agent cluster</span>, which this standard maps
88433-
to the web platform using the <span>can share memory with</span> equivalence relation detailed
88434-
below, as well as explicit allocation of <span data-x="similar-origin window agent">similar-origin
88435-
window agents</span> to agent clusters. On the web platform, an <span>agent cluster</span>
88436-
consists of all <span data-x="agent">agents</span> in the same equivalence class with respect to
88437-
the <span>can share memory with</span> equivalence relation.</p>
88455+
to the web platform by placing agents appropriately when they are created<span w-nodev> using the
88456+
<span data-x="obtain-similar-origin-window-agent">obtain a similar-origin window agent</span> or
88457+
<span data-x="obtaining a worker/worklet agent">obtain a worker/worklet agent</span>
88458+
algorithms</span>.</p>
8843888459

8843988460
<p>The <span>agent cluster</span> concept is crucial for defining the JavaScript memory model, and
8844088461
in particular among which <span data-x="agent">agents</span> the backing data of
@@ -88448,34 +88469,13 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8844888469
ensure that web developers see interoperable behavior with regard to shared memory, even in the
8844988470
face of varying and changing user agent process models.</p>
8845088471

88472+
<div w-nodev>
88473+
8845188474
<hr>
8845288475

8845388476
<p>The following defines the allocation of the <span data-x="agent cluster">agent clusters</span>
8845488477
of <span data-x="similar-origin window agent">similar-origin window agents</span>.</p>
8845588478

88456-
<p>A <dfn data-export="">scheme-and-registrable-domain</dfn> is a <span>tuple</span> of a <span
88457-
data-x="concept-url-scheme">scheme</span> and a <span data-x="concept-domain">domain</span>.</p>
88458-
88459-
<p>A <dfn data-export="">site</dfn> is an <span data-x="concept-origin-opaque">opaque
88460-
origin</span>, a <span data-x="concept-origin-tuple">tuple origin</span> whose <span
88461-
data-x="concept-origin-host">host</span>'s <span>registrable domain</span> is null, or a
88462-
<span>scheme-and-registrable-domain</span>.</p>
88463-
88464-
<p>To <dfn data-export="">obtain a site</dfn>, given an origin <var>origin</var>, run these
88465-
steps:</p>
88466-
88467-
<ol>
88468-
<li><p>If <var>origin</var> is an <span data-x="concept-origin-opaque">opaque origin</span>, then
88469-
return <var>origin</var>.</p></li>
88470-
88471-
<li><p>If <var>origin</var>'s <span data-x="concept-origin-host">host</span>'s <span>registrable
88472-
domain</span> is null, then return <var>origin</var>.</p></li>
88473-
88474-
<li><p>Return (<var>origin</var>'s <span data-x="concept-origin-scheme">scheme</span>,
88475-
<var>origin</var>'s <span data-x="concept-origin-host">host</span>'s <span>registrable
88476-
domain</span>).</p></li>
88477-
</ol>
88478-
8847988479
<p>An <dfn>agent cluster key</dfn> is a <span>site</span>.</p>
8848088480

8848188481
<p class="XXX"><a href="https://github.com/whatwg/html/pull/4734">whatwg/html #4734</a> is
@@ -88514,8 +88514,8 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8851488514
<ol>
8851588515
<li><p>Let <var>agentCluster</var> be a new <span>agent cluster</span>.</p></li>
8851688516

88517-
<li><p>Add the result of <span data-x="similar-origin window agent">creating a similar-origin
88518-
window agent</span> to <var>agentCluster</var>.</p></li>
88517+
<li><p>Add the result of <span data-x="create an agent">creating an agent</span>, given false,
88518+
to <var>agentCluster</var>.</p></li>
8851988519

8852088520
<li><p>Set <var>group</var>'s <span>agent cluster map</span>[<var>key</var>] to
8852188521
<var>agentCluster</var>.</p></li>
@@ -88526,47 +88526,67 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8852688526
</ol>
8852788527

8852888528
<p class="note">This means that there is only one <span>similar-origin window agent</span> per
88529-
browsing context agent cluster. (However, other types of agents might be in the same cluster, if
88530-
they <span>can share memory with</span> the similar-origin window agent.)</p>
88529+
browsing context agent cluster. (However, <span data-x="dedicated worker agent">dedicated
88530+
worker</span> and <span data-x="worklet agent">worklet agents</span> might be in the same
88531+
cluster.)</p>
8853188532

8853288533
<hr>
8853388534

88534-
<p>The allocation of other types of agents to agent clusters is done via the following <dfn>can
88535-
share memory with</dfn> equivalence relation. Until such a time that this standard has a better
88536-
handle on the lifetimes of those sorts of agents, user agents must allocate new agent clusters, or
88537-
reuse ones created via <span data-x="obtain-browsing-agent-cluster">obtain a browsing context
88538-
agent cluster</span>, in order to ensure that there is an agent cluster for each equivalence class
88539-
of <span>can share memory with</span>.</p>
88535+
<p>The following defines the allocation of the <span data-x="agent cluster">agent clusters</span>
88536+
of all other types of agents.</p>
8854088537

88541-
<p>A <span>similar-origin window agent</span>, <span>dedicated worker agent</span>, <span>shared
88542-
worker agent</span>, or <span>service worker agent</span>, <var>agent</var>, <span>can share
88543-
memory with</span> any <span>dedicated worker agent</span> whose single <span data-x="JavaScript
88544-
realm">realm</span>'s <span data-x="concept-realm-global">global object</span>'s <span>owner
88545-
set</span> contains an item whose <span>relevant agent</span> is <var>agent</var>.</p>
88538+
<p>To <dfn data-x="obtaining a worker/worklet agent">obtain a worker/worklet agent</dfn>, given an
88539+
<span>environment settings object</span> <var>owner</var>, a boolean <var>isTopLevel</var>, and a
88540+
boolean <var>canBlock</var>, run these steps:</p>
8854688541

88547-
<p class="note">"Item" is used above as an <span>owner set</span> can contain
88548-
<code>Document</code> objects.</p>
88542+
<ol>
88543+
<li>
88544+
<p>If <var>isTopLevel</var> is true:</p>
8854988545

88550-
<p>A <span>similar-origin window agent</span> <var>agent</var> <span>can share memory with</span>
88551-
any <span>worklet agent</span> whose single <span data-x="JavaScript realm">realm</span>'s
88552-
<span data-x="concept-realm-global">global object</span>'s
88553-
<span data-x="concept-worklet-owner-document">owner document</span>'s <span>relevant agent</span>
88554-
is <var>agent</var>.</p>
88546+
<ol>
88547+
<li><p>Let <var>agentCluster</var> be a new <span>agent cluster</span>.</p></li>
8855588548

88556-
<p>In addition, any <span>agent</span> <var>A</var> <span>can share memory with</span>:</p>
88549+
<li><p>Let <var>agent</var> be the result of <span data-x="create an agent">creating an
88550+
agent</span> given <var>canBlock</var>.</p></li>
8855788551

88558-
<ul class="brief">
88559-
<li><var>A</var>,</li>
88552+
<li><p>Add <var>agent</var> to <var>agentCluster</var>.</p></li>
8856088553

88561-
<li>any <span>agent</span> <var>B</var> such that <var>B</var> <span>can share memory with</span>
88562-
<var>A</var>, and</li>
88554+
<li><p>Return <var>agent</var>.</p></li>
88555+
</ol>
88556+
</li>
8856388557

88564-
<li>any <span>agent</span> <var>B</var> such that there exists an <span>agent</span>
88565-
<var>C</var>, where <var>A</var> <span>can share memory with</span> <var>C</var> and <var>C</var>
88566-
<span>can share memory with</span> <var>B</var>.</li>
88567-
</ul>
88558+
<li><p>Let <var>ownerAgent</var> be <var>owner</var>'s <span data-x="environment settings
88559+
object's Realm">Realm</span>'s agent.</p></li>
8856888560

88569-
<div class="example">
88561+
<li><p>Let <var>ownerAgentCluster</var> be the agent cluster which contains
88562+
<var>ownerAgent</var>.</p></li>
88563+
88564+
<li><p>Let <var>agent</var> be the result of <span data-x="create an agent">creating an
88565+
agent</span> given <var>canBlock</var>.</p></li>
88566+
88567+
<li><p>Add <var>agent</var> to <var>ownerAgentCluster</var>.</p></li>
88568+
88569+
<li><p>Return <var>agent</var>.</p></li>
88570+
</ol>
88571+
88572+
<p>To <dfn>obtain a dedicated/shared worker agent</dfn>, given an <span>environment settings
88573+
object</span> <var>owner</var> and a boolean <var>isShared</var>, return the result of
88574+
<span>obtaining a worker/worklet agent</span> given <var>owner</var>, <var>isShared</var>, and
88575+
true.</p>
88576+
88577+
<p>To <dfn data-export="">obtain a worklet agent</dfn>, given an <span>environment settings
88578+
object</span> <var>owner</var>, return the result of <span>obtaining a worker/worklet
88579+
agent</span> given <var>owner</var>, false, and false.</p>
88580+
88581+
<p>To <dfn data-export="">obtain a service worker agent</dfn>, given an <span>environment settings
88582+
object</span> <var>owner</var>, return the result of <span>obtaining a worker/worklet
88583+
agent</span> given <var>owner</var>, true, and false.</p>
88584+
88585+
<hr>
88586+
88587+
</div>
88588+
88589+
<div class="example" id="can-share-memory-with">
8857088590
<p>The following pairs of global objects are each within the same <span>agent cluster</span>, and
8857188591
thus can use <code>SharedArrayBuffer</code> instances to share memory with each other:</p>
8857288592

@@ -88606,8 +88626,6 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8860688626
</ul>
8860788627
</div>
8860888628

88609-
</div>
88610-
8861188629

8861288630
<h5 id="runtime-script-errors">Runtime script errors</h5>
8861388631

@@ -97887,15 +97905,6 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9788797905
<var>options</var>, it must run the following steps.</p>
9788897906

9788997907
<ol>
97890-
<li id="worker-processing-model-top">
97891-
97892-
<p>Create a separate parallel execution environment (i.e. a separate thread or process or
97893-
equivalent construct), and run the rest of these steps in that context.</p>
97894-
97895-
<p>For the purposes of timing APIs, this is the <dfn data-export="">official moment of
97896-
creation</dfn> of the worker.</p>
97897-
</li>
97898-
9789997908
<li><p>Let <var>is shared</var> be true if <var>worker</var> is a <code>SharedWorker</code>
9790097909
object, and false otherwise.</p></li>
9790197910

@@ -97907,11 +97916,24 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9790797916
<li><p>If <var>owner</var> is a <code>WorkerGlobalScope</code> object (i.e., we are creating a
9790897917
nested worker), then set <var>parent worker global scope</var> to <var>owner</var>.</p></li>
9790997918

97919+
<li>
97920+
<p>Let <var>agent</var> be the result of <span data-x="obtain a dedicated/shared worker
97921+
agent">obtaining a dedicated/shared worker agent</span> given <var>outside settings</var> and
97922+
<var>is shared</var>.</p>
97923+
97924+
<p id="worker-processing-model-top">For the purposes of timing APIs, this is the <dfn
97925+
data-export="">official moment of creation</dfn> of the worker.</p>
97926+
</li>
97927+
9791097928
<li>
9791197929
<p>Let <var>realm execution context</var> be the result of <span>creating a new JavaScript
9791297930
realm</span> with the following customizations:</p>
9791397931

9791497932
<ul>
97933+
<li><p>For the agent, use <var>agent</var>. <span class="XXX" data-x="">This pointer is not yet
97934+
defined in the JavaScript specification; see <a
97935+
href="https://github.com/tc39/ecma262/issues/1357">tc39/ecma262#1357</a>.</span></p></li>
97936+
9791597937
<li><p>For the global object, if <var>is shared</var> is true, create a new
9791697938
<code>SharedWorkerGlobalScope</code> object. Otherwise, create a new
9791797939
<code>DedicatedWorkerGlobalScope</code> object.</p></li>

0 commit comments

Comments
 (0)