Skip to content

Commit

Permalink
Give workers a base URL and clean up shared workers
Browse files Browse the repository at this point in the history
This fixes the following from #164:

* It gives workers a base URL that matches the response's url. Per https://www.w3.org/Bugs/Public/show_bug.cgi?id=28835 this matches Firefox and would also be more consistent with how the platform determines base URLs in general. (The fix is slightly ugly as it puts the URL on the global object so it can be overridden later. In HTML Standard theory the global object is optional and non-JavaScript languages need not provide it, but I think we should move away from that: #167.)

* It keys shared worker on constructor URL rather than "location". The latter takes redirects into account and if implemented results in racy behavior. Fortunately, neither Chrome nor Firefox implemented this and instead already use this new "constructor url" concept.

* It references "in parallel" where used.

* It defaults name to the empty string through IDL.
  • Loading branch information
annevk committed Sep 21, 2015
1 parent 634875f commit b620471
Showing 1 changed file with 56 additions and 42 deletions.
98 changes: 56 additions & 42 deletions source
Expand Up @@ -95172,13 +95172,17 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {
attribute <span>EventHandler</span> <span data-x="handler-WorkerGlobalScope-ononline">ononline</span>;
};</pre>

<p>A <code>WorkerGlobalScope</code> object has an associated <dfn data-dfn-for="WorkerGlobalScope"
data-x="concept-WorkerGlobalScope-url">url</dfn> (null or a <span>URL</span>). It is initially
null.

<p>The <dfn><code data-x="dom-WorkerGlobalScope-self">self</code></dfn> attribute must return the
<code>WorkerGlobalScope</code> object itself.</p>

<p>The <dfn><code data-x="dom-WorkerGlobalScope-location">location</code></dfn> attribute must
return the <code>WorkerLocation</code> object created for the <code>WorkerGlobalScope</code>
object when the worker was created. It represents the <span>absolute URL</span> of the script that
was used to initialise the worker, after any redirects.</p>
object when the worker was created. It represents the <code>WorkerGlobalScope</code> object's
<span data-x="concept-WorkerGlobalScope-url">url</span>.</p>

<hr>

Expand Down Expand Up @@ -95278,14 +95282,20 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {
attribute <span>EventHandler</span> <span data-x="handler-SharedWorkerGlobalScope-onconnect">onconnect</span>;
};</pre>

<p>A <code>SharedWorkerGlobalScope</code> object has an associated <dfn
data-dfn-for="SharedWorkerGlobalScope"
data-x="concept-SharedWorkerGlobalScope-constructor-url">constructor url</dfn> and <dfn
data-dfn-for="SharedWorkerGlobalScope"
data-x="concept-SharedWorkerGlobalScope-name">name</dfn>.

<p>Shared workers receive message ports through <code
data-x="event-WorkerGlobalScope-connect">connect</code> events on their <code>SharedWorkerGlobalScope</code> object for each
connection.</p>

<p>The <dfn><code data-x="dom-SharedWorkerGlobalScope-name">name</code></dfn> attribute must return
the value it was assigned when the <code>SharedWorkerGlobalScope</code> object was created by the
"<span>run a worker</span>" algorithm. Its value represents the name that can be used to obtain a
reference to the worker using the <code>SharedWorker</code> constructor.</p>
<p>The <dfn><code data-x="dom-SharedWorkerGlobalScope-name">name</code></dfn> attribute must
return the <code>SharedWorkerGlobalScope</code> object's <span
data-x="concept-SharedWorkerGlobalScope-name">name</span>. Its value represents the name that can
be used to obtain a reference to the worker using the <code>SharedWorker</code> constructor.</p>

