From 4db86547f1184e7ceb4f1009cb3bef28101eda4f Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 26 Apr 2017 11:46:01 +0200 Subject: [PATCH] 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: https://github.com/w3c/web-platform-tests/pull/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. Follow-up for better agent shutdown notifications: #2581. https://github.com/tc39/ecma262/issues/882 is follow-up to define agents in more detail; in particular make their implicit realms slot explicit. https://github.com/w3c/css-houdini-drafts/issues/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 https://github.com/w3c/ServiceWorker/issues/1115. Fixes most of https://github.com/w3c/css-houdini-drafts/issues/380 (no tests and no nice grouping of multiple realms in a single agent as that is not needed). --- source | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/source b/source index 271faae73a1..2650e4c3a84 100644 --- a/source +++ b/source @@ -2855,6 +2855,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute @@ -3905,6 +3909,17 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute +
Worklets
+ +
+

The following feature is defined in the Worklets specification:

+ + +
+
@@ -88465,6 +88480,133 @@ import "https://example.com/foo/../module2.js"; data-x="concept-module-script-module-record">module record.

+
Integration with the JavaScript agent formalism
+ +

JavaScript defines the concept of an agent. Until such a time that this standard + has a better handle on lifetimes, we define five types of agents that + user agents must allocate at the appropriate time.

+ +

In the future, when this specification has a better handle on lifetimes, we hope + to define exactly when agents and agent + clusters are created.

+ +

JavaScript is expected to define agents in more detail; in particular that they hold a set of realms: tc39/ecma262 issue #882.

+ +
+
Similar-origin window agent
+
+

An agent whose [[CanBlock]] is false and whose set of realms consists of all realms of Window objects whose + relevant settings object's responsible browsing context is in the same + unit of related similar-origin browsing contexts.

+ +

Two Window objects that are same origin can be in + different similar-origin window agents, for + instance if they are each in their own unit of related similar-origin browsing + contexts.

+
+ +
Dedicated worker agent
+

An agent whose [[CanBlock]] is true and whose set of realms consists of a single DedicatedWorkerGlobalScope object's Realm.

+ +
Shared worker agent
+

An agent whose [[CanBlock]] is true and whose set of realms consists a single SharedWorkerGlobalScope object's Realm.

+ +
Service worker agent
+

An agent whose [[CanBlock]] is false and whose set of realms consists of a single ServiceWorkerGlobalScope object's Realm.

+ +
Worklet agent
+
+

An agent whose [[CanBlock]] is false and whose set of realms consists of a single WorkletGlobalScope + object's Realm.

+ +

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.

+
+
+ +
Integration with the JavaScript agent cluster formalism
+ +

Can share memory with defines an equivalence relation. An agent cluster + consists of all agents in the same equivalence class with respect to + the can share memory with equivalence relation.

+ +

A similar-origin window agent, dedicated worker agent, shared + worker agent, or service worker agent, agent, can share + memory with any dedicated worker agent whose single realm's global object's owner + set contains an item whose relevant Realm + belongs to agent.

+ +

We use item above as an owner set can contain Document + objects.

+ +

A worklet agent … currently worklets have + no clearly defined owner, see: w3c/css-houdini-drafts issue + #224.

+ +

In addition, any agent A can share memory with:

+ + + +

The agent cluster concept is crucial for defining the JavaScript memory model, and + in particular among which agents the backing data of + SharedArrayBuffer objects can be shared.

+ +
+

The following pairs of global objects are each within the same agent cluster, and + thus can use SharedArrayBuffer instances to share memory with each other:

+ + + +

The following pairs of global objects are not within the same agent + cluster, and thus cannot share memory:

+ + +
+ @@ -119758,6 +119900,9 @@ INSERT INTERFACES HERE
[WHATWGWIKI]
The WHATWG Wiki. WHATWG.
+
[WORKLETS]
+
Worklets. I. Kilpatrick. W3C.
+
[WSP]
The WebSocket protocol, I. Fette, A. Melnikov. IETF.