Skip to content

Commit 8358093

Browse files
annevkinikulin
authored andcommitted
Editorial: restructure ownership of workers to parent-owners
Instead of each worker being owned by a document, have it instead be owned by one or more of its parents (more only in the case of SharedWorkerGlobalScope). This makes it possible to define JavaScript agent clusters (whatwg#2260) and also helps with allowing service workers to have nested workers (whatwg#411). This is marked editorial as it should have no normative impact. This also removes a step that should have been removed as part of whatwg@4e2b006.
1 parent 2432401 commit 8358093

File tree

1 file changed

+67
-72
lines changed

1 file changed

+67
-72
lines changed

source

+67-72
Original file line numberDiff line numberDiff line change
@@ -2401,15 +2401,18 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
24012401
<dfn data-x="map get" data-x-href="https://infra.spec.whatwg.org/#map-get">getting the value of an entry</dfn>, and
24022402
<dfn data-x="map set" data-x-href="https://infra.spec.whatwg.org/#map-set">setting the value of an entry</dfn></li>
24032403
<li>The <dfn data-x-href="https://infra.spec.whatwg.org/#list">list</dfn> data structure and the associated definitions for
2404-
<dfn data-x="list append" data-x-href="https://infra.spec.whatwg.org/#list-append">append</dfn>, and
2404+
<dfn data-x="list append" data-x-href="https://infra.spec.whatwg.org/#list-append">append</dfn>,
2405+
<dfn data-x="list remove" data-x-href="https://infra.spec.whatwg.org/#list-remove">remove</dfn>,
2406+
<dfn data-x="list empty" data-x-href="https://infra.spec.whatwg.org/#list-empty">empty</dfn>,
24052407
<dfn data-x="list contains" data-x-href="https://infra.spec.whatwg.org/#list-contain">contains</dfn>,
24062408
<dfn data-x="list size" data-x-href="https://infra.spec.whatwg.org/#list-size">size</dfn>,
24072409
<dfn data-x="list is empty" data-x-href="https://infra.spec.whatwg.org/#list-is-empty">is empty</dfn>, and
24082410
<dfn data-x="list iterate" data-x-href="https://infra.spec.whatwg.org/#list-iterate">iterate</dfn></li>
24092411
<li>The <dfn data-x-href="https://infra.spec.whatwg.org/#stack">stack</dfn> data structure and the associated definitions for
24102412
<dfn data-x="stack push" data-x-href="https://infra.spec.whatwg.org/#stack-push">push</dfn> and
24112413
<dfn data-x="stack pop" data-x-href="https://infra.spec.whatwg.org/#stack-pop">pop</dfn></li>
2412-
<li>The <dfn data-x="set" data-x-href="https://infra.spec.whatwg.org/#ordered-set">ordered set</dfn> data structure</li>
2414+
<li>The <dfn data-x="set" data-x-href="https://infra.spec.whatwg.org/#ordered-set">ordered set</dfn> data structure and the associated definition for
2415+
<dfn data-x="set append" data-x-href="https://infra.spec.whatwg.org/#set-append">append</dfn></li>
24132416
<li><dfn data-x-href="https://infra.spec.whatwg.org/#html-namespace">HTML namespace</dfn></li>
24142417
<li><dfn data-x-href="https://infra.spec.whatwg.org/#mathml-namespace">MathML namespace</dfn></li>
24152418
<li><dfn data-x-href="https://infra.spec.whatwg.org/#svg-namespace">SVG namespace</dfn></li>
@@ -79148,8 +79151,8 @@ callback <dfn>FrameRequestCallback</dfn> = void (<span>DOMHighResTimeStamp</span
7914879151
</ol>
7914979152

7915079153
<p class="note">Whenever a <code>Document</code> object is <span data-x="discard a
79151-
Document">discarded</span>, it is also removed from the list of <span>the worker's
79152-
<code>Document</code>s</span> of each worker whose list contains that <code>Document</code>.</p>
79154+
Document">discarded</span>, it is also removed from the <span>owner set</span> of each worker
79155+
whose set contains that <code>Document</code>.</p>
7915379156

7915479157
<p>When <dfn data-export="">a <em>browsing context</em> is discarded</dfn>, the strong reference
7915579158
from the user agent itself to the <span>browsing context</span> must be severed, and all the
@@ -96884,6 +96887,19 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {
9688496887
attribute <span>EventHandler</span> <span data-x="handler-WorkerGlobalScope-onunhandledrejection">onunhandledrejection</span>;
9688596888
};</pre>
9688696889

96890+
<p id="the-worker's-documents">A <code>WorkerGlobalScope</code> object has an associated <dfn
96891+
id="concept-WorkerGlobalScope-owner-set" data-export="" data-for="WorkerGlobalScope">owner
96892+
set</dfn> (a <span>set</span> of <code>Document</code> and <code>WorkerGlobalScope</code>
96893+
objects). It is initially empty and populated when the worker is created or obtained.</p>
96894+
96895+
<p class="note">It is a <span>set</span>, instead of a single owner, to accomodate
96896+
<code>SharedWorkerGlobalScope</code> objects.</p>
96897+
96898+
<p>A <code>WorkerGlobalScope</code> object has an associated <dfn id="the-worker's-workers"
96899+
data-export="" data-for="WorkerGlobalScope">worker set</dfn> (a <span>set</span> of
96900+
<code>WorkerGlobalScope</code> objects). It is initially empty and populated when the worker
96901+
creates or obtains further workers.</p>
96902+
9688796903
<p>A <code>WorkerGlobalScope</code> object has an associated <dfn data-export=""
9688896904
data-dfn-for="WorkerGlobalScope" data-x="concept-WorkerGlobalScope-type">type</dfn> ("<code
9688996905
data-x="">classic</code>" or "<code data-x="">module</code>"). It is set during creation.
@@ -97127,63 +97143,48 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9712797143
contexts</span> through <span data-x="channel messaging">message channels</span> and their
9712897144
<code>MessagePort</code> objects.</p>
9712997145

97130-
<p>Each <code>WorkerGlobalScope</code> <var>worker global scope</var> has a list of
97146+
<p>Each <code>WorkerGlobalScope</code> object <var>worker global scope</var> has a list of
9713197147
<dfn data-export="">the worker's ports</dfn>, which consists of all the <code>MessagePort</code>
9713297148
objects that are entangled with another port and that have one (but only one) port owned by
97133-
<var>worker global scope</var>. This list includes <!--all the <code>MessagePort</code> objects
97134-
that are in events pending in the <code>WorkerGlobalScope</code> object's <span>event loop</span>,
97135-
as well as (commented out because in practice it makes no difference either way as far as I can
97136-
tell, and it would be hard to strictly implement since these ports might not yet be across the
97137-
thread boundary)--> the implicit <code>MessagePort</code> in the case of <span
97138-
data-x="DedicatedWorkerGlobalScope">dedicated workers</span>.</p>
97139-
97140-
<p>Each <code>WorkerGlobalScope</code> also has a list of <dfn data-export="">the worker's
97141-
workers</dfn>. Initially this list is empty; it is populated when the worker creates or obtains
97142-
further workers.</p>
97143-
97144-
<p>Finally, each <code>WorkerGlobalScope</code> also has a list of <dfn data-export="">the
97145-
worker's <code>Document</code>s</dfn>. Initially this list is empty; it is populated when the
97146-
worker is created.</p>
97147-
97148-
<p>Whenever a <code>Document</code> <var>d</var> is <dfn data-x="add a document to the
97149-
worker's Documents">added to the worker's <code>Document</code>s</dfn>, the user agent must, for
97150-
each worker <var>q</var> in the list of <span>the worker's workers</span> whose list of
97151-
<span>the worker's <code>Document</code>s</span> does not contain <var>d</var>, <span
97152-
data-x="add a document to the worker's Documents">add <var>d</var> to <var>q</var>'s <code>WorkerGlobalScope</code> owner's list of <span>the worker's
97153-
<code>Document</code>s</span></span>.</p> <!-- suggestions welcome on making this sentence into
97154-
understandable English -->
97149+
<var>worker global scope</var>. This list includes the implicit <code>MessagePort</code> in the
97150+
case of <span data-x="DedicatedWorkerGlobalScope">dedicated workers</span>.</p>
9715597151

9715697152
<p>Whenever a <code>Document</code> object is <span data-x="discard a Document">discarded</span>,
97157-
it must be removed from the list of <span>the worker's <code>Document</code>s</span> of each
97158-
worker whose list contains that <code>Document</code>.</p>
97159-
97160-
<p>Given an <span>environment settings object</span> <var>o</var> when creating or obtaining a
97161-
worker, the <dfn>list of relevant <code>Document</code> objects to add</dfn> depends on the type
97162-
of <span data-x="concept-settings-object-global">global object</span> specified by <var>o</var>.
97163-
If <var>o</var> specifies a <span data-x="concept-settings-object-global">global object</span>
97164-
that is a <code>WorkerGlobalScope</code> object (i.e. if we are creating a nested worker), then
97165-
the relevant <code>Document</code>s are the <span>the worker's <code>Document</code>s</span> of
97166-
the <span data-x="concept-settings-object-global">global object</span> specified by <var>o</var>.
97167-
Otherwise, <var>o</var> specifies a <span data-x="concept-settings-object-global">global
97168-
object</span> that is a <code>Window</code> object, and the relevant <code>Document</code> is just
97169-
the <span>responsible document</span> specified by <var>o</var>.</p>
97153+
it must be <span data-x="list remove">removed</span> from the <span>owner set</span> of each
97154+
<code>WorkerGlobalScope</code> object whose set <span data-x="list contains">contains</span> that
97155+
<code>Document</code> object.</p>
97156+
97157+
<p id="list-of-relevant-document-objects-to-add">Given an <span>environment settings object</span>
97158+
<var>o</var> when creating or obtaining a worker, the <dfn>relevant owner to add</dfn> depends on
97159+
the type of <span data-x="concept-settings-object-global">global object</span> specified by
97160+
<var>o</var>. If <var>o</var> specifies a <span data-x="concept-settings-object-global">global
97161+
object</span> that is a <code>WorkerGlobalScope</code> object (i.e., if we are creating a nested
97162+
worker), then the relevant owner is that global object. Otherwise, <var>o</var> specifies a <span
97163+
data-x="concept-settings-object-global">global object</span> that is a <code>Window</code> object,
97164+
and the relevant owner is the <span>responsible document</span> specified by <var>o</var>.</p>
9717097165

9717197166
<hr>
9717297167

97173-
<p>A worker is said to be a <dfn>permissible worker</dfn> if its list of <span>the worker's
97174-
<code>Document</code>s</span> is not empty, or if its list has been empty for no more than a short
97175-
user-agent-defined timeout value, its <code>WorkerGlobalScope</code> is actually a
97176-
<code>SharedWorkerGlobalScope</code> object (i.e. the worker is a shared worker), and the user
97177-
agent has a <span>browsing context</span> whose <code>Document</code> is not <span>completely
97178-
loaded</span>.</p>
97168+
<p>A worker is said to be a <dfn>permissible worker</dfn> if its <code>WorkerGlobalScope</code>'s
97169+
<span>owner set</span> is not <span data-x="list is empty">empty</span> or:</p>
97170+
97171+
<ul class=brief>
97172+
<li>its <span>owner set</span> has been <span data-x="list is empty">empty</span> for no more
97173+
than a short user-agent-defined timeout value,</li>
97174+
<li>its <code>WorkerGlobalScope</code> object is a <code>SharedWorkerGlobalScope</code> object
97175+
(i.e., the worker is a shared worker), and</li>
97176+
<li>the user agent has a <span>browsing context</span> whose <code>Document</code> object is not
97177+
<span>completely loaded</span>.</li>
97178+
</ul>
9717997179

9718097180
<p class="note">The second part of this definition allows a shared worker to survive for a short
9718197181
time while a page is loading, in case that page is going to contact the shared worker again. This
9718297182
can be used by user agents as a way to avoid the cost of restarting a shared worker used by a site
9718397183
when the user is navigating from page to page within that site.</p>
9718497184

97185-
<p>A worker is said to be an <dfn>active needed worker</dfn> if any of the <code>Document</code>
97186-
objects in <span>the worker's <code>Document</code>s</span> are <span>fully active</span>.</p>
97185+
<p>A worker is said to be an <dfn>active needed worker</dfn> if any its <span data-x="owner
97186+
set">owners</span> are either <code>Document</code> objects that are <span>fully active</span> or
97187+
<span data-x="active needed worker">active needed workers</span>.</p>
9718797188

9718897189
<p>A worker is said to be a <dfn>protected worker</dfn> if it is an <span>active needed
9718997190
worker</span> and either it has outstanding timers, database transactions, or network connections,
@@ -97219,15 +97220,13 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9721997220
<li><p>Let <var>is shared</var> be true if <var>worker</var> is a <code>SharedWorker</code>
9722097221
object, and false otherwise.</p></li>
9722197222

97222-
<li><p>Let <var>docs</var> be the <span>list of relevant <code>Document</code> objects to
97223-
add</span> given <var>outside settings</var>.</p></li>
97223+
<li><p>Let <var>owner</var> be the <span>relevant owner to add</span> given <var>outside
97224+
settings</var>.</p></li>
9722497225

9722597226
<li><p>Let <var>parent worker global scope</var> be null.</p>
9722697227

97227-
<li><p>If <var>outside settings</var>'s <span data-x="concept-settings-object-global">global
97228-
object</span> is a <code>WorkerGlobalScope</code> object (i.e. we are creating a nested worker),
97229-
set <var>parent worker global scope</var> to <var>outside settings</var>'s <span
97230-
data-x="concept-settings-object-global">global object</span>.</p></li>
97228+
<li><p>If <var>owner</var> is a <code>WorkerGlobalScope</code> object (i.e., we are creating a
97229+
nested worker), then set <var>parent worker global scope</var> to <var>owner</var>.</p></li>
9723197230

9723297231
<li>
9723397232
<p>Call the JavaScript <span
@@ -97334,13 +97333,12 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9733497333

9733597334
<li><p><span>Entangle</span> <var>outside port</var> and <var>inside port</var>.</p></li>
9733697335

97337-
<li><p><span data-x="add a document to the worker's Documents">Add to <var>worker global
97338-
scope</var>'s list of <span>the worker's <code>Document</code>s</span></span> the
97339-
<code>Document</code> objects in <var>docs</var>.</p></li>
97336+
<li><p><span data-x="set append">Append</span> <var>owner</var> to <var>worker global
97337+
scope</var>'s <span>owner set</span>.</p></li>
9734097338

97341-
<li><p>If <var>parent worker global scope</var> is not null, add <var>worker global scope</var>
97342-
to the list of <span>the worker's workers</span> of <var>parent worker global
97343-
scope</var>.</p></li>
97339+
<li><p>If <var>parent worker global scope</var> is not null, then <span data-x="set
97340+
append">append</span> <var>worker global scope</var> to <var>parent worker global scope</var>'s
97341+
<span>worker set</span>.</p></li>
9734497342

9734597343
<li><p>Set <var>worker global scope</var>'s <span
9734697344
data-x="concept-WorkerGlobalScope-type">type</span> to the value of the <code
@@ -97436,8 +97434,8 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9743697434
<li>
9743797435

9743897436
<!-- this has no normative impact but makes it clearer that the worker is irrelevant now, and
97439-
doesn't have to survive until its Documents all die off too --> <p>Empty the worker's list of
97440-
<span>the worker's <code>Document</code>s</span>.</p>
97437+
doesn't have to survive until its Documents all die off too --> <p><span data-x="list
97438+
empty">Empty</span> <var>worker global scope</var>'s <span>owner set</span>.</p>
9744197439

9744297440
</li>
9744397441

@@ -97811,9 +97809,6 @@ enum <dfn>WorkerType</dfn> { "classic", "module" };
9781197809

9781297810
<li><p>Associate the <var>outside port</var> with <var>worker</var>.</p></li>
9781397811

97814-
<li><p>Let <var>docs</var> be the <span>list of relevant <code>Document</code> objects to
97815-
add</span> given <var>outside settings</var>.</p></li>
97816-
9781797812
<li><p>Return <var>worker</var>, and run the following step <span>in parallel</span>.</p></li>
9781897813

9781997814
<li><p><span>Run a worker</span> given <var>worker</var>, <var>worker URL</var>, <var>outside
@@ -97962,15 +97957,15 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
9796297957
data-x="dom-MessageEvent-source">source</code> attribute initialized to <var>inside
9796397958
port</var>.</p></li>
9796497959

97965-
<li><p><span data-x="add a document to the worker's Documents">Add to <var>worker global
97966-
scope</var>'s list of <span>the worker's <code>Document</code>s</span></span> the
97967-
<span>list of relevant <code>Document</code> objects to add</span> given <var>outside
97968-
settings</var>.</p></li>
97960+
<li><p><span data-x="set append">Append</span> the <span>relevant owner to add</span> given
97961+
<var>outside settings</var> to <var>worker global scope</var>'s <span>owner
97962+
set</span>.</p></li>
9796997963

9797097964
<li><p>If <var>outside settings</var>'s <span data-x="concept-settings-object-global">global
97971-
object</span> is a <code>WorkerGlobalScope</code> object, add <var>worker global scope</var>
97972-
to the list of <span>the worker's workers</span> of <var>outside settings</var>'s <span
97973-
data-x="concept-settings-object-global">global object</span>.</p></li>
97965+
object</span> is a <code>WorkerGlobalScope</code> object, then <span data-x="set
97966+
append">append</span> <var>worker global scope</var> to <var>outside settings</var>'s <span
97967+
data-x="concept-settings-object-global">global object</span>'s <span>worker
97968+
set</span>.</p></li>
9797497969
</ol>
9797597970
</li>
9797697971

0 commit comments

Comments
 (0)