Skip to content

Commit

Permalink
Define agents and agent clusters
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
annevk committed Apr 16, 2017
1 parent 59a4750 commit 11e8452
Showing 1 changed file with 151 additions and 0 deletions.
151 changes: 151 additions & 0 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<ul class="brief">
<li><dfn data-x-href="https://tc39.github.io/ecma262/#active-function-object">active function object</dfn></li>
<li><dfn data-x-href="https://tc39.github.io/ecma262/#sec-agents">agent</dfn> and
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-agent-clusters">agent cluster</dfn></li>
<li><dfn data-x-href="https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion">automatic semicolon insertion</dfn></li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#current-realm">current Realm Record</dfn></li>
<li><dfn data-x-href="https://tc39.github.io/ecma262/#early-error-rule">early error</dfn></li>
Expand Down Expand Up @@ -2936,6 +2938,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<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>
<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>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-date-objects"><code>Date</code></dfn> class</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-sharedarraybuffer-objects"><code>SharedArrayBuffer</code></dfn> class</li>
<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>
<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>
<li>The <dfn data-x="js-typeof" data-x-href="https://tc39.github.io/ecma262/#sec-typeof-operator"><code>typeof</code></dfn> operator</li>
Expand Down Expand Up @@ -3780,6 +3783,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#dfn-serviceworker-link">serviceworker link</dfn></li>
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#serviceworker"><code>ServiceWorker</code></dfn> interface</li>
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#serviceworkercontainer"><code>ServiceWorkerContainer</code></dfn> interface</li>
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope"><code>ServiceWorkerGlobalScope</code></dfn> interface</li>
<li><dfn data-x-href="https://w3c.github.io/ServiceWorker/#dfn-use-cache">use cache</dfn></li>
</ul>

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

<dt>Worklets</dt>

<dd>
<p>The following feature is defined in the <cite>Worklets</cite> specification: <ref
spec=WORKLETS></p>

<ul class="brief">
<li><dfn data-x-href="https://drafts.css-houdini.org/worklets/#workletglobalscope"><code>WorkletGlobalScope</code></dfn></li>
</ul>
</dd>

</dl>

<hr>
Expand Down Expand Up @@ -88419,6 +88434,139 @@ import "https://example.com/foo/../module2.js";</pre>
data-x="concept-module-script-module-record">module record</span>.</p></li>
</ol>

<h5>Integration with the JavaScript agent formalism</h5>

<p>JavaScript defines the concept of an <span>agent</span>. Until such a time that this standard
has a better handle on lifetimes, we define five types of <span data-x="agent">agents</span> that
user agents must allocate at the appropriate time.</p>

<p class="note">In the future, when this specification has a better handle on lifetimes, we hope
to define exactly when <span data-x="agent">agents</span> and <span data-x="agent cluster">agent
clusters</span> are created.</p>

<dl>
<dt><dfn data-export="">Similar-origin window agent</dfn></dt>
<dd>
<p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span
data-x="JavaScript realm">realms</span> consists of all <span
data-x="concept-global-object-realm">realms</span> of <code>Window</code> objects whose
<span>relevant settings object</span>'s <span>responsible browsing context</span> is in the same
<span>unit of related similar-origin browsing contexts</span>.</p>

<p class="note">Two <code>Window</code> objects that are <span>same origin</span> can be in
different <span data-x="similar-origin window agent">similar-origin window agents</span>, for
instance iif they are each in their own <span>top-level browsing context</span>.</p>
</dd>

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

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

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

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

<p class="note">While conceptually it might be cleaner for worklets that end up with multiple
realms to put all those in the same agent, it is not observable in practice.</p>
</dd>
</dl>

<p>For convenience in what follows, for all <span data-x="agent">agents</span> that are not <span
data-x="similar-origin window agent">similar-origin window agents</span>, we define <dfn
data-x="concept-agent-realm">the agent's realm</dfn> to be the single <span data-x="JavaScript
realm">realm</span> in its set of realms, and <dfn data-x="concept-agent-global">the agent's
global object</dfn> to be <span data-x="concept-agent-realm">the agent's realm</span>'s <span
data-x="concept-realm-global">global object</span>.</p>

