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 (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.
  • Loading branch information
annevk authored and inikulin committed May 9, 2017
1 parent 8292496 commit 9f16279
Showing 1 changed file with 67 additions and 72 deletions.
139 changes: 67 additions & 72 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2401,15 +2401,18 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<dfn data-x="map get" data-x-href="https://infra.spec.whatwg.org/#map-get">getting the value of an entry</dfn>, and
<dfn data-x="map set" data-x-href="https://infra.spec.whatwg.org/#map-set">setting the value of an entry</dfn></li>
<li>The <dfn data-x-href="https://infra.spec.whatwg.org/#list">list</dfn> data structure and the associated definitions for
<dfn data-x="list append" data-x-href="https://infra.spec.whatwg.org/#list-append">append</dfn>, and
<dfn data-x="list append" data-x-href="https://infra.spec.whatwg.org/#list-append">append</dfn>,
<dfn data-x="list remove" data-x-href="https://infra.spec.whatwg.org/#list-remove">remove</dfn>,
<dfn data-x="list empty" data-x-href="https://infra.spec.whatwg.org/#list-empty">empty</dfn>,
<dfn data-x="list contains" data-x-href="https://infra.spec.whatwg.org/#list-contain">contains</dfn>,
<dfn data-x="list size" data-x-href="https://infra.spec.whatwg.org/#list-size">size</dfn>,
<dfn data-x="list is empty" data-x-href="https://infra.spec.whatwg.org/#list-is-empty">is empty</dfn>, and
<dfn data-x="list iterate" data-x-href="https://infra.spec.whatwg.org/#list-iterate">iterate</dfn></li>
<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 @@ -79148,8 +79151,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 <span>owner set</span> of each worker
whose set 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 @@ -96884,6 +96887,19 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {
attribute <span>EventHandler</span> <span data-x="handler-WorkerGlobalScope-onunhandledrejection">onunhandledrejection</span>;
};</pre>

<p id="the-worker's-documents">A <code>WorkerGlobalScope</code> object has an associated <dfn
id="concept-WorkerGlobalScope-owner-set" data-export="" data-for="WorkerGlobalScope">owner
set</dfn> (a <span>set</span> of <code>Document</code> and <code>WorkerGlobalScope</code>
objects). It is initially empty and populated when the worker is created or obtained.</p>

<p class="note">It is a <span>set</span>, instead of a single owner, to accomodate
<code>SharedWorkerGlobalScope</code> objects.</p>

<p>A <code>WorkerGlobalScope</code> object has an associated <dfn id="the-worker's-workers"
data-export="" data-for="WorkerGlobalScope">worker set</dfn> (a <span>set</span> of
<code>WorkerGlobalScope</code> objects). It is initially empty and populated when the worker
creates or obtains further workers.</p>

<p>A <code>WorkerGlobalScope</code> object has an associated <dfn data-export=""
data-dfn-for="WorkerGlobalScope" data-x="concept-WorkerGlobalScope-type">type</dfn> ("<code
data-x="">classic</code>" or "<code data-x="">module</code>"). It is set during creation.
Expand Down Expand Up @@ -97127,63 +97143,48 @@ 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>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 <span data-x="list remove">removed</span> from the <span>owner set</span> of each
<code>WorkerGlobalScope</code> object whose set <span data-x="list contains">contains</span> that
<code>Document</code> object.</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
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
agent has a <span>browsing context</span> whose <code>Document</code> is not <span>completely
loaded</span>.</p>
<p>A worker is said to be a <dfn>permissible worker</dfn> if its <code>WorkerGlobalScope</code>'s
<span>owner set</span> is not <span data-x="list is empty">empty</span> or:</p>

<ul class=brief>
<li>its <span>owner set</span> has been <span data-x="list is empty">empty</span> for no more
than a short user-agent-defined timeout value,</li>
<li>its <code>WorkerGlobalScope</code> object is a <code>SharedWorkerGlobalScope</code> object
(i.e., the worker is a shared worker), and</li>
<li>the user agent has a <span>browsing context</span> whose <code>Document</code> object is not
<span>completely loaded</span>.</li>
</ul>

<p class="note">The second part of this definition allows a shared worker to survive for a short
time while a page is loading, in case that page is going to contact the shared worker again. This
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 its <span data-x="owner
set">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 @@ -97219,15 +97220,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 @@ -97334,13 +97333,12 @@ 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 <span>owner set</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
scope</var>.</p></li>
<li><p>If <var>parent worker global scope</var> is not null, then <span data-x="set
append">append</span> <var>worker global scope</var> to <var>parent worker global scope</var>'s
<span>worker set</span>.</p></li>

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

<!-- 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>
doesn't have to survive until its Documents all die off too --> <p><span data-x="list
empty">Empty</span> <var>worker global scope</var>'s <span>owner set</span>.</p>

</li>

Expand Down Expand Up @@ -97811,9 +97809,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 @@ -97962,15 +97957,15 @@ 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 <span>owner
set</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>
to the list of <span>the worker's workers</span> of <var>outside settings</var>'s <span
data-x="concept-settings-object-global">global object</span>.</p></li>
object</span> is a <code>WorkerGlobalScope</code> object, then <span data-x="set
append">append</span> <var>worker global scope</var> to <var>outside settings</var>'s <span
data-x="concept-settings-object-global">global object</span>'s <span>worker
set</span>.</p></li>
</ol>
</li>

Expand Down

0 comments on commit 9f16279

Please sign in to comment.