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.

Tests: web-platform-tests/wpt#5569.

Follow-up to define similar-origin window agents upon a less shaky
foundation is whatwg#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.

Follow-up for better agent shutdown notifications: whatwg#2581.

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 whatwg#2260. Fixes whatwg#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).
  • Loading branch information
annevk authored and Alice Boxhall committed Jan 7, 2019
1 parent fc1208b commit 6190b09
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 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 @@ -88480,6 +88495,133 @@ 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>

<p class="&#x0058;&#x0058;&#x0058;">JavaScript is expected to define <span
data-x="agent">agents</span> in more detail; in particular that they hold a set of <span
data-x="concept-global-object-realm">realms</span>: <a
href="https://github.com/tc39/ecma262/issues/882">tc39/ecma262 issue #882</a>.</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 if they are each in their own <span>unit of related similar-origin browsing
contexts</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>

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

<p><dfn>Can share memory with</dfn> defines an equivalence relation. An <span>agent cluster</span>
consists of all <span data-x="agent">agents</span> in the same equivalence class with respect to
the <span>can share memory with</span> equivalence relation.</p>

<p>A <span>similar-origin window agent</span>, <span>dedicated worker agent</span>, <span>shared
worker agent</span>, or <span>service worker agent</span>, <var>agent</var>, <span>can share
memory with</span> any <span>dedicated worker agent</span> whose single <span data-x="JavaScript
realm">realm</span>'s <span data-x="concept-realm-global">global object</span>'s <span>owner
set</span> contains an item whose <span data-x="concept-relevant-realm">relevant Realm</span>
belongs to <var>agent</var>.</p>

<p class="note">We use item above as an <span>owner set</span> can contain <code>Document</code>
objects.</p>

<p class="&#x0058;&#x0058;&#x0058;">A <span>worklet agent</span> &hellip; 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>

<p>In addition, any <span>agent</span> <var>A</var> <span>can share memory with</span>:</p>

<ul class="brief">
<li><var>A</var>,</li>

<li>any <span>agent</span> <var>B</var> such that <var>B</var> <span>can share memory with</span>
<var>A</var>, and</li>

<li>any <span>agent</span> <var>B</var> such that there exists an <span>agent</span>
<var>C</var>, where <var>A</var> <span>can share memory with</span> <var>C</var> and <var>C</var>
<span>can share memory with</span> <var>B</var>.</li>
</ul>

<p>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> object and a dedicated worker that it created.</li>

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

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

<li>A <code>Window</code> object and a <span>same origin-domain</span> <code>Window</code>
object 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> object and a shared worker it created.</li>

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

<li>A <code>Window</code> object and a service worker it created.</li>

<li>A <code>Window</code> object <var></var> and the <code>Window</code> object of an
<code>iframe</code> element that <var>A</var> created that cannot be <span>same
origin-domain</span> with <var>A</var>.</li>
</ul>
</div>

</div>


Expand Down Expand Up @@ -119778,6 +119920,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 6190b09

Please sign in to comment.