Skip to content

Commit 84f4750

Browse files
committed
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 (#2260) and also helps with allowing service workers to have nested workers (#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 4e2b006 9418bd.
1 parent 5aa74a0 commit 84f4750

File tree

1 file changed

+46
-61
lines changed

1 file changed

+46
-61
lines changed

source

Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
24092409
<li>The <dfn data-x-href="https://infra.spec.whatwg.org/#stack">stack</dfn> data structure and the associated definitions for
24102410
<dfn data-x="stack push" data-x-href="https://infra.spec.whatwg.org/#stack-push">push</dfn> and
24112411
<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>
2412+
<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
2413+
<dfn data-x="set append" data-x-href="https://infra.spec.whatwg.org/#set-append">append</dfn></li>
24132414
<li><dfn data-x-href="https://infra.spec.whatwg.org/#html-namespace">HTML namespace</dfn></li>
24142415
<li><dfn data-x-href="https://infra.spec.whatwg.org/#mathml-namespace">MathML namespace</dfn></li>
24152416
<li><dfn data-x-href="https://infra.spec.whatwg.org/#svg-namespace">SVG namespace</dfn></li>
@@ -79134,8 +79135,8 @@ callback <dfn>FrameRequestCallback</dfn> = void (<span>DOMHighResTimeStamp</span
7913479135
</ol>
7913579136

7913679137
<p class="note">Whenever a <code>Document</code> object is <span data-x="discard a
79137-
Document">discarded</span>, it is also removed from the list of <span>the worker's
79138-
<code>Document</code>s</span> of each worker whose list contains that <code>Document</code>.</p>
79138+
Document">discarded</span>, it is also removed from the list of <span>the worker's owners</span>
79139+
of each worker whose list contains that <code>Document</code>.</p>
7913979140

7914079141
<p>When <dfn data-export="">a <em>browsing context</em> is discarded</dfn>, the strong reference
7914179142
from the user agent itself to the <span>browsing context</span> must be severed, and all the
@@ -97113,53 +97114,43 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9711397114
contexts</span> through <span data-x="channel messaging">message channels</span> and their
9711497115
<code>MessagePort</code> objects.</p>
9711597116

97116-
<p>Each <code>WorkerGlobalScope</code> <var>worker global scope</var> has a list of
97117+
<p>Each <code>WorkerGlobalScope</code> object <var>worker global scope</var> has a list of
9711797118
<dfn data-export="">the worker's ports</dfn>, which consists of all the <code>MessagePort</code>
9711897119
objects that are entangled with another port and that have one (but only one) port owned by
97119-
<var>worker global scope</var>. This list includes <!--all the <code>MessagePort</code> objects
97120-
that are in events pending in the <code>WorkerGlobalScope</code> object's <span>event loop</span>,
97121-
as well as (commented out because in practice it makes no difference either way as far as I can
97122-
tell, and it would be hard to strictly implement since these ports might not yet be across the
97123-
thread boundary)--> the implicit <code>MessagePort</code> in the case of <span
97124-
data-x="DedicatedWorkerGlobalScope">dedicated workers</span>.</p>
97125-
97126-
<p>Each <code>WorkerGlobalScope</code> also has a list of <dfn data-export="">the worker's
97127-
workers</dfn>. Initially this list is empty; it is populated when the worker creates or obtains
97128-
further workers.</p>
97129-
97130-
<p>Finally, each <code>WorkerGlobalScope</code> also has a list of <dfn data-export="">the
97131-
worker's <code>Document</code>s</dfn>. Initially this list is empty; it is populated when the
97132-
worker is created.</p>
97133-
97134-
<p>Whenever a <code>Document</code> <var>d</var> is <dfn data-x="add a document to the
97135-
worker's Documents">added to the worker's <code>Document</code>s</dfn>, the user agent must, for
97136-
each worker <var>q</var> in the list of <span>the worker's workers</span> whose list of
97137-
<span>the worker's <code>Document</code>s</span> does not contain <var>d</var>, <span
97138-
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
97139-
<code>Document</code>s</span></span>.</p> <!-- suggestions welcome on making this sentence into
97140-
understandable English -->
97120+
<var>worker global scope</var>. This list includes the implicit <code>MessagePort</code> in the
97121+
case of <span data-x="DedicatedWorkerGlobalScope">dedicated workers</span>.</p>
97122+
97123+
<p>Each <code>WorkerGlobalScope</code> object also has a <span>set</span> of <dfn
97124+
id="the-worker's-workers" data-export="" data-for="WorkerGlobalScope" data-lt="workers">the
97125+
worker's workers</dfn>. Initially this set is empty; it is populated when the worker creates or
97126+
obtains further workers.</p>
97127+
97128+
<p id="the-worker's-documents">Finally, each <code>WorkerGlobalScope</code> object also has a
97129+
<span>set</span> of <dfn data-export="" data-for="WorkerGlobalScope" data-lt="owners">the worker's
97130+
owners</dfn>. Initially this set is empty; it is populated when the worker is created or
97131+
obtained.</p>
97132+
97133+
<p class="note">It is a list to accomodate <code>SharedWorkerGlobalScope</code> objects.</p>
9714197134

9714297135
<p>Whenever a <code>Document</code> object is <span data-x="discard a Document">discarded</span>,
97143-
it must be removed from the list of <span>the worker's <code>Document</code>s</span> of each
97144-
worker whose list contains that <code>Document</code>.</p>
97145-
97146-
<p>Given an <span>environment settings object</span> <var>o</var> when creating or obtaining a
97147-
worker, the <dfn>list of relevant <code>Document</code> objects to add</dfn> depends on the type
97148-
of <span data-x="concept-settings-object-global">global object</span> specified by <var>o</var>.
97149-
If <var>o</var> specifies a <span data-x="concept-settings-object-global">global object</span>
97150-
that is a <code>WorkerGlobalScope</code> object (i.e. if we are creating a nested worker), then
97151-
the relevant <code>Document</code>s are the <span>the worker's <code>Document</code>s</span> of
97152-
the <span data-x="concept-settings-object-global">global object</span> specified by <var>o</var>.
97153-
Otherwise, <var>o</var> specifies a <span data-x="concept-settings-object-global">global
97154-
object</span> that is a <code>Window</code> object, and the relevant <code>Document</code> is just
97155-
the <span>responsible document</span> specified by <var>o</var>.</p>
97136+
it must be removed from the list of <span>the worker's owners</span> of each worker whose list
97137+
contains that <code>Document</code>.</p>
97138+
97139+
<p id="list-of-relevant-document-objects-to-add">Given an <span>environment settings object</span>
97140+
<var>o</var> when creating or obtaining a worker, the <dfn>relevant owner to add</dfn> depends on
97141+
the type of <span data-x="concept-settings-object-global">global object</span> specified by
97142+
<var>o</var>. If <var>o</var> specifies a <span data-x="concept-settings-object-global">global
97143+
object</span> that is a <code>WorkerGlobalScope</code> object (i.e., if we are creating a nested
97144+
worker), then the relevant owner is that global object. Otherwise, <var>o</var> specifies a <span
97145+
data-x="concept-settings-object-global">global object</span> that is a <code>Window</code> object,
97146+
and the relevant owner is the <span>responsible document</span> specified by <var>o</var>.</p>
9715697147

9715797148
<hr>
9715897149

97159-
<p>A worker is said to be a <dfn>permissible worker</dfn> if its list of <span>the worker's
97160-
<code>Document</code>s</span> is not empty, or if its list has been empty for no more than a short
97150+
<p>A worker is said to be a <dfn>permissible worker</dfn> if its set of <span>the worker's
97151+
owners</span> is not empty, or if its list has been empty for no more than a short
9716197152
user-agent-defined timeout value, its <code>WorkerGlobalScope</code> is actually a
97162-
<code>SharedWorkerGlobalScope</code> object (i.e. the worker is a shared worker), and the user
97153+
<code>SharedWorkerGlobalScope</code> object (i.e., the worker is a shared worker), and the user
9716397154
agent has a <span>browsing context</span> whose <code>Document</code> is not <span>completely
9716497155
loaded</span>.</p>
9716597156

@@ -97168,8 +97159,9 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9716897159
can be used by user agents as a way to avoid the cost of restarting a shared worker used by a site
9716997160
when the user is navigating from page to page within that site.</p>
9717097161

97171-
<p>A worker is said to be an <dfn>active needed worker</dfn> if any of the <code>Document</code>
97172-
objects in <span>the worker's <code>Document</code>s</span> are <span>fully active</span>.</p>
97162+
<p>A worker is said to be an <dfn>active needed worker</dfn> if any of <span>the worker's
97163+
owners</span> are either <code>Document</code> objects that are <span>fully active</span> or
97164+
<span data-x="active needed worker">active needed workers</span>.</p>
9717397165

9717497166
<p>A worker is said to be a <dfn>protected worker</dfn> if it is an <span>active needed
9717597167
worker</span> and either it has outstanding timers, database transactions, or network connections,
@@ -97205,15 +97197,13 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9720597197
<li><p>Let <var>is shared</var> be true if <var>worker</var> is a <code>SharedWorker</code>
9720697198
object, and false otherwise.</p></li>
9720797199

97208-
<li><p>Let <var>docs</var> be the <span>list of relevant <code>Document</code> objects to
97209-
add</span> given <var>outside settings</var>.</p></li>
97200+
<li><p>Let <var>owner</var> be the <span>relevant owner to add</span> given <var>outside
97201+
settings</var>.</p></li>
9721097202

9721197203
<li><p>Let <var>parent worker global scope</var> be null.</p>
9721297204

97213-
<li><p>If <var>outside settings</var>'s <span data-x="concept-settings-object-global">global
97214-
object</span> is a <code>WorkerGlobalScope</code> object (i.e. we are creating a nested worker),
97215-
set <var>parent worker global scope</var> to <var>outside settings</var>'s <span
97216-
data-x="concept-settings-object-global">global object</span>.</p></li>
97205+
<li><p>If <var>owner</var> is a <code>WorkerGlobalScope</code> object (i.e., we are creating a
97206+
nested worker), then set <var>parent worker global scope</var> to <var>owner</var>.</p></li>
9721797207

9721897208
<li>
9721997209
<p>Call the JavaScript <span
@@ -97320,9 +97310,8 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9732097310

9732197311
<li><p><span>Entangle</span> <var>outside port</var> and <var>inside port</var>.</p></li>
9732297312

97323-
<li><p><span data-x="add a document to the worker's Documents">Add to <var>worker global
97324-
scope</var>'s list of <span>the worker's <code>Document</code>s</span></span> the
97325-
<code>Document</code> objects in <var>docs</var>.</p></li>
97313+
<li><p><span data-x="set append">Append</span> <var>owner</var> to <var>worker global
97314+
scope</var>'s set of <span>the worker's owners</span>.</p></li>
9732697315

9732797316
<li><p>If <var>parent worker global scope</var> is not null, add <var>worker global scope</var>
9732897317
to the list of <span>the worker's workers</span> of <var>parent worker global
@@ -97423,7 +97412,7 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9742397412

9742497413
<!-- this has no normative impact but makes it clearer that the worker is irrelevant now, and
9742597414
doesn't have to survive until its Documents all die off too --> <p>Empty the worker's list of
97426-
<span>the worker's <code>Document</code>s</span>.</p>
97415+
<span>the worker's owners</span>.</p>
9742797416

9742897417
</li>
9742997418

@@ -97797,9 +97786,6 @@ enum <dfn>WorkerType</dfn> { "classic", "module" };
9779797786

9779897787
<li><p>Associate the <var>outside port</var> with <var>worker</var>.</p></li>
9779997788

97800-
<li><p>Let <var>docs</var> be the <span>list of relevant <code>Document</code> objects to
97801-
add</span> given <var>outside settings</var>.</p></li>
97802-
9780397789
<li><p>Return <var>worker</var>, and run the following step <span>in parallel</span>.</p></li>
9780497790

9780597791
<li><p><span>Run a worker</span> given <var>worker</var>, <var>worker URL</var>, <var>outside
@@ -97948,10 +97934,9 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
9794897934
data-x="dom-MessageEvent-source">source</code> attribute initialized to <var>inside
9794997935
port</var>.</p></li>
9795097936

97951-
<li><p><span data-x="add a document to the worker's Documents">Add to <var>worker global
97952-
scope</var>'s list of <span>the worker's <code>Document</code>s</span></span> the
97953-
<span>list of relevant <code>Document</code> objects to add</span> given <var>outside
97954-
settings</var>.</p></li>
97937+
<li><p><span data-x="set append">Append</span> the <span>relevant owner to add</span> given
97938+
<var>outside settings</var> to <var>worker global scope</var>'s set of <span>the worker's
97939+
owners</span>.</p></li>
9795597940

9795697941
<li><p>If <var>outside settings</var>'s <span data-x="concept-settings-object-global">global
9795797942
object</span> is a <code>WorkerGlobalScope</code> object, add <var>worker global scope</var>

0 commit comments

Comments
 (0)