Skip to content
Permalink
Browse files

Give workers a base URL and clean up shared workers

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 18, 2015
1 parent 634875f commit b620471ff823e8e6507b077cf0785a530762f5e3
Showing with 56 additions and 42 deletions.
  1. +56 −42 source
98 source
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>

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
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

<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>


<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>


<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>

<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>

<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>

<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>

<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>;
};

<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

<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>


<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>
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
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>

0 comments on commit b620471

Please sign in to comment.
You can’t perform that action at this time.