<p>The following are the <span>event handlers</span> (and their corresponding <span data-x="event
handler event type">event handler event types</span>) that must be supported, as <span>event
Expand Down Expand Up @@ -95470,6 +95480,10 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {
event</span> named <code data-x="event-error">error</code> at that object. Abort these
steps.</p></li>

<li><p>Set <var>worker global scope</var>'s <span
data-x="concept-WorkerGlobalScope-url">url</span> to <var>response</var>'s <span
data-x="concept-response-url">url</span>.</p></li>

<li><p>In the newly created execution environment, create a <span>JavaScript global
environment</span> whose <i>global object</i> is <var>worker global scope</var>. If <var>worker
global scope</var> is a <code>DedicatedWorkerGlobalScope</code> object, then this is a
Expand Down Expand Up @@ -95568,8 +95582,9 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {

<hr>

<p>When a user agent is to <dfn>kill a worker</dfn> it must run the following steps in parallel
with the worker's main loop (the "<span>run a worker</span>" processing model defined above):</p>
<p>When a user agent is to <dfn>kill a worker</dfn> it must run the following steps <span>in
parallel</span> with the worker's main loop (the "<span>run a worker</span>" processing model
defined above):</p>

<ol>

Expand All @@ -95593,9 +95608,9 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {

<hr>

<p>When a user agent is to <dfn>terminate a worker</dfn> it must run the following steps in
parallel with the worker's main loop (the "<span>run a worker</span>" processing model defined
above):</p>
<p>When a user agent is to <dfn>terminate a worker</dfn> it must run the following steps <span>in
parallel</span> with the worker's main loop (the "<span>run a worker</span>" processing model
defined above):</p>

<ol>

Expand Down Expand Up @@ -95685,9 +95700,8 @@ interface <dfn>AbstractWorker</dfn> {

<h5>Script settings for workers</h5>

<p>When the user agent is required to <dfn>set up a worker environment settings object</dfn>, given a
<var>worker global scope</var> and a <span>URL</span> <var>script
address</var> it must run the following steps:</p>
<p>When the user agent is required to <dfn>set up a worker environment settings object</dfn>,
given a <var>worker global scope</var>, it must run the following steps:</p>

<ol>

Expand Down Expand Up @@ -95761,7 +95775,8 @@ interface <dfn>AbstractWorker</dfn> {
<dt>The <span>API base URL</span></dt>
<dd>

<p>Return <var>script address</var>.</p>
<p>Return <var>worker global scope</var>'s <span
data-x="concept-WorkerGlobalScope-url">url</span>.</p>

</dd>

Expand All @@ -95775,7 +95790,8 @@ interface <dfn>AbstractWorker</dfn> {
<dt>The <span>creation URL</span></dt>
<dd>

<p>Return <var>script address</var>.</p>
<p>Return <var>worker global scope</var>'s <span
data-x="concept-WorkerGlobalScope-url">url</span>.</p>

</dd>

Expand Down Expand Up @@ -95881,8 +95897,8 @@ interface <dfn>Worker</dfn> : <span>EventTarget</span> {
<li><p>Create a new <code>DedicatedWorkerGlobalScope</code> object. Let <var>worker global
scope</var> be this new object.</p></li>

<li><p><span>Set up a worker environment settings object</span> with <var>worker global scope</var>
and <var>worker URL</var>, and let <var>settings object</var> be the result.</p></li>
<li><p><span>Set up a worker environment settings object</span> with <var>worker global
scope</var>, and let <var>settings object</var> be the result.</p></li>

<li><p>Create a new <code>Worker</code> object, associated with <var>worker global scope</var>.
Let <var>worker</var> be this new object.</p></li>
Expand Down Expand Up @@ -95932,7 +95948,7 @@ interface <dfn>Worker</dfn> : <span>EventTarget</span> {

<h5>Shared workers and the <code>SharedWorker</code> interface</h5>

<pre class="idl">[<span data-x="dom-SharedWorker">Constructor</span>(DOMString scriptURL, optional DOMString name), Exposed=(Window,Worker)]
<pre class="idl">[<span data-x="dom-SharedWorker">Constructor</span>(DOMString scriptURL, optional DOMString name = ""), Exposed=(Window,Worker)]
interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
readonly attribute <span>MessagePort</span> <span data-x="dom-SharedWorker-port">port</span>;
};
Expand All @@ -95958,9 +95974,6 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {

<li><p>Let <var>scriptURL</var> be the resulting <span>absolute URL</span> and <var>parsed scriptURL</var> be the resulting <span>parsed URL</span>.</p></li>

<li><p>Let <var>name</var> be the value of the second argument, or the empty string if
the second argument was omitted.</p></li>

<li>

<p>If the <span data-x="concept-url-scheme">scheme</span> component of <var>parsed
Expand Down Expand Up @@ -96005,20 +96018,20 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {

<p>If <var>name</var> is not the empty string and there exists a
<code>SharedWorkerGlobalScope</code> object whose <span
data-x="dom-WorkerGlobalScope-closing">closing</span> flag is false, whose <code
data-x="dom-SharedWorkerGlobalScope-name">name</code> attribute is exactly equal to
<var>name</var>, and that is the <span>global object</span> specified by an <span>environment
settings object</span> that specifies as its <span>origin</span> the <span>same origin</span>
as the <span>origin</span> of <var>scriptURL</var>, then let <var>worker global scope</var> be
data-x="dom-WorkerGlobalScope-closing">closing</span> flag is false, whose <span
data-x="concept-SharedWorkerGlobalScope-name">name</span> is exactly equal to <var>name</var>,
and that is the <span>global object</span> specified by an <span>environment settings
object</span> that specifies as its <span>origin</span> the <span>same origin</span> as the
<span>origin</span> of <var>scriptURL</var>, then let <var>worker global scope</var> be
that <code>SharedWorkerGlobalScope</code> object.</p>

<p>Otherwise, if <var>name</var> is the empty string and there exists a
<code>SharedWorkerGlobalScope</code> object whose <span
data-x="dom-WorkerGlobalScope-closing">closing</span> flag is false, whose <code
data-x="dom-SharedWorkerGlobalScope-name">name</code> attribute is the empty string, and whose
<code data-x="dom-WorkerGlobalScope-location">location</code> attribute represents an
<span>absolute URL</span> that is exactly equal to <var>scriptURL</var>, then let <var>worker
global scope</var> be that <code>SharedWorkerGlobalScope</code> object.</p>
data-x="dom-WorkerGlobalScope-closing">closing</span> flag is false, whose <span
data-x="concept-SharedWorkerGlobalScope-name">name</span> is the empty string, and whose <span
data-x="concept-SharedWorkerGlobalScope-constructor-url">constructor url</span> is equal to
<var>scriptURL</var>, then let <var>worker global scope</var> be that
<code>SharedWorkerGlobalScope</code> object.</p>

</li>

Expand All @@ -96042,10 +96055,10 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {

<ol>

<li><p>If <var>worker global scope</var>'s <code
data-x="dom-WorkerGlobalScope-location">location</code> attribute represents an <span>absolute
URL</span> that is not exactly equal to <var>scriptURL</var>, then throw a
<code>URLMismatchError</code> exception and abort all these steps.</p></li>
<li><p>If <var>worker global scope</var>'s <span
data-x="concept-SharedWorkerGlobalScope-constructor-url">constructor url</span> is not equal
to <var>scriptURL</var>, then throw a <code>URLMismatchError</code> exception and abort all
these steps.</p></li>

<li><p>Associate <var>worker</var> with <var>worker global
scope</var>.</p></li>
Expand Down Expand Up @@ -96102,13 +96115,14 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
global scope</var> be this new object.</p></li>

<li><p><span>Set up a worker environment settings object</span> with <var>worker global
scope</var> and <var>scriptURL</var>, and let <var>settings object</var> be
the result.</p></li>
scope</var>, and let <var>settings object</var> be the result.</p></li>

<li><p>Associate <var>worker</var> with <var>worker global scope</var>.</p></li>

<li><p>Set the <code data-x="dom-SharedWorkerGlobalScope-name">name</code> attribute of
<var>worker global scope</var> to <var>name</var>.</p></li>
<li><p>Set <var>worker global scope</var>'s <span
data-x="concept-SharedWorkerGlobalScope-name">name</span> to <var>name</var> and <span
data-x="concept-SharedWorkerGlobalScope-constructor-url">constructor url</span> to
<var>scriptURL</var>.</p></li>

<li><p><span>Create a new <code>MessagePort</code> object</span> whose <span
data-x="concept-port-owner">owner</span> is <var>settings object</var>. Let <var>inside
Expand Down Expand Up @@ -96313,8 +96327,8 @@ interface <dfn>WorkerNavigator</dfn> {};
interface <dfn>WorkerLocation</dfn> { };
<span>WorkerLocation</span> implements <span>URLUtilsReadOnly</span>;</pre>

<p>A <code>WorkerLocation</code> object represents an <span>absolute URL</span> set at its
creation.</p>
<p>A <code>WorkerLocation</code> object represents the <code>WorkerGlobalScope</code> object's
<span data-x="concept-WorkerGlobalScope-url">url</span>.

<p>The <code>WorkerLocation</code> interface supports the <code>URLUtilsReadOnly</code>
interface. <ref spec=URL></p>
Expand Down

0 comments on commit b620471

Please sign in to comment.