<p>To determine the manifestation of JavaScript's <span>agent cluster</span> concept in user
agents, we first define an <dfn>agent subcluster</dfn> for a given <span>agent</span>
<var>agent</var>, based on its type:</p>

<dl class="switch">
<dt><span>Similar-origin window agent</span></dt>
<dd><p>The set containing <var>agent</var> and any <span>dedicated worker agent</span> whose
<span data-x="concept-agent-global">global object</span>'s <span>owner set</span> contains a
<code>Document</code> object whose <span data-x="concept-relevant-realm">relevant Realm</span>
belongs to <var>agent</var>.</p></dd>

<dt><span>Dedicated worker agent</span></dt>
<dd>
<p>The set containing:

<ul>
<li><var>agent</var>,</li>
<li>any <span>agent</span> with a <span data-x="JavaScript realm">realm</span> whose <span
data-x="concept-realm-global">global object</span> is in <var>agent</var>'s <span
data-x="concept-agent-global">global object</span>'s <span>owner set</span>, and</li>
<li>any <span>dedicated worker agent</span> whose <span data-x="concept-agent-global">global
object</span> is in <var>agent</var>'s <span data-x="concept-agent-global">global
object</span>'s <span>worker set</span>.
</ul>
</dd>

<dt><span>Worklet agent</span></dt>
<dd><p class="&#x0058;&#x0058;&#x0058;">Currently worklets have no clearly defined owner, see: <a
href="https://github.com/w3c/css-houdini-drafts/issues/224">w3c/css-houdini-drafts issue
#224</a>.</p></dd>

<dt><span>Shared worker agent</span></dt>
<dt><span>Service worker agent</span></dt>
<dd><p>The set containing <var>agent</var> and any <span>dedicated worker agent</span> whose
<span data-x="concept-agent-global">global object</span> is in <var>agent</var>'s <span
data-x="concept-agent-global">global object</span>'s <span>worker set</span>.</p></dd>
</dl>

<p>Then, the transitive closure of <span data-x="agent subcluster">agent subclusters</span> is an
<span>agent cluster</span>.</p>

<p class="note">The <span>agent cluster</span> concept is crucial for defining the JavaScript
memory model, and in particular among which <span data-x="agent">agents</span> the backing data of
<code>SharedArrayBuffer</code> objects can be shared.</p>

<div class="example">
<p>The following pairs of global objects are each within the same <span>agent cluster</span>, and
thus can use <code>SharedArrayBuffer</code> instances to share memory with each other:</p>

<ul class="brief">
<li>A <code>Window</code> and a dedicated worker that it created</li>

<li>A worker (of any type) and a dedicated worker it creates</li>

<li>A <code>Window</code> and the <code>Window</code> of an <code>iframe</code> element that
could be <span>same origin-domain</span></li>

<li>A <code>Window</code> and the <code>Window</code> that opened it</li>
</ul>

<p>The following pairs of global objects are <em>not</em> within the same <span>agent
cluster</span>, and thus cannot share memory:</p>

<ul class="brief">
<li>A <code>Window</code> and a shared worker it creates</li>

<li>A worker (of any type) and a shared worker it creates</li>

<li>A <code>Window</code> and a service worker it creates</li>

<li>A <code>Window</code> and the <code>Window</code> of an <code>iframe</code> element that
cannot be <span>same origin-domain</span></li>
</ul>

</div>

</div>


Expand Down Expand Up @@ -119747,6 +119895,9 @@ INSERT INTERFACES HERE
<dt id="refsWHATWGWIKI">[WHATWGWIKI]</dt>
<dd><cite><a href="https://wiki.whatwg.org/">The WHATWG Wiki</a></cite>. WHATWG.</dd>

<dt id="refsWORKLETS">[WORKLETS]</dt>
<dd><cite><a href="https://drafts.css-houdini.org/worklets/">Worklets</a></cite>. I. Kilpatrick. W3C.</dd>

<dt id="refsWSP">[WSP]</dt>
<dd><cite><a href="https://tools.ietf.org/html/rfc6455">The WebSocket protocol</a></cite>, I. Fette, A. Melnikov. IETF.</dd>

Expand Down

0 comments on commit 11e8452

Please sign in to comment.