Skip to content

Commit

Permalink
Editorial: restructure ownership of workers to parent-owners
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
annevk committed Apr 11, 2017
1 parent 5aa74a0 commit 84f4750
Showing 1 changed file with 46 additions and 61 deletions.
107 changes: 46 additions & 61 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://infra.spec.whatwg.org/#stack">stack</dfn> data structure and the associated definitions for
<dfn data-x="stack push" data-x-href="https://infra.spec.whatwg.org/#stack-push">push</dfn> and
<dfn data-x="stack pop" data-x-href="https://infra.spec.whatwg.org/#stack-pop">pop</dfn></li>
<li>The <dfn data-x="set" data-x-href="https://infra.spec.whatwg.org/#ordered-set">ordered set</dfn> data structure</li>
<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
<dfn data-x="set append" data-x-href="https://infra.spec.whatwg.org/#set-append">append</dfn></li>
<li><dfn data-x-href="https://infra.spec.whatwg.org/#html-namespace">HTML namespace</dfn></li>
<li><dfn data-x-href="https://infra.spec.whatwg.org/#mathml-namespace">MathML namespace</dfn></li>
<li><dfn data-x-href="https://infra.spec.whatwg.org/#svg-namespace">SVG namespace</dfn></li>
Expand Down Expand Up @@ -79134,8 +79135,8 @@ callback <dfn>FrameRequestCallback</dfn> = void (<span>DOMHighResTimeStamp</span
</ol>

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

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

<p>Each <code>WorkerGlobalScope</code> <var>worker global scope</var> has a list of
<p>Each <code>WorkerGlobalScope</code> object <var>worker global scope</var> has a list of
<dfn data-export="">the worker's ports</dfn>, which consists of all the <code>MessagePort</code>
objects that are entangled with another port and that have one (but only one) port owned by
<var>worker global scope</var>. This list includes <!--all the <code>MessagePort</code> objects
that are in events pending in the <code>WorkerGlobalScope</code> object's <span>event loop</span>,
as well as (commented out because in practice it makes no difference either way as far as I can
tell, and it would be hard to strictly implement since these ports might not yet be across the
thread boundary)--> the implicit <code>MessagePort</code> in the case of <span
data-x="DedicatedWorkerGlobalScope">dedicated workers</span>.</p>

<p>Each <code>WorkerGlobalScope</code> also has a list of <dfn data-export="">the worker's
workers</dfn>. Initially this list is empty; it is populated when the worker creates or obtains
further workers.</p>

<p>Finally, each <code>WorkerGlobalScope</code> also has a list of <dfn data-export="">the
worker's <code>Document</code>s</dfn>. Initially this list is empty; it is populated when the
worker is created.</p>

<p>Whenever a <code>Document</code> <var>d</var> is <dfn data-x="add a document to the
worker's Documents">added to the worker's <code>Document</code>s</dfn>, the user agent must, for
each worker <var>q</var> in the list of <span>the worker's workers</span> whose list of
<span>the worker's <code>Document</code>s</span> does not contain <var>d</var>, <span
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
<code>Document</code>s</span></span>.</p> <!-- suggestions welcome on making this sentence into
understandable English -->
<var>worker global scope</var>. This list includes the implicit <code>MessagePort</code> in the
case of <span data-x="DedicatedWorkerGlobalScope">dedicated workers</span>.</p>

<p>Each <code>WorkerGlobalScope</code> object also has a <span>set</span> of <dfn
id="the-worker's-workers" data-export="" data-for="WorkerGlobalScope" data-lt="workers">the
worker's workers</dfn>. Initially this set is empty; it is populated when the worker creates or
obtains further workers.</p>

<p id="the-worker's-documents">Finally, each <code>WorkerGlobalScope</code> object also has a
<span>set</span> of <dfn data-export="" data-for="WorkerGlobalScope" data-lt="owners">the worker's
owners</dfn>. Initially this set is empty; it is populated when the worker is created or
obtained.</p>

<p class="note">It is a list to accomodate <code>SharedWorkerGlobalScope</code> objects.</p>

<p>Whenever a <code>Document</code> object is <span data-x="discard a Document">discarded</span>,
it must be removed from the list of <span>the worker's <code>Document</code>s</span> of each
worker whose list contains that <code>Document</code>.</p>

<p>Given an <span>environment settings object</span> <var>o</var> when creating or obtaining a
worker, the <dfn>list of relevant <code>Document</code> objects to add</dfn> depends on the type
of <span data-x="concept-settings-object-global">global object</span> specified by <var>o</var>.
If <var>o</var> specifies a <span data-x="concept-settings-object-global">global object</span>
that is a <code>WorkerGlobalScope</code> object (i.e. if we are creating a nested worker), then
the relevant <code>Document</code>s are the <span>the worker's <code>Document</code>s</span> of
the <span data-x="concept-settings-object-global">global object</span> specified by <var>o</var>.
Otherwise, <var>o</var> specifies a <span data-x="concept-settings-object-global">global
object</span> that is a <code>Window</code> object, and the relevant <code>Document</code> is just
the <span>responsible document</span> specified by <var>o</var>.</p>
it must be removed from the list of <span>the worker's owners</span> of each worker whose list
contains that <code>Document</code>.</p>

<p id="list-of-relevant-document-objects-to-add">Given an <span>environment settings object</span>
<var>o</var> when creating or obtaining a worker, the <dfn>relevant owner to add</dfn> depends on
the type of <span data-x="concept-settings-object-global">global object</span> specified by
<var>o</var>. If <var>o</var> specifies a <span data-x="concept-settings-object-global">global
object</span> that is a <code>WorkerGlobalScope</code> object (i.e., if we are creating a nested
worker), then the relevant owner is that global object. Otherwise, <var>o</var> specifies a <span
data-x="concept-settings-object-global">global object</span> that is a <code>Window</code> object,
and the relevant owner is the <span>responsible document</span> specified by <var>o</var>.</p>

<hr>

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

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

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

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

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

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

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

<li>
<p>Call the JavaScript <span
Expand Down Expand Up @@ -97320,9 +97310,8 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {

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

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

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

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

</li>

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

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

<li><p>Let <var>docs</var> be the <span>list of relevant <code>Document</code> objects to
add</span> given <var>outside settings</var>.</p></li>

<li><p>Return <var>worker</var>, and run the following step <span>in parallel</span>.</p></li>

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

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

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

0 comments on commit 84f4750

Please sign in to comment.