/[suikacvs]/markup/html/html5/spec-ja/.workers-spec.en.html
Suika

Contents of /markup/html/html5/spec-ja/.workers-spec.en.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.183 - (hide annotations) (download) (as text)
Fri Jan 8 06:31:47 2010 UTC (16 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.182: +1 -3 lines
File MIME type: text/html
make

1 wakaba 1.177 <!DOCTYPE html><html lang=en-US-x-hixie><meta charset=ascii><title>Web Workers</title><link href=/style/specification rel=stylesheet><link href=/images/icon rel=icon><body class=cfc>
2 wakaba 1.171
3     <header class=head><p><a class=logo href=http://www.whatwg.org/ rel=home><img alt=WHATWG src=/images/logo></a></p>
4     <hgroup><h1>Web Workers</h1>
5 wakaba 1.183 <h2 class="no-num no-toc">Draft Recommendation &mdash; 8 January 2010</h2>
6 wakaba 1.171 </hgroup><p>You can take part in this work. <a href=http://www.whatwg.org/mailing-list>Join the working group's discussion list.</a></p>
7 wakaba 1.82 <p><strong>Web designers!</strong> We have a <a href=http://blog.whatwg.org/faq/>FAQ</a>, a <a href=http://forums.whatwg.org/>forum</a>, and a <a href=http://www.whatwg.org/mailing-list#help>help mailing list</a> for you!</p>
8 wakaba 1.130 <dl><dt>This version:</dt>
9 wakaba 1.82 <dd><a href=http://www.whatwg.org/specs/web-workers/current-work/>http://whatwg.org/ww</a></dd>
10     <dt>Version history:</dt>
11     <dd>Twitter messages (non-editorial changes only): <a href=http://twitter.com/WHATWG>http://twitter.com/WHATWG</a></dd>
12     <dd>Commit-Watchers mailing list: <a href=http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org>http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org</a></dd>
13     <dd>Interactive Web interface: <a href=http://html5.org/tools/web-workers-tracker>http://html5.org/tools/web-workers-tracker</a></dd>
14     <dd>Subversion interface: <a href=http://svn.whatwg.org/webworkers/>http://svn.whatwg.org/webworkers/</a></dd>
15     <dt>Issues:</dt>
16     <dd>To send feedback: <a href=http://www.whatwg.org/mailing-list>[email protected]</a></dd>
17     <dd>To view and vote on feedback: <a href=http://www.whatwg.org/issues/>http://www.whatwg.org/issues/</a></dd>
18     <dt>Editor:</dt>
19     <dd>Ian Hickson, Google, [email protected]</dd>
20 wakaba 1.130 </dl><p class=copyright>&copy; Copyright 2004-2008 Apple Computer, Inc.,
21 wakaba 1.82 Mozilla Foundation, and Opera Software ASA.</p>
22     <p class=copyright>You are granted a license to use, reproduce
23     and create derivative works of this document.</p>
24 wakaba 1.171 </header><hr><h2 class="no-num no-toc" id=abstract>Abstract</h2>
25 wakaba 1.82
26     <p>This specification defines an API that allows Web application
27     authors to spawn background workers running scripts in parallel to
28     their main page. This allows for thread-like operation with
29     message-passing as the coordination mechanism.</p>
30    
31    
32     <h2 class="no-num no-toc" id=status>Status of this document</h2>
33    
34     <p><strong>This is a work in progress!</strong> This document is
35     changing on a daily if not hourly basis in response to comments and
36     as a general part of its development process. Comments are very
37     welcome, please send them to <a href=mailto:[email protected]>[email protected]</a>. Thank
38     you.</p>
39    
40     <p>The current focus is in developing a first draft proposal.</p>
41    
42     <p>Implementors should be aware that this specification is not
43     stable. <strong>Implementors who are not taking part in the
44     discussions are likely to find the specification changing out from
45     under them in incompatible ways.</strong> Vendors interested in
46     implementing this specification before it eventually reaches the
47     call for implementations should join the <a href=/mailing-list>WHATWG mailing list</a> and take part in the
48     discussions.</p>
49    
50     <p>This specification is also being produced by the <a href=http://www.w3.org/2008/webapps/>W3C Web Apps WG</a>. The two
51     specifications are identical from the table of contents onwards.</p>
52    
53     <h2 class="no-num no-toc" id=contents>Table of contents</h2>
54    
55     <!--begin-toc-->
56     <ol class=toc>
57     <li><a href=#introduction><span class=secno>1 </span>Introduction</a>
58     <ol>
59     <li><a href=#scope><span class=secno>1.1 </span>Scope</a></li>
60     <li><a href=#tutorial><span class=secno>1.2 </span>Tutorial</a>
61     <ol>
62     <li><a href=#a-background-number-crunching-worker><span class=secno>1.2.1 </span>A background number-crunching worker</a></li>
63     <li><a href=#a-worker-for-updating-a-client-side-database><span class=secno>1.2.2 </span>A worker for updating a client-side database</a></li>
64     <li><a href=#worker-used-for-background-i/o><span class=secno>1.2.3 </span>Worker used for background I/O</a></li>
65     <li><a href=#shared-workers><span class=secno>1.2.4 </span>Shared workers</a></li>
66     <li><a href=#delegation><span class=secno>1.2.5 </span>Delegation</a></li>
67     <li><a href=#providing-libraries><span class=secno>1.2.6 </span>Providing libraries</a></ol></ol></li>
68 wakaba 1.110 <li><a href=#conformance-requirements><span class=secno>2 </span>Conformance requirements</a>
69 wakaba 1.82 <ol>
70 wakaba 1.110 <li><a href=#dependencies><span class=secno>2.1 </span>Dependencies</a></ol></li>
71     <li><a href=#terminology><span class=secno>3 </span>Terminology</a></li>
72     <li><a href=#infrastructure><span class=secno>4 </span>Infrastructure</a>
73     <ol>
74     <li><a href=#the-global-scope><span class=secno>4.1 </span>The global scope</a>
75 wakaba 1.82 <ol>
76 wakaba 1.110 <li><a href=#the-workerglobalscope-abstract-interface><span class=secno>4.1.1 </span>The <code>WorkerGlobalScope</code> abstract interface</a></li>
77     <li><a href=#dedicated-workers-and-the-dedicatedworkerglobalscope-interface><span class=secno>4.1.2 </span>Dedicated workers and the <code>DedicatedWorkerGlobalScope</code> interface</a></li>
78     <li><a href=#shared-workers-and-the-sharedworkerglobalscope-inteface><span class=secno>4.1.3 </span>Shared workers and the <code>SharedWorkerGlobalScope</code> inteface</a></ol></li>
79 wakaba 1.141 <li><a href=#origins-of-workers><span class=secno>4.2 </span>Origins of workers</a></li>
80 wakaba 1.172 <li><a href=#the-event-loop><span class=secno>4.3 </span>The event loop</a></li>
81     <li><a href="#the-worker's-lifetime"><span class=secno>4.4 </span>The worker's lifetime</a></li>
82     <li><a href=#processing-model><span class=secno>4.5 </span>Processing model</a></li>
83     <li><a href=#runtime-script-errors><span class=secno>4.6 </span>Runtime script errors</a></li>
84     <li><a href=#creating-workers><span class=secno>4.7 </span>Creating workers</a>
85 wakaba 1.82 <ol>
86 wakaba 1.172 <li><a href=#the-abstractworker-abstract-interface><span class=secno>4.7.1 </span>The <code>AbstractWorker</code> abstract interface</a></li>
87     <li><a href=#dedicated-workers-and-the-worker-interface><span class=secno>4.7.2 </span>Dedicated workers and the <code>Worker</code> interface</a></li>
88     <li><a href=#shared-workers-and-the-sharedworker-interface><span class=secno>4.7.3 </span>Shared workers and the <code>SharedWorker</code> interface</a></ol></ol></li>
89 wakaba 1.110 <li><a href=#apis-available-to-workers><span class=secno>5 </span>APIs available to workers</a>
90 wakaba 1.82 <ol>
91 wakaba 1.110 <li><a href=#importing-scripts-and-libraries><span class=secno>5.1 </span>Importing scripts and libraries</a></li>
92 wakaba 1.179 <li><a href=#the-workernavigator-object><span class=secno>5.2 </span>The <code>WorkerNavigator</code> object</a></li>
93 wakaba 1.110 <li><a href=#apis-defined-in-other-specifications><span class=secno>5.3 </span>APIs defined in other specifications</a></li>
94     <li><a href=#interface-objects-and-constructors><span class=secno>5.4 </span>Interface objects and constructors</a></li>
95     <li><a href=#worker-locations><span class=secno>5.5 </span>Worker locations</a></ol></li>
96 wakaba 1.82 <li><a class=no-num href=#references>References</a></li>
97     <li><a class=no-num href=#acknowledgements>Acknowledgements</a></ol>
98     <!--end-toc-->
99 wakaba 1.130 <hr><h2 id=introduction><span class=secno>1 </span>Introduction</h2>
100 wakaba 1.82
101     <h3 id=scope><span class=secno>1.1 </span>Scope</h3>
102    
103 wakaba 1.106 <p><i>This section is non-normative.</i></p>
104 wakaba 1.82
105     <p>This specification defines an API for running scripts in the
106     background independently of any user interface scripts.</p>
107    
108     <p>This allows for long-running scripts that are not interrupted by
109     scripts that respond to clicks or other user interactions, and
110     allows long tasks to be executed without yielding to keep the page
111     responsive.</p>
112    
113     <p>Workers (as these background scripts are called herein) are
114     relatively heavy-weight, and are not intended to be used in large
115     numbers. For example, it would be inappropriate to launch one worker
116     for each pixel of a four megapixel image. The examples below show
117     some appropriate uses of workers.</p>
118    
119     <p>Generally, workers are expected to be long-lived, have a high
120     start-up performance cost, and a high per-instance memory cost.</p>
121    
122    
123     <h3 id=tutorial><span class=secno>1.2 </span>Tutorial</h3>
124    
125 wakaba 1.106 <p><i>This section is non-normative.</i></p>
126 wakaba 1.82
127     <p>There are a variety of uses that workers can be put to. The
128     following subsections show various examples of this use.</p>
129    
130     <h4 id=a-background-number-crunching-worker><span class=secno>1.2.1 </span>A background number-crunching worker</h4>
131    
132 wakaba 1.106 <p><i>This section is non-normative.</i></p>
133 wakaba 1.82
134     <p>The simplest use of workers is for performing a computationally
135     expensive task without interrupting the user interface.</p>
136    
137     <p>In this example, the main document spawns a worker to
138 wakaba 1.130 (na&iuml;vely) compute prime numbers, and progressively displays the
139 wakaba 1.82 most recently found prime number.</p>
140    
141     <p>The main page is as follows:</p>
142    
143     <pre>&lt;!DOCTYPE HTML&gt;
144     &lt;html&gt;
145     &lt;head&gt;
146     &lt;title&gt;Worker example: One-core computation&lt;/title&gt;
147     &lt;/head&gt;
148     &lt;body&gt;
149     &lt;p&gt;The highest prime number discovered so far is: &lt;output id="result"&gt;&lt;/output&gt;&lt;/p&gt;
150     &lt;script&gt;
151     var worker = new Worker('worker.js');
152     worker.onmessage = function (event) {
153     document.getElementById('result').textContent = event.data;
154     };
155     &lt;/script&gt;
156     &lt;/body&gt;
157     &lt;/html&gt;</pre>
158    
159     <p>The <code title=dom-Worker><a href=#dom-worker>Worker()</a></code> constructor call
160     creates a worker and returns a <code><a href=#worker>Worker</a></code> object
161     representing that worker, which is used to communicate with the
162 wakaba 1.162 worker. That object's <code title=handler-Worker-onmessage><a href=#handler-worker-onmessage>onmessage</a></code> event handler allows the code to receive messages from the worker.</p>
163 wakaba 1.82
164     <p>The worker itself is as follows:</p>
165    
166     <pre>var n = 1;
167     search: while (true) {
168     n += 1;
169     for (var i = 2; i &lt;= Math.sqrt(n); i += 1)
170     if (n % i == 0)
171     continue search;
172     // found a prime!
173     postMessage(n);
174     }</pre>
175    
176     <p>The bulk of this code is simply an unoptimized search for a prime
177     number. To send a message back to the page, the <code title=dom-DedicatedWorkerGlobalScope-postMessage><a href=#dom-dedicatedworkerglobalscope-postmessage>postMessage()</a></code>
178     method is used to post a message when a prime is found.</p>
179    
180     <p><a href=http://www.whatwg.org/demos/workers/primes/page.html>View this example online</a>.</p>
181    
182    
183    
184     <h4 id=a-worker-for-updating-a-client-side-database><span class=secno>1.2.2 </span>A worker for updating a client-side database</h4>
185    
186 wakaba 1.106 <p><i>This section is non-normative.</i></p>
187 wakaba 1.82
188     <p>In this example, the main document spawns a worker whose only
189     task is to listen for notifications from the server, and, when
190     appropriate, either add or remove data from the client-side
191     database.</p>
192    
193     <p>Since no communication occurs between the worker and the main
194     page, the main page can start the worker by just doing:</p>
195    
196     <pre>&lt;script&gt;
197     new Worker('worker.js');
198     &lt;/script&gt;</pre>
199    
200     <p>The worker itself is as follows:</p>
201    
202     <pre>var server = new WebSocket('ws://whatwg.org/database');
203     var database = openDatabase('demobase', '1.0', 'Demo Database', 10240);
204     server.onmessage = function (event) {
205     // data is in the format "command key value"
206     var data = event.data.split(' ');
207     switch (data[0]) {
208     case '+':
209     database.transaction(function(tx) {
210     tx.executeSql('INSERT INTO pairs (key, value) VALUES (?, ?)', data[1], data[2]);
211     });
212     case '-':
213     database.transaction(function(tx) {
214     tx.executeSql('DELETE FROM pairs WHERE key=? AND value=?', data[1], data[2]);
215     });
216     }
217     };</pre>
218    
219     <p>This connects to the server using the <code>WebSocket</code>
220     mechanism and opens the local database (which, we presume, has been
221     created earlier). The worker then just listens for messages from the
222     server and acts on them as appropriate, forever (or until the main
223     page is closed).</p>
224    
225     <p><a href=http://www.whatwg.org/demos/workers/database-updater/page.html>View
226     this example online</a>. (This example will not actually function,
227     since the server does not actually exist and the database is not
228     created by this sample code.)</p>
229    
230    
231    
232     <h4 id=worker-used-for-background-i/o><span class=secno>1.2.3 </span>Worker used for background I/O</h4>
233    
234 wakaba 1.106 <p><i>This section is non-normative.</i></p>
235 wakaba 1.82
236     <p>In this example, the main document uses two workers, one for
237     fetching stock updates for at regular intervals, and one for
238     fetching performing search queries that the user requests.</p>
239    
240     <p>The main page is as follows:</p>
241    
242     <pre>&lt;!DOCTYPE HTML&gt;
243     &lt;html&gt;
244     &lt;head&gt;
245     &lt;title&gt;Worker example: Stock ticker&lt;/title&gt;
246     &lt;script&gt;
247     // TICKER
248     var symbol = 'GOOG'; // default symbol to watch
249     var ticker = new Worker('ticker.js');
250    
251     // SEARCHER
252     var searcher = new Worker('searcher.js');
253     function search(query) {
254     searcher.postMessage(query);
255     }
256    
257     // SYMBOL SELECTION UI
258     function select(newSymbol) {
259     symbol = newSymbol;
260     ticker.postMessage(symbol);
261     }
262     &lt;/script&gt;
263     &lt;/head&gt;
264     &lt;body onload="search('')"&gt;
265     &lt;p&gt;&lt;output id="symbol"&gt;&lt;/output&gt; &lt;output id="value"&gt;&lt;/output&gt;&lt;/p&gt;
266     &lt;script&gt;
267     ticker.onmessage = function (event) {
268     var data = event.data.split(' ');
269     document.getElementById('symbol').textContent = data[0];
270     document.getElementById('value').textContent = data[1];
271     };
272     ticker.postMessage(symbol);
273     &lt;/script&gt;
274     &lt;p&gt;&lt;label&gt;Search: &lt;input type="text" autofocus oninput="search(this.value)"&gt;&lt;/label&gt;&lt;/p&gt;
275     &lt;ul id="results"&gt;&lt;/ul&gt;
276     &lt;script&gt;
277     searcher.onmessage = function (event) {
278     var data = event.data.split(' ');
279     var results = document.getElementById('results');
280     while (results.hasChildNodes()) // clear previous results
281     results.removeChild(results.firstChild);
282     for (var i = 0; i &lt; data.length; i += 1) {
283     // add a list item with a button for each result
284     var li = document.createElement('li');
285     var button = document.createElement('button');
286     button.value = data[i];
287     button.type = 'button';
288     button.onclick = function () { select(this.value); };
289     button.textContent = data[i];
290     li.appendChild(button);
291     results.appendChild(li);
292     }
293     };
294     &lt;/script&gt;
295     &lt;p&gt;(The data in this example is not real. Try searching for "Google" or "Apple".)&lt;/p&gt;
296     &lt;/body&gt;
297     &lt;/html&gt;</pre>
298    
299     <p>The two workers use a common library for performing the actual
300     network calls. This library is as follows:</p>
301    
302     <pre>function get(url) {
303     try {
304     var xhr = new XMLHttpRequest();
305     xhr.open('GET', url, false);
306     xhr.send();
307     return xhr.responseText;
308     } catch (e) {
309     return ''; // turn all errors into empty results
310     }
311     }</pre>
312    
313     <p>The stock updater worker is as follows:</p>
314    
315     <pre>importScripts('io.js');
316     var timer;
317     var symbol;
318     function update() {
319     postMessage(symbol + ' ' + get('stock.cgi?' + symbol));
320     timer = setTimeout(update, 10000);
321     }
322     onmessage = function (event) {
323     if (timer)
324     clearTimeout(timer);
325     symbol = event.data;
326     update();
327     };</pre>
328    
329     <p>The search query worker is as follows:</p>
330    
331     <pre>importScripts('io.js');
332     onmessage = function (event) {
333     postMessage(get('search.cgi?' + event.data));
334     };</pre>
335    
336     <p><a href=http://www.whatwg.org/demos/workers/stocks/page.html>View this example online</a>.</p>
337    
338    
339     <h4 id=shared-workers><span class=secno>1.2.4 </span>Shared workers</h4>
340    
341 wakaba 1.106 <p><i>This section is non-normative.</i></p>
342 wakaba 1.82
343     <p>In this example, multiple windows (viewers) can be opened that
344     are all viewing the same map. All the windows share the same map
345     information, with a single worker coordinating all the viewers. Each
346     viewer can move around independently, but if they set any data on
347     the map, all the viewers are updated.</p>
348    
349     <p>The main page isn't interesting, it merely provides a way to open
350     the viewers:</p>
351    
352     <pre>&lt;!DOCTYPE HTML&gt;
353     &lt;html&gt;
354     &lt;head&gt;
355     &lt;title&gt;Workers example: Multiviewer&lt;/title&gt;
356     &lt;script&gt;
357     function openViewer() {
358     window.open('viewer.html');
359     }
360     &lt;/script&gt;
361     &lt;/head&gt;
362     &lt;body&gt;
363     &lt;p&gt;&lt;button type=button onclick="openViewer()"&gt;Open a new
364     viewer&lt;/button&gt;&lt;/p&gt;
365     &lt;p&gt;Each viewer opens in a new window. You can have as many viewers
366     as you like, they all view the same data.&lt;/p&gt;
367     &lt;/body&gt;
368     &lt;/html&gt;</pre>
369    
370     <p>The viewer is more involved:</p>
371    
372     <pre>&lt;!DOCTYPE HTML&gt;
373     &lt;html&gt;
374     &lt;head&gt;
375     &lt;title&gt;Workers example: Multiviewer viewer&lt;/title&gt;
376     &lt;script&gt;
377     var worker = new SharedWorker('worker.js', 'core');
378    
379     // CONFIGURATION
380     function configure(event) {
381     if (event.data.substr(0, 4) != 'cfg ') return;
382     var name = event.data.substr(4).split(' ', 1);
383     // update display to mention our name is name
384     document.getElementsByTagName('h1')[0].textContent += ' ' + name;
385     // no longer need this listener
386     worker.port.removeEventListener('message', configure, false);
387     }
388     worker.port.addEventListener('message', configure, false);
389    
390     // MAP
391     function paintMap(event) {
392     if (event.data.substr(0, 4) != 'map ') return;
393     var data = event.data.substr(4).split(',');
394     // display tiles data[0] .. data[8]
395     var canvas = document.getElementById('map');
396     var context = canvas.getContext('2d');
397     for (var y = 0; y &lt; 3; y += 1) {
398     for (var x = 0; x &lt; 3; x += 1) {
399     var tile = data[y * 3 + x];
400     if (tile == '0')
401     context.fillStyle = 'green';
402     else
403     context.fillStyle = 'maroon';
404     fillRect(x * 50, y * 50, 50, 50);
405     }
406     }
407     }
408     worker.port.addEventListener('message', paintMap, false);
409    
410     // PUBLIC CHAT
411     function updatePublicChat(event) {
412     if (event.data.substr(0, 4) != 'txt ') return;
413     var name = event.data.substr(4).split(' ', 1);
414     var message = event.data.substr(4 + length(name) + 1);
415     // display "&lt;name&gt; message" in public chat
416     var dialog = document.getElementById('public');
417     var dt = document.createElement('dt');
418     dt.textContent = name;
419     dialog.appendChild(dt);
420     var dd = document.createElement('dd');
421     dd.textContent = message;
422     dialog.appendChild(dd);
423     }
424     worker.port.addEventListener('message', updatePublicChat, false);
425    
426     // PRIVATE CHAT
427     function startPrivateChat(event) {
428     if (event.data.substr(0, 4) != 'msg ') return;
429     var name = event.data.substr(4).split(' ', 1);
430     var port = event.ports[0];
431     // display a private chat UI
432     var ul = document.getElementById('private');
433     var li = document.createElement('li');
434     var h3 = document.createElement('h3');
435     h3.textContent = 'Private chat with ' + name;
436     li.appendChild(h3);
437     var dialog = document.createElement('dialog');
438     var addMessage = function(name, message) {
439     var dt = document.createElement('dt');
440     dt.textContent = name;
441     dialog.appendChild(dt);
442     var dd = document.createElement('dd');
443     dd.textContent = message;
444     dialog.appendChild(dd);
445     };
446     port.onmessage = function (event) {
447     addMessage(name, event.data);
448     };
449     li.appendChild(dialog);
450     var form = document.createElement('form');
451     var p = document.createElement('p');
452     var input = document.createElement('input');
453     input.size = 50;
454     p.appendChild(input);
455     p.appendChild(document.createTextNode(' '));
456     var button = document.createElement('button');
457     button.textContent = 'Post';
458     p.appendChild(button);
459     form.onsubmit = function () {
460     port.postMessage(input.value);
461     addMessage('me', input.value);
462     input.value = '';
463     return false;
464     };
465     form.appendChild(p);
466     li.appendChild(form);
467     }
468     worker.port.addEventListener('message', startPrivateChat, false);
469 wakaba 1.174
470     worker.port.start();
471 wakaba 1.82 &lt;/script&gt;
472     &lt;/head&gt;
473     &lt;body&gt;
474     &lt;h1&gt;Viewer&lt;/h1&gt;
475     &lt;h2&gt;Map&lt;/h2&gt;
476     &lt;p&gt;&lt;canvas id="map" height=150 width=150&gt;&lt;/canvas&gt;&lt;/p&gt;
477     &lt;p&gt;
478     &lt;button type=button onclick="worker.port.postMessage('mov left')"&gt;Left&lt;/button&gt;
479     &lt;button type=button onclick="worker.port.postMessage('mov up')"&gt;Up&lt;/button&gt;
480     &lt;button type=button onclick="worker.port.postMessage('mov down')"&gt;Down&lt;/button&gt;
481     &lt;button type=button onclick="worker.port.postMessage('mov right')"&gt;Right&lt;/button&gt;
482     &lt;button type=button onclick="worker.port.postMessage('set 0')"&gt;Set 0&lt;/button&gt;
483     &lt;button type=button onclick="worker.port.postMessage('set 1')"&gt;Set 1&lt;/button&gt;
484     &lt;/p&gt;
485     &lt;h2&gt;Public Chat&lt;/h2&gt;
486     &lt;dialog id="public"&gt;&lt;/dialog&gt;
487     &lt;form onsubmit="worker.port.postMessage('txt ' + message.value); message.value = ''; return false;"&gt;
488     &lt;p&gt;
489     &lt;input type="text" name="message" size="50"&gt;
490     &lt;button&gt;Post&lt;/button&gt;
491     &lt;/p&gt;
492     &lt;/form&gt;
493     &lt;h2&gt;Private Chat&lt;/h2&gt;
494     &lt;ul id="private"&gt;&lt;/ul&gt;
495     &lt;/body&gt;
496     &lt;/html&gt;
497     </pre>
498    
499     <p>There are several key things worth noting about the way the
500     viewer is written.</p>
501    
502     <p><strong>Multiple listeners</strong>. Instead of a single message
503     processing function, the code here attaches multiple event
504     listeners, each one performing a quick check to see if it is
505     relevant for the message. In this example it doesn't make much
506     difference, but if multiple authors wanted to collaborate using a
507     single port to communicate with a worker, it would allow for
508     independent code instead of changes having to all be made to a
509     single event handling function.</p>
510    
511     <p>Registering event listeners in this way also allows you to
512     unregister specific listeners when you are done with them, as is
513     done with the <code title="">configure()</code> method in this
514     example.</p>
515    
516     <p>Finally, the worker:</p>
517    
518 wakaba 1.130 <pre>
519     var nextName = 0;
520 wakaba 1.82 function getNextName() {
521     // this could use more friendly names
522     // but for now just return a number
523     return nextName++;
524     }
525    
526     var map = [
527     [0, 0, 0, 0, 0, 0, 0],
528     [1, 1, 0, 1, 0, 1, 1],
529     [0, 1, 0, 1, 0, 0, 0],
530     [0, 1, 0, 1, 0, 1, 1],
531     [0, 0, 0, 1, 0, 0, 0],
532     [1, 0, 0, 1, 1, 1, 1],
533     [1, 1, 0, 1, 1, 0, 1],
534     ];
535    
536     function wrapX(x) {
537     if (x &lt; 0) return wrapX(x + map[0].length);
538     if (x &gt;= map[0].length) return wrapX(x - map[0].length);
539     return x;
540     }
541    
542     function wrapY(y) {
543     if (y &lt; 0) return wrapY(y + map.length);
544     if (y &gt;= map[0].length) return wrapY(y - map.length);
545     return y;
546     }
547    
548     function sendMapData(callback) {
549     var data = '';
550     for (var y = viewer.y-1; y &lt;= viewer.y+1; y += 1) {
551     for (var x = viewer.x-1; x &lt;= viewer.x+1; x += 1) {
552     if (data != '')
553     data += ',';
554     data += map[y][x];
555     }
556     }
557     callback('map ' + data);
558     }
559    
560     var viewers = {};
561     onconnect = function (event) {
562     event.ports[0]._name = getNextName();
563     event.ports[0]._data = { port: event.port, x: 0, y: 0, };
564     viewers[event.ports[0]._name] = event.port._data;
565     event.ports[0].postMessage('cfg ' + name);
566     event.ports[0].onmessage = getMessage;
567     sendMapData(event.ports[0].postMessage);
568     };
569    
570     function getMessage(event) {
571     switch (event.data.substr(0, 4)) {
572     case 'mov ':
573     var direction = event.data.substr(4);
574     var dx = 0;
575     var dy = 0;
576     switch (direction) {
577     case 'up': dy = -1; break;
578     case 'down': dy = 1; break;
579     case 'left': dx = -1; break;
580     case 'right': dx = 1; break;
581     }
582     event.target._data.x = wrapX(event.target._data.x + dx);
583     event.target._data.y = wrapY(event.target._data.y + dy);
584     sendMapData(event.target.postMessage);
585     break;
586     case 'set ':
587     var value = event.data.substr(4);
588     map[event.target._data.y][event.target._data.x] = value;
589     for (var viewer in viewers)
590     sendMapData(viewers[viewer].port.postMessage);
591     break;
592     case 'txt ':
593     var name = event.target._name;
594     var message = event.data.substr(4);
595     for (var viewer in viewers)
596     viewers[viewer].port.postMessage('txt ' + name + ' ' + message);
597     break;
598     case 'msg ':
599     var party1 = event._data;
600     var party2 = viewers[event.data.substr(4).split(' ', 1)];
601     if (party2) {
602     var channel = new MessageChannel();
603     party1.port.postMessage('msg ' + party2.name, [channel.port1]);
604     party2.port.postMessage('msg ' + party1.name, [channel.port2]);
605     }
606     break;
607     }
608     }</pre>
609    
610     <p><strong>Connecting to multiple pages</strong>. The script uses
611     the <code title=handler-SharedWorkerGlobalScope-onconnect><a href=#handler-sharedworkerglobalscope-onconnect>onconnect</a></code>
612     event listener to listen for multiple connections.</p>
613    
614     <p><strong>Direct channels</strong>. When the worker receives a
615     "msg" message from one viewer naming another viewer, it sets up a
616     direct connection between the two, so that the two viewers can
617     communicate directly without the worker having to proxy all the
618     messages.</p>
619    
620     <p><a href=http://www.whatwg.org/demos/workers/multiviewer/page.html>View this example online</a>.</p>
621    
622    
623     <h4 id=delegation><span class=secno>1.2.5 </span>Delegation</h4>
624    
625 wakaba 1.106 <p><i>This section is non-normative.</i></p>
626 wakaba 1.82
627     <p>With multicore CPUs becoming prevalent, one way to obtain better
628     performance is to split computationally expensive tasks amongst
629     multiple workers. In this example, a computationally expensive task
630     that is to be performed for every number from 1 to 10,000,000 is
631     farmed out to ten subworkers.</p>
632    
633     <p>The main page is as follows, it just reports the result:</p>
634    
635     <pre>&lt;!DOCTYPE HTML&gt;
636     &lt;html&gt;
637     &lt;head&gt;
638 wakaba 1.178 &lt;title&gt;Worker example: Multicore computation&lt;/title&gt;
639 wakaba 1.82 &lt;/head&gt;
640     &lt;body&gt;
641 wakaba 1.178 &lt;p&gt;Result: &lt;output id="result"&gt;&lt;/output&gt;&lt;/p&gt;
642 wakaba 1.82 &lt;script&gt;
643     var worker = new Worker('worker.js');
644     worker.onmessage = function (event) {
645     document.getElementById('result').textContent = event.data;
646     };
647     &lt;/script&gt;
648     &lt;/body&gt;
649     &lt;/html&gt;</pre>
650    
651     <p>The worker itself is as follows:</p>
652    
653     <pre>// settings
654     var num_workers = 10;
655     var items_per_worker = 1000000;
656    
657     // start the workers
658     var result = 0;
659     var pending_workers = num_workers;
660     for (var i = 0; i &lt; num_workers; i += 1) {
661     var worker = new Worker('core.js');
662     worker.postMessage(i * items_per_worker);
663     worker.postMessage((i+1) * items_per_worker);
664     worker.onmessage = storeResult;
665     }
666    
667     // handle the results
668     function storeResult(event) {
669     result += 1*event.data;
670     pending_workers -= 1;
671     if (pending_workers &lt;= 0)
672     postMessage(result); // finished!
673     }</pre>
674    
675     <p>It consists of a loop to start the subworkers, and then a handler
676     that waits for all the subworkers to respond.</p>
677    
678     <p>The subworkers are implemented as follows:</p>
679    
680     <pre>var start;
681     onmessage = getStart;
682     function getStart(event) {
683     start = 1*event.data;
684     onmessage = getEnd;
685     }
686    
687     var end;
688     function getEnd(event) {
689     end = 1*event.data;
690     onmessage = null;
691     work();
692     }
693    
694     function work() {
695     var result = 0;
696     for (var i = start; i &lt; end; i += 1) {
697     // perform some complex calculation here
698     result += 1;
699     }
700     postMessage(result);
701     close();
702     }</pre>
703    
704     <p>They receive two numbers in two events, perform the computation
705     for the range of numbers thus specified, and then report the result
706     back to the parent.</p>
707    
708     <p><a href=http://www.whatwg.org/demos/workers/multicore/page.html>View this example online</a>.</p>
709    
710    
711     <h4 id=providing-libraries><span class=secno>1.2.6 </span>Providing libraries</h4>
712    
713 wakaba 1.106 <p><i>This section is non-normative.</i></p>
714 wakaba 1.82
715     <p>Suppose that a cryptography library is made available that
716     provides three tasks:</p>
717    
718 wakaba 1.130 <dl><dt>Generate a public/private key pair</dt>
719 wakaba 1.82
720     <dd>Takes a port, on which it will send two messages, first the
721     public key and then the private key.</dd>
722    
723     <dt>Given a plaintext and a public key, return the corresponding cyphertext</dt>
724    
725     <dd>Takes a port, to which any number of messages can be sent, the
726     first giving the public key, and the remainder giving the
727     plaintext, each of which is encrypted and then sent on that same
728     channel as the cyphertext. The user can close the port when it is
729     done encrypting content.</dd>
730    
731     <dt>Given a cyphertext and a private key, return the corresponding plaintext</dt>
732    
733     <dd>Takes a port, to which any number of messages can be sent, the
734     first giving the private key, and the remainder giving the
735     cyphertext, each of which is decrypted and then sent on that same
736     channel as the plaintext. The user can close the port when it is
737     done decrypting content.</dd>
738    
739 wakaba 1.130 </dl><p>The library itself is as follows:</p>
740 wakaba 1.82
741     <pre>function handleMessage(e) {
742     if (e.data == "genkeys")
743     genkeys(e.ports[0]);
744     else if (e.data == "encrypt")
745     encrypt(e.ports[0]);
746     else if (e.data == "decrypt")
747     decrypt(e.ports[0]);
748     }
749    
750     function genkeys(p) {
751     var keys = _generateKeyPair();
752     p.postMessage(keys[0]);
753     p.postMessage(keys[1]);
754     }
755    
756     function encrypt(p) {
757     var key, state = 0;
758     p.onmessage = function (e) {
759     if (state == 0) {
760     key = e.data;
761     state = 1;
762     } else {
763     p.postMessage(_encrypt(key, e.data));
764     }
765     };
766     }
767    
768     function decrypt(p) {
769     var key, state = 0;
770     p.onmessage = function (e) {
771     if (state == 0) {
772     key = e.data;
773     state = 1;
774     } else {
775     p.postMessage(_decrypt(key, e.data));
776     }
777     };
778     }
779    
780     // support being used as a shared worker as well as a dedicated worker
781 wakaba 1.177 if ('onmessage' in this) // dedicated worker
782 wakaba 1.82 onmessage = handleMessage;
783     else // shared worker
784     onconnect = function (e) { e.port.onmessage = handleMessage; }
785    
786    
787     // the "crypto" functions:
788    
789     function _generateKeyPair() {
790     return [Math.random(), Math.random()];
791     }
792    
793     function _encrypt(k, s) {
794     return 'encrypted-' + k + ' ' + s;
795     }
796    
797     function _decrypt(k, s) {
798     return s.substr(s.indexOf(' ')+1);
799     }</pre>
800    
801     <p>Note that the crypto functions here are just stubs and don't do
802     real cryptography.</p>
803    
804     <p>This library could be used as follows:</p>
805    
806     <pre>&lt;!DOCTYPE HTML&gt;
807     &lt;html&gt;
808     &lt;head&gt;
809     &lt;title&gt;Worker example: Crypto library&lt;/title&gt;
810     &lt;script&gt;
811     var crytoLib = new Worker('libcrypto-v1.js'); // or could use 'libcrypto-v2.js'
812     function getKeys() {
813     var state = 0;
814     cryptoLib.startConversation("genkeys").onmessage = function (e) {
815     if (state == 0)
816     document.getElementById('public').value = e.data;
817     else if (state == 1)
818     document.getElementById('private').value = e.data;
819     state += 1;
820     };
821     }
822     function enc() {
823     var port = cryptoLib.startConversation("encrypt");
824     port.postMessage(document.getElementById('public').value);
825     port.postMessage(document.getElementById('input').value);
826     port.onmessage = function (e) {
827     document.getElementById('input').value = e.data;
828     port.close();
829     };
830     }
831     function dec() {
832     var port = cryptoLib.startConversation("decrypt");
833     port.postMessage(document.getElementById('private').value);
834     port.postMessage(document.getElementById('input').value);
835     port.onmessage = function (e) {
836     document.getElementById('input').value = e.data;
837     port.close();
838     };
839     }
840     &lt;/script&gt;
841     &lt;style&gt;
842     textarea { display: block; }
843     &lt;/style&gt;
844     &lt;/head&gt;
845     &lt;body onload="getKeys()"&gt;
846     &lt;fieldset&gt;
847     &lt;legend&gt;Keys&lt;/legend&gt;
848     &lt;p&gt;&lt;label&gt;Public Key: &lt;textarea id="public"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
849     &lt;p&gt;&lt;label&gt;Private Key: &lt;textarea id="private"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
850     &lt;/fieldset&gt;
851     &lt;p&gt;&lt;label&gt;Input: &lt;textarea id="input"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
852     &lt;p&gt;&lt;button onclick="enc()"&gt;Encrypt&lt;/button&gt; &lt;button onclick="dec()"&gt;Decrypt&lt;/button&gt;&lt;/p&gt;
853     &lt;/body&gt;
854     &lt;/html&gt;</pre>
855    
856     <p>A later version of the API, though, might want to offload all the
857     crypto work onto subworkers. This could be done as follows:</p>
858    
859     <pre>function handleMessage(e) {
860     if (e.data == "genkeys")
861     genkeys(e.ports[0]);
862     else if (e.data == "encrypt")
863     encrypt(e.ports[0]);
864     else if (e.data == "decrypt")
865     decrypt(e.ports[0]);
866     }
867    
868     function genkeys(p) {
869     var generator = new Worker('libcrypto-v2-generator.js');
870     generator.postMessage('', [p]);
871     }
872    
873     function encrypt(p) {
874     p.onmessage = function (e) {
875     var key = e.data;
876     var encryptor = new Worker('libcrypto-v2-encryptor.js');
877     encryptor.postMessage(key, [p]);
878     };
879     }
880    
881     function encrypt(p) {
882     p.onmessage = function (e) {
883     var key = e.data;
884     var decryptor = new Worker('libcrypto-v2-decryptor.js');
885     decryptor.postMessage(key, [p]);
886     };
887     }
888    
889     // support being used as a shared worker as well as a dedicated worker
890 wakaba 1.177 if ('onmessage' in this) // dedicated worker
891 wakaba 1.82 onmessage = handleMessage;
892     else // shared worker
893     onconnect = function (e) { e.ports[0].onmessage = handleMessage };
894     </pre>
895    
896     <p>The little subworkers would then be as follows.</p>
897    
898     <p>For generating key pairs:</p>
899    
900     <pre>onmessage = function (e) {
901     var k = _generateKeyPair();
902     e.ports[0].postMessage(k[0]);
903     e.ports[0].postMessage(k[1]);
904     close();
905     }
906    
907     function _generateKeyPair() {
908     return [Math.random(), Math.random()];
909     }</pre>
910    
911     <p>For encrypting:</p>
912    
913     <pre>onmessage = function (e) {
914     var key = e.data;
915     e.ports[0].onmessage = function (e) {
916     var s = e.data;
917     postMessage(_encrypt(key, s));
918     }
919     }
920    
921     function _encrypt(k, s) {
922     return 'encrypted-' + k + ' ' + s;
923     }</pre>
924    
925     <p>For decrypting:</p>
926    
927     <pre>onmessage = function (e) {
928     var key = e.data;
929     e.ports[0].onmessage = function (e) {
930     var s = e.data;
931     postMessage(_decrypt(key, s));
932     }
933     }
934    
935     function _decrypt(k, s) {
936     return s.substr(s.indexOf(' ')+1);
937     }</pre>
938    
939     <p>Notice how the users of the API don't have to even know that this
940 wakaba 1.130 is happening &mdash; the API hasn't changed; the library can
941 wakaba 1.82 delegate to subworkers without changing its API, even though it is
942     accepting data using message channels.</p>
943    
944     <p><a href=http://www.whatwg.org/demos/workers/crypto/page.html>View this example online</a>.</p>
945    
946    
947    
948    
949     <h2 id=conformance-requirements><span class=secno>2 </span>Conformance requirements</h2>
950    
951     <p>All diagrams, examples, and notes in this specification are
952     non-normative, as are all sections explicitly marked non-normative.
953     Everything else in this specification is normative.</p>
954    
955     <p>The key words "MUST", "MUST NOT", "REQUIRED", <!--"SHALL", "SHALL
956     NOT",--> "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
957     "OPTIONAL" in the normative parts of this document are to be
958     interpreted as described in RFC2119. For readability, these words do
959     not appear in all uppercase letters in this specification. <a href=#refsRFC2119>[RFC2119]</a></p>
960    
961     <p>Requirements phrased in the imperative as part of algorithms
962     (such as "strip any leading space characters" or "return false and
963     abort these steps") are to be interpreted with the meaning of the
964     key word ("must", "should", "may", etc) used in introducing the
965     algorithm.</p>
966    
967     <p>Some conformance requirements are phrased as requirements on
968     attributes, methods or objects. Such requirements are to be
969     interpreted as requirements on user agents.</p>
970    
971     <p>Conformance requirements phrased as algorithms or specific steps
972     may be implemented in any manner, so long as the end result is
973     equivalent. (In particular, the algorithms defined in this
974     specification are intended to be easy to follow, and not intended to
975     be performant.)</p>
976    
977     <p>The only conformance class defined by this specification is user
978     agents.</p>
979    
980     <p>User agents may impose implementation-specific limits on
981     otherwise unconstrained inputs, e.g. to prevent denial of service
982     attacks, to guard against running out of memory, or to work around
983     platform-specific limitations.</p>
984    
985    
986 wakaba 1.110 <h3 id=dependencies><span class=secno>2.1 </span>Dependencies</h3>
987 wakaba 1.82
988     <p>This specification relies on several other underlying
989     specifications.</p>
990    
991 wakaba 1.130 <dl><dt>HTML5</dt>
992 wakaba 1.82
993     <dd>
994    
995     <p>Many fundamental concepts from HTML5 are used by this
996     specification. <a href=#refsHTML5>[HTML5]</a></p>
997    
998     </dd>
999    
1000     <dt>WebIDL</dt>
1001    
1002     <dd>
1003    
1004     <p>The IDL blocks in this specification use the semantics of the
1005 wakaba 1.129 WebIDL specification. <a href=#refsWEBIDL>[WEBIDL]</a></p>
1006 wakaba 1.82
1007     </dd>
1008    
1009 wakaba 1.130 </dl><h2 id=terminology><span class=secno>3 </span>Terminology</h2>
1010 wakaba 1.82
1011     <p>The construction "a <code title="">Foo</code> object", where
1012     <code title="">Foo</code> is actually an interface, is sometimes
1013     used instead of the more accurate "an object implementing the
1014     interface <code title="">Foo</code>".</p>
1015    
1016     <p>The term DOM is used to refer to the API set made available to
1017     scripts in Web applications, and does not necessarily imply the
1018     existence of an actual <code>Document</code> object or of any other
1019     <code>Node</code> objects as defined in the DOM Core
1020 wakaba 1.129 specifications. <a href=#refsDOMCORE>[DOMCORE]</a></p>
1021 wakaba 1.82
1022 wakaba 1.154 <p>An IDL attribute is said to be <em>getting</em> when its value is
1023 wakaba 1.82 being retrieved (e.g. by author script), and is said to be
1024     <em>setting</em> when a new value is assigned to it.</p>
1025     <p>The term "JavaScript" is used to refer to ECMA262, rather than
1026     the official term ECMAScript, since the term JavaScript is more
1027     widely known. <a href=#refsECMA262>[ECMA262]</a></p>
1028    
1029 wakaba 1.110 <h2 id=infrastructure><span class=secno>4 </span>Infrastructure</h2>
1030 wakaba 1.82
1031     <p>There are two kinds of workers; dedicated workers, and shared
1032     workers. Dedicated workers, once created, and are linked to their
1033     creator; but message ports can be used to communicate from a
1034     dedicated worker to multiple other browsing contexts or
1035     workers. Shared workers, on the other hand, are named, and once
1036     created any script running in the same <span>origin</span> can
1037     obtain a reference to that worker and communicate with it.</p>
1038    
1039    
1040 wakaba 1.110 <h3 id=the-global-scope><span class=secno>4.1 </span>The global scope</h3>
1041 wakaba 1.82
1042     <p>The global scope is the "inside" of a worker.</p>
1043    
1044 wakaba 1.110 <h4 id=the-workerglobalscope-abstract-interface><span class=secno>4.1.1 </span>The <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> abstract interface</h4>
1045 wakaba 1.82
1046     <pre class=idl>interface <dfn id=workerglobalscope>WorkerGlobalScope</dfn> {
1047     readonly attribute <a href=#workerglobalscope>WorkerGlobalScope</a> <a href=#dom-workerglobalscope-self title=dom-WorkerGlobalScope-self>self</a>;
1048     readonly attribute <a href=#workerlocation>WorkerLocation</a> <a href=#dom-workerglobalscope-location title=dom-WorkerGlobalScope-location>location</a>;
1049    
1050     void <a href=#dom-workerglobalscope-close title=dom-WorkerGlobalScope-close>close</a>();
1051 wakaba 1.108 <!-- v2-onclose attribute <span>Function</span> <span title="handler-WorkerGlobalScope-onclose">onclose</span>;
1052     --> attribute <span>Function</span> <a href=#handler-workerglobalscope-onerror title=handler-WorkerGlobalScope-onerror>onerror</a>;
1053 wakaba 1.125 };
1054 wakaba 1.155 <a href=#workerglobalscope>WorkerGlobalScope</a> implements <a href=#workerutils>WorkerUtils</a>;
1055     <a href=#workerglobalscope>WorkerGlobalScope</a> implements <span>EventTarget</span>;</pre>
1056 wakaba 1.82
1057     <p>The <dfn id=dom-workerglobalscope-self title=dom-WorkerGlobalScope-self><code>self</code></dfn> attribute
1058     must return the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object itself.</p>
1059    
1060     <p>The <dfn id=dom-workerglobalscope-location title=dom-WorkerGlobalScope-location><code>location</code></dfn>
1061     attribute must return the <code><a href=#workerlocation>WorkerLocation</a></code> object created
1062     for the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object when the worker was
1063     created. It represents the <span>absolute URL</span> of the script
1064 wakaba 1.83 that was used to initialize the worker, after any redirects.</p>
1065 wakaba 1.82
1066 wakaba 1.130 <hr><p>When a script invokes the <dfn id=dom-workerglobalscope-close title=dom-WorkerGlobalScope-close><code>close()</code></dfn>
1067 wakaba 1.82 method on a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object, the user agent
1068     must run the following steps (atomically):</p>
1069    
1070 wakaba 1.130 <ol><li><p>Discard any <span title=concept-task>tasks</span> that
1071 wakaba 1.82 have been added to the <span>event loop</span>'s <span title="task
1072     queue">task queues</span>.</p>
1073    
1074     <!-- v2-onclose
1075     <li><p><span>Queue a task</span> to <span>fire a simple
1076 wakaba 1.166 event</span> named <code title="event-close">close</code> at the
1077 wakaba 1.82 <code>WorkerGlobalScope</code> object.</p></li>
1078     -->
1079    
1080     <li><p>Set the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's
1081     <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag to
1082     true. (This prevents any further tasks from being queued.)</li>
1083    
1084     <li><p>Disentangle all the ports in the list of <a href="#the-worker's-ports">the worker's
1085     ports</a>.</li>
1086    
1087 wakaba 1.162 </ol><p>The following are the <span>event handlers</span> (and their
1088     corresponding <span title="event handler event type">event handler
1089     event types</span>) that must be supported, as IDL attributes, by
1090     objects implementing the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>
1091     interface:</p>
1092 wakaba 1.82
1093 wakaba 1.162 <table><thead><tr><th><span title="event handlers">Event handler</span> <th><span>Event handler event type</span>
1094 wakaba 1.130 <tbody><!-- v2-onclose <tr><td><dfn title="handler-WorkerGlobalScope-onclose"><code>onclose</code></dfn> <td> <code title="event-close">close</code> --><tr><td><dfn id=handler-workerglobalscope-onerror title=handler-WorkerGlobalScope-onerror><code>onerror</code></dfn> <td> <code title=event-error>error</code>
1095 wakaba 1.179 </table><hr><p>The <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> interface must not exist if
1096     the interface's <span>relevant namespace object</span> is a
1097     <code>Window</code> object. <a href=#refsWEBIDL>[WEBIDL]</a></p>
1098    
1099    
1100    
1101     <h4 id=dedicated-workers-and-the-dedicatedworkerglobalscope-interface><span class=secno>4.1.2 </span>Dedicated workers and the <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> interface</h4>
1102 wakaba 1.82
1103 wakaba 1.125 <pre class=idl>[Supplemental, NoInterfaceObject]
1104     interface <dfn id=dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</dfn> : <a href=#workerglobalscope>WorkerGlobalScope</a> {
1105 wakaba 1.159 void <a href=#dom-dedicatedworkerglobalscope-postmessage title=dom-DedicatedWorkerGlobalScope-postMessage>postMessage</a>(in any message, in optional <span>MessagePortArray</span> ports);<!--
1106 wakaba 1.82 <span>MessagePort</span> <span title="dom-DedicatedWorkerGlobalScope-startConversation">startConversation</span>(in any message);-->
1107 wakaba 1.108 attribute <span>Function</span> <a href=#handler-dedicatedworkerglobalscope-onmessage title=handler-DedicatedWorkerGlobalScope-onmessage>onmessage</a>;
1108 wakaba 1.82 };</pre>
1109    
1110     <p><code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> objects act as if they
1111     had an implicit <code>MessagePort</code> associated with them. This
1112     port is part of a channel that is set up when the worker is created,
1113     but it is not exposed. This object must never be garbage collected
1114     before the <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> object.</p>
1115    
1116     <p>All messages received by that port must immediately be retargeted
1117     at the <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> object.</p>
1118    
1119     <p>The <dfn id=dom-dedicatedworkerglobalscope-postmessage title=dom-DedicatedWorkerGlobalScope-postMessage><code>postMessage()</code></dfn><!--
1120     and <dfn
1121     title="dom-DedicatedWorkerGlobalScope-startConversation"><code>startConversation()</code></dfn>-->
1122     method<!--s (startConversation)--> on
1123     <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> objects must act as if, when
1124     invoked, it<!--/they (startConversation)--> immediately invoked the
1125     method of the same name on the port, with the same arguments, and
1126     returned the same return value.</p>
1127    
1128 wakaba 1.162 <p>The following are the <span>event handlers</span> (and their
1129     corresponding <span title="event handler event type">event handler
1130     event types</span>) that must be supported, as IDL attributes, by
1131     objects implementing the <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code>
1132     interface:</p>
1133 wakaba 1.82
1134 wakaba 1.162 <table><thead><tr><th><span title="event handlers">Event handler</span> <th><span>Event handler event type</span>
1135 wakaba 1.130 <tbody><tr><td><dfn id=handler-dedicatedworkerglobalscope-onmessage title=handler-DedicatedWorkerGlobalScope-onmessage><code>onmessage</code></dfn> <td> <code title=event-message>message</code>
1136 wakaba 1.175 </table><p>For the purposes of the <span>application cache</span> networking
1137     model, a dedicated worker is an extension of the <span>cache
1138     host</span> from which it was created.</p>
1139 wakaba 1.82
1140    
1141    
1142 wakaba 1.110 <h4 id=shared-workers-and-the-sharedworkerglobalscope-inteface><span class=secno>4.1.3 </span>Shared workers and the <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> inteface</h4>
1143 wakaba 1.82
1144 wakaba 1.125 <pre class=idl>[Supplemental, NoInterfaceObject]
1145     interface <dfn id=sharedworkerglobalscope>SharedWorkerGlobalScope</dfn> : <a href=#workerglobalscope>WorkerGlobalScope</a> {
1146 wakaba 1.82 readonly attribute DOMString <a href=#dom-sharedworkerglobalscope-name title=dom-SharedWorkerGlobalScope-name>name</a>;
1147 wakaba 1.171 readonly attribute <span>ApplicationCache</span> <span title=dom-SharedWorkerGlobalScope-applicationCache>applicationCache</span>;
1148 wakaba 1.108 attribute <span>Function</span> <a href=#handler-sharedworkerglobalscope-onconnect title=handler-SharedWorkerGlobalScope-onconnect>onconnect</a>;
1149 wakaba 1.82 };</pre>
1150    
1151     <p>Shared workers receive message ports through <code title=event-WorkerGlobalScope-connect>connect</code> events on
1152     their global object for each connection.</p>
1153    
1154     <p>The <dfn id=dom-sharedworkerglobalscope-name title=dom-SharedWorkerGlobalScope-name><code>name</code></dfn>
1155     attribute must return the value it was assigned when the
1156     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object was created by the
1157     "<a href=#run-a-worker>run a worker</a>" algorithm. Its value represents the name
1158     that can be used to obtain a reference to the worker using the
1159     <code><a href=#sharedworker>SharedWorker</a></code> constructor.</p>
1160    
1161 wakaba 1.162 <p>The following are the <span>event handlers</span> (and their
1162     corresponding <span title="event handler event type">event handler
1163     event types</span>) that must be supported, as IDL attributes, by
1164     objects implementing the <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code>
1165     interface:</p>
1166 wakaba 1.82
1167 wakaba 1.162 <table><thead><tr><th><span title="event handlers">Event handler</span> <th><span>Event handler event type</span>
1168 wakaba 1.130 <tbody><tr><td><dfn id=handler-sharedworkerglobalscope-onconnect title=handler-SharedWorkerGlobalScope-onconnect><code>onconnect</code></dfn> <td> <code title=event-connect>connect</code>
1169 wakaba 1.175 </table><p>For the purposes of the <span>application cache</span> networking
1170     model, a shared worker is its own <span>cache host</span>. The
1171     <a href=#run-a-worker>run a worker</a> algorithm takes care of associating the
1172     worker with an <span>application cache</span>.</p>
1173 wakaba 1.82
1174 wakaba 1.171 <p class=note>The <code title=dom-SharedWorkerGlobalScope-applicationCache>applicationCache</code>
1175 wakaba 1.82 attribute returns the <code>ApplicationCache</code> object for the
1176     worker.</p><!-- normative conf criteria is in the appcache section
1177     -->
1178    
1179    
1180 wakaba 1.141 <h3 id=origins-of-workers><span class=secno>4.2 </span>Origins of workers</h3>
1181 wakaba 1.82
1182     <p>Both the <span>origin</span> and <span>effective script
1183     origin</span> of scripts running in workers are the
1184     <span>origin</span> of the <span>absolute URL</span> given in that
1185     the worker's <code title=dom-WorkerGlobalScope-location><a href=#dom-workerglobalscope-location>location</a></code> attribute
1186     represents.</p>
1187    
1188    
1189    
1190 wakaba 1.172 <h3 id=the-event-loop><span class=secno>4.3 </span>The event loop</h3>
1191 wakaba 1.82
1192 wakaba 1.83 <p>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object has an <span>event
1193     loop</span> distinct from those defined for <span title="unit of
1194     related similar-origin browsing contexts">units of related
1195     similar-origin browsing contexts</span>. This <span>event
1196     loop</span> has no associated <span>browsing context</span>, and its
1197     <span title="task queue">task queues</span> only have events,
1198     callbacks, and networking activity as <span title=concept-task>tasks</span>. The processing model of these
1199     <span title="event loop">event loops</span> is defined below in the
1200     <a href=#run-a-worker>run a worker</a> algorithm.</p>
1201 wakaba 1.82
1202     <p>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object also has a <dfn id=dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</dfn> flag, which must
1203     initially be false, but which can get set to true by the algorithms
1204     in the processing model section below.</p>
1205    
1206     <p>Once the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set to
1207     true, the <span>event loop</span>'s <span title="task queue">task
1208     queues</span> must discard any further <span title=concept-task>tasks</span> that would be added to them (tasks
1209 wakaba 1.161 already on the queue are unaffected except where otherwise
1210 wakaba 1.82 specified). Effectively, once the <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is true,
1211     timers stop firing, notifications for all pending asynchronous
1212     operations are dropped, etc.</p>
1213    
1214    
1215 wakaba 1.104
1216 wakaba 1.172 <h3 id="the-worker's-lifetime"><span class=secno>4.4 </span>The worker's lifetime</h3>
1217 wakaba 1.82
1218     <p>Workers communicate with other workers and with <span title="browsing context">browsing contexts</span> through <span title="channel messaging">message channels</span> and their
1219     <code>MessagePort</code> objects.</p>
1220    
1221     <p>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> <var title="">worker global
1222     scope</var> has a list of <dfn id="the-worker's-ports">the worker's ports</dfn>, which
1223     consists of all the <code>MessagePort</code> objects that are
1224     entangled with another port and that have one (but only one) port
1225     owned by <var title="">worker global scope</var>. This list includes
1226     <!--all the <code>MessagePort</code> objects that are in events
1227     pending in the <span>event loop</span>, as well as (commented out
1228     because in practice it makes no difference either way as far as I
1229     can tell, and it would be hard to strictly implement since these
1230     ports might not yet be across the thread boundary)--> the implicit
1231     <code>MessagePort</code> in the case of <a href=#dedicatedworkerglobalscope title=DedicatedWorkerGlobalScope>dedicated workers</a>.</p>
1232    
1233     <p>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> also has a list of <dfn id="the-worker's-workers">the
1234     worker's workers</dfn>. Initially this list is empty; it is
1235     populated when the worker creates or obtains further workers.</p>
1236    
1237     <p>Finally, each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> also has a list of
1238     <dfn id="the-worker's-documents">the worker's <code>Document</code>s</dfn>. Initially this list
1239     is empty; it is populated when the worker is created.</p>
1240    
1241     <p>Whenever a <code>Document</code> <var title="">d</var> is <dfn id="add-a-document-to-the-worker's-documents" title="add a document to the worker's documents">added to the
1242     worker's <code>Document</code>s</dfn>, the user agent must, for each
1243     worker in the list of <a href="#the-worker's-workers">the worker's workers</a> whose list
1244     of <a href="#the-worker's-documents">the worker's <code>Document</code>s</a> does not contain
1245     <var title="">d</var>, <a href="#add-a-document-to-the-worker's-documents" title="add a document to the worker's
1246     documents">add <var title="">d</var> to <var title="">q</var>'s
1247     <code>WorkerGlobalScope</code> owner's list of <span>the worker's
1248     <code>Document</code>s</span></a>.</p> <!-- suggestions welcome
1249     on making this sentence into understandable English -->
1250    
1251     <p>Whenever a <code>Document</code> object is <span title="discard a
1252     Document">discarded</span>, it must be removed from the list of
1253     <a href="#the-worker's-documents">the worker's <code>Document</code>s</a> of each worker
1254     whose list contains that <code>Document</code>.</p>
1255    
1256 wakaba 1.176 <p>Given a <span>script's global object</span> <var title="">o</var>
1257 wakaba 1.82 when creating or obtaining a worker, the <dfn id=list-of-relevant-document-objects-to-add>list of relevant
1258     <code>Document</code> objects to add</dfn> depends on the type of
1259     <var title="">o</var>. If <var title="">o</var> is a
1260     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object (i.e. if we are creating a
1261     nested worker), then the relevant <code>Document</code>s are the
1262     <code>Document</code>s that are in <var title="">o</var>'s own list
1263     of <a href="#the-worker's-documents">the worker's <code>Document</code>s</a>. Otherwise, <var title="">o</var> is a <code>Window</code> object, and the relevant
1264     <code>Document</code> is just the <code>Document</code> that is the
1265     <span>active document</span> of the <code>Window</code> object <var title="">o</var>.</p>
1266    
1267 wakaba 1.130 <hr><p>A worker is said to be a <dfn id=permissible-worker>permissible worker</dfn> if its
1268 wakaba 1.82 list of <a href="#the-worker's-documents">the worker's <code>Document</code>s</a> is not
1269     empty.</p>
1270    
1271     <p>A worker is said to be a <dfn id=protected-worker>protected worker</dfn> if it is a
1272     <a href=#permissible-worker>permissible worker</a> and either it has outstanding
1273     timers, database transactions, or network connections, or its list
1274     of <a href="#the-worker's-ports">the worker's ports</a> is not empty, or its
1275     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> is actually a
1276     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object (i.e. the worker is a
1277     shared worker).</p>
1278    
1279     <p>A worker is said to be an <dfn id=active-needed-worker>active needed worker</dfn> if any
1280     of the <code>Document</code> objects in <a href="#the-worker's-documents">the worker's
1281     <code>Document</code>s</a> are <span>fully active</span>.</p>
1282    
1283     <p>A worker is said to be a <dfn id=suspendable-worker>suspendable worker</dfn> if it is
1284     not an <a href=#active-needed-worker>active needed worker</a> but it is a
1285     <a href=#permissible-worker>permissible worker</a>.</p>
1286    
1287    
1288 wakaba 1.172 <h3 id=processing-model><span class=secno>4.5 </span>Processing model</h3>
1289 wakaba 1.82
1290     <p>When a user agent is to <dfn id=run-a-worker>run a worker</dfn> for a script with
1291 wakaba 1.162 <span>URL</span> <var title="">url</var>, a browsing context <var title="">owner browsing context</var>, an origin <var title="">owner
1292     origin</var>, and with global scope <var title="">worker global
1293     scope</var>, it must run the following steps:</p>
1294 wakaba 1.82
1295 wakaba 1.130 <ol><li>
1296 wakaba 1.82
1297     <p>Create a completely separate and parallel execution environment
1298     (i.e. a separate thread or process or equivalent construct), and
1299     run the rest of these steps asynchronously in that context.</p>
1300    
1301     </li>
1302    
1303     <li><p>If <var title="">worker global scope</var> is actually a
1304     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object (i.e. the worker is a
1305     shared worker), and there are any <span title="relevant application
1306     cache">relevant application caches</span> that are identified by a
1307     manifest URL with the <span>same origin</span> as <var title="">url</var> and that have <var title="">url</var> as one of
1308     their entries, <em>not</em> excluding entries marked as <span title=concept-appcache-foreign>foreign</span>, then associate the
1309     <var title="">worker global scope</var> with the <span title=concept-appcache-selection>most appropriate application
1310     cache</span> of those that match.</li>
1311    
1312     <li>
1313    
1314 wakaba 1.162 <p>Attempt to <span>fetch</span> the resource identified by <var title="">url</var>, from the <var title="">owner origin</var>.</p>
1315     <!-- not http-origin privacy sensitive -->
1316 wakaba 1.82
1317 wakaba 1.83 <p>If the attempt fails, or if the attempt involves any redirects
1318     to URIs that do not have the <span>same origin</span> as <var title="">url</var> (even if the final URI is at the <span>same
1319     origin</span> as the original <var title="">url</var>), then for
1320     each <code><a href=#worker>Worker</a></code> or <code><a href=#sharedworker>SharedWorker</a></code> object
1321     associated with <var title="">worker global scope</var>,
1322     <span>queue a task</span> to <span>fire a simple event</span>
1323 wakaba 1.166 named <code title=event-error>error</code> at that
1324 wakaba 1.83 object. Abort these steps.</p>
1325 wakaba 1.82
1326 wakaba 1.172 <p>If the attempt succeeds, then convert the script resource to
1327     Unicode by assuming it was encoded as UTF-8, to obtain its <var title="">source</var>.</p>
1328 wakaba 1.82
1329     <p>Let <var title="">language</var> be JavaScript.</p>
1330    
1331     <p class=note>As with <code>script</code> elements, the MIME
1332     type of the script is ignored. Unlike with <code>script</code>
1333     elements, there is no way to override the type. It's always
1334 wakaba 1.154 assumed to be JavaScript.</p>
1335 wakaba 1.82
1336     </li>
1337    
1338     <li>
1339    
1340     <p>A new <span title=concept-script>script</span> is now
1341     created, as follows.</p>
1342    
1343     <p>Create a new <span>script execution environment</span>
1344     set up as appropriate for the scripting language <var title="">language</var>.</p>
1345    
1346     <p>Parse/compile/initialize <var title="">source</var> using that
1347     <span>script execution environment</span>, as appropriate for <var title="">language</var>, and thus obtain a <span>list of code
1348     entry-points</span>; set the <i>initial code entry-point</i> to
1349     the entry-point for any executable code to be immediately run.</p>
1350    
1351     <p>Set the <span>script's global object</span> to <var title="">worker global scope</var>.</p>
1352    
1353     <p>Set the <span>script's browsing context</span> to <var title="">owner browsing context</var>.</p>
1354    
1355     <p>Set the <span>script's URL character encoding</span> to
1356     UTF-8. (This is just used for encoding non-ASCII characters in the
1357     query component of URLs.)</p>
1358    
1359     <p>Set the <span>script's base URL</span> to <var title="">url</var>.</p>
1360    
1361     </li>
1362    
1363     <li>
1364    
1365     <p><strong>Closing orphan workers</strong>: Start monitoring the
1366     worker such that no sooner than it stops being either a
1367     <a href=#protected-worker>protected worker</a> or a <a href=#suspendable-worker>suspendable
1368     worker</a>, and no later than it stops being a
1369     <a href=#permissible-worker>permissible worker</a>, <var title="">worker global
1370     scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set
1371     to true<!-- v2-onclose and <span title="queue a task">a task is
1372 wakaba 1.166 queued</span> to <span>fire a simple event</span> named <code
1373 wakaba 1.82 title="event-close">close</code> at <var title="">worker global
1374     scope</var>-->.</p>
1375    
1376     </li>
1377    
1378     <li>
1379    
1380     <p><strong>Suspending workers</strong>: Start monitoring the
1381     worker, such that whenever <var title="">worker global
1382     scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is false
1383     and the worker is a <a href=#suspendable-worker>suspendable worker</a>, the user
1384     agent suspends execution of script in that worker until such time
1385     as either the <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag switches
1386     to true or the worker stops being a <a href=#suspendable-worker>suspendable
1387     worker</a>.</p>
1388    
1389     </li>
1390    
1391     <li>
1392    
1393     <p><span title="jump to a code entry-point">Jump</span> to the
1394     <span title=concept-script>script</span>'s <i>initial code
1395     entry-point</i>, and let that run until it either returns, fails
1396     to catch an exception, or gets prematurely aborted by the
1397     "<a href=#kill-a-worker>kill a worker</a>" or "<a href=#terminate-a-worker>terminate a worker</a>"
1398     algorithms defined below.</p>
1399    
1400 wakaba 1.122 <!-- v2-onclose
1401     <p class="note">If the script gets aborted by the "<span>kill a
1402     worker</span>" algorithm, then that same algorithm will cause
1403     there to only be a single <span title="concept-task">task</span>
1404 wakaba 1.82 in the <span>event loop</span> at the next step, namely the task
1405 wakaba 1.122 for the <code title="message-close">close</code> event. The
1406     "<span>terminate a worker</span>" algorithm removes all the
1407 wakaba 1.82 events.</p>
1408 wakaba 1.122 -->
1409 wakaba 1.82
1410     </li>
1411    
1412     <li><p>If <var title="">worker global scope</var> is actually a
1413     <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> object (i.e. the worker is
1414     a dedicated worker), then enable the <span>port message
1415     queue</span> of the worker's implicit port.</li>
1416    
1417     <li>
1418    
1419     <p><i title="">Event loop</i>: Wait until either there is a <span title=concept-task>task</span> in one of the <span>event
1420     loop</span>'s <span title="task queue">task queues</span> or <var title="">worker global scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set
1421     to true.</p>
1422    
1423     </li>
1424    
1425     <li>
1426    
1427     <p>Run the oldest task on one of the <span>event loop</span>'s
1428     <span title="task queue">task queues</span>, if any. The user
1429     agent may pick any <span>task queue</span>.</p>
1430    
1431     <p class=note>The handling of events or the execution of
1432     callbacks might get prematurely aborted by the "<a href=#kill-a-worker>kill a
1433     worker</a>" or "<a href=#terminate-a-worker>terminate a worker</a>" algorithms
1434     defined below.</p>
1435    
1436     </li>
1437    
1438     <li>
1439    
1440     <p>Remove the task run in the previous step, if any, from its
1441     <span>task queue</span>.</p>
1442    
1443     </li>
1444    
1445     <li>
1446    
1447     <p>If there are any more events in the <span>event loop</span>'s
1448     <span title="task queue">task queues</span> or if <var title="">worker global scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set
1449     to false, then jump back to the step above labeled <i>event
1450     loop</i>.</p>
1451    
1452     </li>
1453    
1454     <li>
1455    
1456     <p>If there are any outstanding transactions that have callbacks
1457     that involve <span title=concept-script>scripts</span> whose
1458     <span title="script's global object">global object</span> is the
1459     <var title="">worker global scope</var>, roll them back (without
1460     invoking any of the callbacks).</p>
1461    
1462     </li>
1463    
1464     <li>
1465    
1466     <p>Empty the <var title="">worker global scope</var>'s <span>list
1467     of active timeouts</span> and its <span>list of active
1468     intervals</span>.</p>
1469    
1470     </li>
1471    
1472     <!-- v2-onclose
1473     <li>
1474    
1475     <p>For each <code>Worker</code> or <code>SharedWorker</code>
1476     object associated with <var title="">worker global scope</var>,
1477     <span>queue a task</span> to <span>fire a simple event</span>
1478 wakaba 1.166 named <code title="event-close">close</code> at that object.</p>
1479 wakaba 1.82
1480     </li>
1481     -->
1482 wakaba 1.130 </ol><hr><p>When a user agent is to <dfn id=kill-a-worker>kill a worker</dfn> it must
1483 wakaba 1.82 run the following steps in parallel with the worker's main loop (the
1484     "<a href=#run-a-worker>run a worker</a>" processing model defined above):</p>
1485    
1486 wakaba 1.130 <ol><!-- v2-onclose
1487 wakaba 1.82 <li><p>If the worker's <code>WorkerGlobalScope</code> object's
1488     <span title="dom-WorkerGlobalScope-closing">closing</span> flag is
1489     false, <span>queue a task</span> to <span>fire a simple
1490 wakaba 1.166 event</span> named <code title="event-close">close</code> at the
1491 wakaba 1.82 worker's <code>WorkerGlobalScope</code> object.</p></li>
1492 wakaba 1.130 --><li><p>Set the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag to
1493 wakaba 1.82 true.</li>
1494    
1495     <!-- v2-onclose
1496     <li><p>Wait a user-agent-defined amount of time. If the "<span>run
1497     a worker</span>" processing model defined above immediately starts
1498     running event listeners registered for the <code
1499     title="event-close">close</code> event, this time should not be
1500     zero &mdash; the idea is that the <code
1501     title="event-close">close</code> event can be used to clean up
1502     when shutting down unexpectedly.</p></li>
1503     -->
1504    
1505     <li><p>If there are any <span title=concept-task>tasks</span>
1506     queued in the <span>event loop</span>'s <span title="task
1507     queue">task queues</span><!-- v2-onclose other than the <code
1508     title="event-close">close</code> event that this algorithm just
1509     added-->, discard them without processing them.</li>
1510    
1511     <!-- v2-onclose
1512     <li><p>If the <code title="event-close">close</code> event that
1513     this algorithm just queued hasn't yet been dispatched, then abort
1514     the script currently running in the worker.</p></li>
1515     -->
1516    
1517     <li><p>Wait a user-agent-defined amount of time.</li>
1518    
1519     <li><p>Abort the script currently running in the worker<!--
1520     v2-onclose (if any script is running, then it will be a handler for
1521     the <code title="event-close">close</code> event)-->.</li>
1522    
1523 wakaba 1.130 </ol><p>User agents may invoke the "<a href=#kill-a-worker>kill a worker</a>"
1524 wakaba 1.82 processing model on a worker at any time, e.g. in response to user
1525     requests, in response to CPU quota management, or when a worker
1526     stops being an <a href=#active-needed-worker>active needed worker</a> if the worker
1527     continues executing even after its <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag was
1528     set to true.</p>
1529    
1530 wakaba 1.130 <hr><p>When a user agent is to <dfn id=terminate-a-worker>terminate a worker</dfn> it must run
1531 wakaba 1.82 the following steps in parallel with the worker's main loop (the
1532     "<a href=#run-a-worker>run a worker</a>" processing model defined above):</p>
1533    
1534 wakaba 1.130 <ol><li><p>Set the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's
1535 wakaba 1.82 <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag to
1536     true.</li>
1537    
1538     <li><p>If there are any <span title=concept-task>tasks</span>
1539     queued in the <span>event loop</span>'s <span title="task
1540     queue">task queues</span>, discard them without processing
1541     them.</li>
1542    
1543     <li><p>Abort the script currently running in the worker.</li>
1544    
1545     <li><p>If the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object is
1546     actually a <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> object (i.e. the
1547     worker is a dedicated worker), then empty the <span>port message
1548     queue</span> of the port that the worker's implicit port is
1549     entangled with.</li>
1550    
1551 wakaba 1.130 </ol><hr><p>The <span>task source</span> for the tasks mentioned above is the
1552 wakaba 1.104 <span>DOM manipulation task source</span>.</p>
1553    
1554    
1555 wakaba 1.172 <h3 id=runtime-script-errors><span class=secno>4.6 </span>Runtime script errors</h3>
1556 wakaba 1.82
1557 wakaba 1.108 <p>Whenever an uncaught runtime script error occurs in one of the
1558     worker's scripts, if the error did not occur while handling a
1559     previous script error, the user agent must <span>report the
1560     error</span> using the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <code title=handler-WorkerGlobalScope-onerror><a href=#handler-workerglobalscope-onerror>onerror</a></code>
1561 wakaba 1.178 attribute.
1562    
1563     <a href=#refsHTML5>[HTML5]</a>
1564    
1565     </p>
1566 wakaba 1.82
1567     <p>For shared workers, if the error is still <i title=concept-error-nothandled>not handled</i> afterwards, or if
1568 wakaba 1.91 the error occurred while handling a previous script error, the error
1569 wakaba 1.181 may be reported to the user.
1570 wakaba 1.178
1571     <a href=#refsHTML5>[HTML5]</a>
1572    
1573     </p>
1574 wakaba 1.82
1575     <p>For dedicated workers, if the error is still <i title=concept-error-nothandled>not handled</i> afterwards, or if
1576 wakaba 1.91 the error occurred while handling a previous script error, the user
1577 wakaba 1.82 agent must <span>queue a task</span> to <a href=#fire-a-worker-error-event>fire a worker error
1578     event</a> at the <code><a href=#worker>Worker</a></code> object associated with the
1579     worker.</p>
1580    
1581     <p>When the user agent is to <dfn id=fire-a-worker-error-event>fire a worker error event</dfn> at
1582     a <code><a href=#worker>Worker</a></code> object, it must dispatch an event that uses
1583     the <code><a href=#errorevent>ErrorEvent</a></code> interface, with the name <code title=event-error>error</code>, that doesn't bubble and is
1584     cancelable, with its <code title=dom-ErrorEvent-message><a href=#dom-errorevent-message>message</a></code>, <code title=dom-ErrorEvent-filename><a href=#dom-errorevent-filename>filename</a></code>, and <code title=dom-ErrorEvent-lineno><a href=#dom-errorevent-lineno>lineno</a></code> attributes set
1585     appropriately. The default action of this event depends on whether
1586     the <code><a href=#worker>Worker</a></code> object is itself in a worker. If it is, and
1587     that worker is also a dedicated worker, then the user agent must
1588     again <span>queue a task</span> to <a href=#fire-a-worker-error-event>fire a worker error
1589     event</a> at the <code><a href=#worker>Worker</a></code> object associated with
1590 wakaba 1.181 <em>that</em> worker. Otherwise, then the error may be reported
1591 wakaba 1.82 to the user.</p>
1592    
1593 wakaba 1.104 <p>The <span>task source</span> for the tasks mentioned above is the
1594     <span>DOM manipulation task source</span>.</p>
1595    
1596 wakaba 1.130 <hr><pre class=idl>interface <dfn id=errorevent>ErrorEvent</dfn> : Event {
1597 wakaba 1.109 readonly attribute DOMString <a href=#dom-errorevent-message title=dom-ErrorEvent-message>message</a>;
1598     readonly attribute DOMString <a href=#dom-errorevent-filename title=dom-ErrorEvent-filename>filename</a>;
1599 wakaba 1.82 readonly attribute unsigned long <a href=#dom-errorevent-lineno title=dom-ErrorEvent-lineno>lineno</a>;
1600 wakaba 1.109 void <a href=#dom-errorevent-initerrorevent title=dom-ErrorEvent-initErrorEvent>initErrorEvent</a>(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in DOMString messageArg, in DOMString filenameArg, in unsigned long linenoArg);
1601 wakaba 1.82 };</pre>
1602    
1603     <p>The <dfn id=dom-errorevent-initerrorevent title=dom-ErrorEvent-initErrorEvent><code>initErrorEvent()</code></dfn>
1604 wakaba 1.175 method must initialize the event in a manner analogous to the
1605     similarly-named method in the DOM Events interfaces. <a href=#refsDOMEVENTS>[DOMEVENTS]</a></p>
1606 wakaba 1.82
1607     <p>The <dfn id=dom-errorevent-message title=dom-ErrorEvent-message><code>message</code></dfn>
1608     attribute represents the error message.</p>
1609    
1610     <p>The <dfn id=dom-errorevent-filename title=dom-ErrorEvent-filename><code>filename</code></dfn>
1611     attribute represents the <span>absolute URL</span> of the script in
1612 wakaba 1.91 which the error originally occurred.</p>
1613 wakaba 1.82
1614     <p>The <dfn id=dom-errorevent-lineno title=dom-ErrorEvent-lineno><code>lineno</code></dfn>
1615 wakaba 1.91 attribute represents the line number where the error occurred in the
1616 wakaba 1.82 script.</p>
1617    
1618    
1619    
1620 wakaba 1.172 <h3 id=creating-workers><span class=secno>4.7 </span>Creating workers</h3>
1621 wakaba 1.82
1622 wakaba 1.172 <h4 id=the-abstractworker-abstract-interface><span class=secno>4.7.1 </span>The <code><a href=#abstractworker>AbstractWorker</a></code> abstract interface</h4>
1623 wakaba 1.82
1624 wakaba 1.179 <pre class=idl>[Supplemental, NoInterfaceObject]
1625     interface <dfn id=abstractworker>AbstractWorker</dfn> {
1626 wakaba 1.108 attribute <span>Function</span> <a href=#handler-abstractworker-onerror title=handler-AbstractWorker-onerror>onerror</a>;
1627     <!-- v2-onclose attribute <span>Function</span> <span title="handler-AbstractWorker-onclose">onclose</span>; -->
1628 wakaba 1.155 };
1629     <a href=#abstractworker>AbstractWorker</a> implements <span>EventTarget</span>;</pre>
1630 wakaba 1.82
1631 wakaba 1.162 <p>The following are the <span>event handlers</span> (and their
1632     corresponding <span title="event handler event type">event handler
1633     event types</span>) that must be supported, as IDL attributes, by
1634     objects implementing the <code><a href=#abstractworker>AbstractWorker</a></code> interface:</p>
1635 wakaba 1.82
1636 wakaba 1.162 <table><thead><tr><th><span title="event handlers">Event handler</span> <th><span>Event handler event type</span>
1637 wakaba 1.130 <tbody><tr><td><dfn id=handler-abstractworker-onerror title=handler-AbstractWorker-onerror><code>onerror</code></dfn> <td> <code title=event-error>error</code>
1638 wakaba 1.82 <!-- v2-onclose <tr><td><dfn title="handler-AbstractWorker-onclose"><code>onclose</code></dfn> <td> <code title="event-close">close</code> -->
1639 wakaba 1.172 </table><h4 id=dedicated-workers-and-the-worker-interface><span class=secno>4.7.2 </span>Dedicated workers and the <code><a href=#worker>Worker</a></code> interface</h4>
1640 wakaba 1.82
1641     <pre class=idl>[<a href=#dom-worker title=dom-Worker>Constructor</a>(in DOMString scriptURL)]
1642     interface <dfn id=worker>Worker</dfn> : <a href=#abstractworker>AbstractWorker</a> {
1643     void <a href=#dom-worker-terminate title=dom-Worker-terminate>terminate</a>();
1644    
1645 wakaba 1.159 void <a href=#dom-worker-postmessage title=dom-Worker-postMessage>postMessage</a>(in any message, in optional <span>MessagePortArray</span> ports);<!--
1646 wakaba 1.82 <span>MessagePort</span> <span title="dom-Worker-startConversation">startConversation</span>(in any message);-->
1647 wakaba 1.108 attribute <span>Function</span> <a href=#handler-worker-onmessage title=handler-Worker-onmessage>onmessage</a>;
1648 wakaba 1.82 };</pre>
1649    
1650     <p>The <dfn id=dom-worker-terminate title=dom-Worker-terminate><code>terminate()</code></dfn> method,
1651     when invoked, must cause the "<a href=#terminate-a-worker>terminate a worker</a>"
1652     algorithm to be run on the worker with with the object is
1653     associated.</p>
1654    
1655     <p><code><a href=#worker>Worker</a></code> objects act as if they had an implicit
1656     <code>MessagePort</code> associated with them. This port is part of
1657     a channel that is set up when the worker is created, but it is not
1658     exposed. This object must never be garbage collected before the
1659     <code><a href=#worker>Worker</a></code> object.</p>
1660    
1661     <p>All messages received by that port must immediately be retargeted
1662     at the <code><a href=#worker>Worker</a></code> object.</p>
1663    
1664     <p>The <dfn id=dom-worker-postmessage title=dom-Worker-postMessage><code>postMessage()</code></dfn><!--
1665     and <dfn
1666     title="dom-Worker-startConversation"><code>startConversation()</code></dfn>-->
1667     method<!--s (startConversation)--> on <code><a href=#worker>Worker</a></code> objects
1668     must act as if, when invoked, it<!--/they (startConversation)-->
1669     immediately invoked the method of the same name on the port, with
1670     the same arguments, and returned the same return value.</p>
1671    
1672 wakaba 1.162 <p>The following are the <span>event handlers</span> (and their
1673     corresponding <span title="event handler event type">event handler
1674     event types</span>) that must be supported, as IDL attributes, by
1675     objects implementing the <code><a href=#worker>Worker</a></code> interface:</p>
1676 wakaba 1.82
1677 wakaba 1.162 <table><thead><tr><th><span title="event handlers">Event handler</span> <th><span>Event handler event type</span>
1678 wakaba 1.130 <tbody><tr><td><dfn id=handler-worker-onmessage title=handler-Worker-onmessage><code>onmessage</code></dfn> <td> <code title=event-message>message</code>
1679     </table><hr><p>When the <dfn id=dom-worker title=dom-Worker><code>Worker(<var title="">scriptURL</var>)</code></dfn> constructor is invoked, the
1680 wakaba 1.82 user agent must run the following steps:</p>
1681    
1682 wakaba 1.181 <ol><li><p><span title="resolve a url">Resolve</span> the <var title="">scriptURL</var> argument relative to the <span>entry
1683 wakaba 1.92 script</span>'s <span title="script's base URL">base URL</span>,
1684     when the method is invoked.</li>
1685 wakaba 1.82
1686     <li><p>If this fails, throw a <code>SYNTAX_ERR</code>
1687     exception.</li>
1688    
1689 wakaba 1.152 <li>
1690    
1691     <p>If the <span>origin</span> of the resulting <span>absolute
1692     URL</span> is not the <span title="same origin">same</span> as the
1693 wakaba 1.181 origin of the <span>entry script</span>, then throw a
1694 wakaba 1.172 <code>SECURITY_ERR</code> exception.</p>
1695 wakaba 1.152
1696     <p class=note>Thus, scripts must be external files with the same
1697     scheme as the original page: you can't load a script from a <code title="">data:</code> URL or <code title="">javascript:</code>
1698     URL, and a <code>https:</code> page couldn't start workers using
1699     scripts with <code>http:</code> URLs.</p>
1700    
1701     </li>
1702 wakaba 1.82
1703 wakaba 1.172 <li><p>Create a new <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code>
1704     object. Let <var title="">worker global scope</var> be this new
1705     object.</li>
1706 wakaba 1.82
1707     <li><p>Create a new <code><a href=#worker>Worker</a></code> object, associated with
1708     <var title="">worker global scope</var>. Let <var title="">worker</var> be this new object.</li>
1709    
1710 wakaba 1.172 <li><p><span>Create a new <code>MessagePort</code> object</span>
1711 wakaba 1.176 owned by the <span title="script's global object">global
1712     object</span> of the <span title=concept-script>script</span> that
1713 wakaba 1.172 invoked the constructor. Let this be the <var title="">outside
1714 wakaba 1.82 port</var>.</li>
1715    
1716     <li><p>Associate the <var title="">outside port</var> with <var title="">worker</var>.</li>
1717    
1718 wakaba 1.172 <li><p><span>Create a new <code>MessagePort</code> object</span>
1719     owned by <var title="">worker global scope</var>. Let <var title="">inside port</var> be this new object.</li>
1720 wakaba 1.82
1721     <li><p>Associate <var title="">inside port</var> with <var title="">worker global scope</var>.</li>
1722    
1723     <li><p><span>Entangle</span> <var title="">outside port</var> and
1724     <var title="">inside port</var>.</li>
1725    
1726     <li><p>Return <var title="">worker</var>, and run the following
1727     steps asynchronously.</li>
1728    
1729 wakaba 1.178 <!-- (this is done by the "run a worker" algorithm)
1730 wakaba 1.82 <li><p>Enable <var title="">inside port</var>'s <span>port message
1731 wakaba 1.178 queue</span>.</p></li>
1732     -->
1733 wakaba 1.82
1734     <li><p>Enable <var title="">outside port</var>'s <span>port message
1735     queue</span>.</li>
1736    
1737     <li>
1738    
1739     <p>Let <var title="">docs</var> be the <a href=#list-of-relevant-document-objects-to-add>list of relevant
1740 wakaba 1.176 <code>Document</code> objects to add</a> given the <span title="script's global object">global object</span> of the <span title=concept-script>script</span> that invoked the
1741 wakaba 1.82 constructor.</p>
1742    
1743     </li>
1744    
1745     <li>
1746    
1747     <p><a href="#add-a-document-to-the-worker's-documents" title="add a document to the worker's documents">Add to
1748     <var title="">worker global scope</var>'s list of <span>the
1749     worker's <code>Document</code>s</span></a> the
1750     <code>Document</code> objects in <var title="">docs</var>.</p>
1751    
1752     </li>
1753    
1754     <li>
1755    
1756 wakaba 1.176 <p>If the <span title="script's global object">global object</span>
1757 wakaba 1.82 of the <span title=concept-script>script</span> that invoked the
1758     constructor is a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object (i.e. we
1759     are creating a nested worker), add <var title="">worker global
1760     scope</var> to the list of <a href="#the-worker's-workers">the worker's workers</a> of the
1761 wakaba 1.176 <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object that is the <span title="script's global object">global object</span> of the <span title=concept-script>script</span> that invoked the
1762 wakaba 1.82 constructor.</p>
1763    
1764     </li>
1765    
1766     <li>
1767    
1768     <p><a href=#run-a-worker>Run a worker</a> for the resulting <span>absolute
1769 wakaba 1.176 URL</span>, with the <span>script's browsing context</span> of the
1770 wakaba 1.82 script that invoked the method as the <var title="">owner browsing
1771 wakaba 1.181 context</var>, with the <span>origin</span> of the <span>entry
1772 wakaba 1.162 script</span> as the <var title="">owner origin</var>, and with
1773     <var title="">worker global scope</var> as the global scope.</p>
1774 wakaba 1.82
1775     </li>
1776    
1777 wakaba 1.130 </ol><p>This constructor must be visible when the <span>script's global
1778 wakaba 1.176 object</span> is either a <code>Window</code> object or an object
1779 wakaba 1.95 implementing the <code><a href=#workerutils>WorkerUtils</a></code> interface.</p>
1780    
1781    
1782 wakaba 1.172 <h4 id=shared-workers-and-the-sharedworker-interface><span class=secno>4.7.3 </span>Shared workers and the <code><a href=#sharedworker>SharedWorker</a></code> interface</h4>
1783 wakaba 1.82
1784 wakaba 1.159 <pre class=idl>[<a href=#dom-sharedworker title=dom-SharedWorker>Constructor</a>(in DOMString scriptURL, in optional DOMString name)]
1785 wakaba 1.82 interface <dfn id=sharedworker>SharedWorker</dfn> : <a href=#abstractworker>AbstractWorker</a> {
1786     readonly attribute <span>MessagePort</span> <a href=#dom-sharedworker-port title=dom-SharedWorker-port>port</a>;
1787     };</pre>
1788    
1789     <p>The <dfn id=dom-sharedworker-port title=dom-SharedWorker-port><code>port</code></dfn>
1790     attribute must return the value it was assigned by the object's
1791     constructor. It represents the <code>MessagePort</code> for
1792     communicating with the shared worker.</p>
1793    
1794     <p>When the <dfn id=dom-sharedworker title=dom-SharedWorker><code>SharedWorker(<var title="">scriptURL</var>, <var title="">name</var>)</code></dfn>
1795     constructor is invoked, the user agent must run the following
1796     steps:</p>
1797    
1798 wakaba 1.130 <ol><li><p><span title="resolve a url">Resolve</span> the <var title="">scriptURL</var> argument.</li>
1799 wakaba 1.82
1800     <li><p>If this fails, throw a <code>SYNTAX_ERR</code>
1801     exception.</li>
1802    
1803 wakaba 1.139 <li><p>Otherwise, let <var title="">scriptURL</var> be the
1804     resulting <span>absolute URL</span>.</li>
1805    
1806     <li><p>Let <var title="">name</var> be the value of the second
1807 wakaba 1.144 argument, or the empty string if the second argument was
1808     omitted.</li>
1809 wakaba 1.139
1810 wakaba 1.152 <li>
1811    
1812     <p>If the <span>origin</span> of <var title="">scriptURL</var> is
1813     not the <span title="same origin">same</span> as the origin of the
1814 wakaba 1.181 <span>entry script</span>, then throw a <code>SECURITY_ERR</code>
1815 wakaba 1.172 exception.</p>
1816 wakaba 1.152
1817     <p class=note>Thus, scripts must be external files with the same
1818     scheme as the original page: you can't load a script from a <code title="">data:</code> URL or <code title="">javascript:</code>
1819     URL, and a <code>https:</code> page couldn't start workers using
1820     scripts with <code>http:</code> URLs.</p>
1821    
1822     </li>
1823 wakaba 1.82
1824     <li>
1825    
1826     <p>Let <var title="">docs</var> be the <a href=#list-of-relevant-document-objects-to-add>list of relevant
1827 wakaba 1.176 <code>Document</code> objects to add</a> given the <span title="script's global object">global object</span> of the <span title=concept-script>script</span> that invoked the
1828 wakaba 1.82 constructor.</p>
1829    
1830     </li>
1831    
1832     <li>
1833    
1834     <p>Execute the following substeps atomically:</p>
1835    
1836 wakaba 1.130 <ol><li><p>Create a new <code><a href=#sharedworker>SharedWorker</a></code> object, which will
1837 wakaba 1.82 shortly be associated with a <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code>
1838     object. Let this <code><a href=#sharedworker>SharedWorker</a></code> object be <var title="">worker</var>.</li>
1839    
1840 wakaba 1.172 <li><p><span>Create a new <code>MessagePort</code> object</span>
1841 wakaba 1.176 owned by the <span title="script's global object">global
1842     object</span> of the script that invoked the method. Let this be
1843 wakaba 1.82 the <var title="">outside port</var>.</li>
1844    
1845     <li><p>Assign <var title="">outside port</var> to the <code title=dom-SharedWorker-port><a href=#dom-sharedworker-port>port</a></code> attribute of <var title="">worker</var>.</li>
1846    
1847 wakaba 1.144 <li><p>Let <var title="">worker global scope</var> be
1848     null.</li>
1849    
1850     <li><p>If <var title="">name</var> is not the empty string and
1851     there exists a <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object whose
1852     <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag
1853     is false, whose <code title=dom-WorkerGlobalScope-name>name</code> attribute is
1854     exactly equal to <var title="">name</var>, and whose <code title=dom-WorkerGlobalScope-location><a href=#dom-workerglobalscope-location>location</a></code> attribute
1855     represents an <span>absolute URL</span> with the <span>same
1856     origin</span> as <var title="">scriptURL</var>, then let <var title="">worker global scope</var> be that
1857     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object.</li>
1858    
1859     <li><p>Otherwise, if <var title="">name</var> is the empty string
1860     and there exists a <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object
1861     whose <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a>
1862     flag is false, and whose <code title=dom-WorkerGlobalScope-location><a href=#dom-workerglobalscope-location>location</a></code> attribute
1863     is exactly equal to <var title="">scriptURL</var>, then let <var title="">worker global scope</var> be that
1864     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object.</li>
1865    
1866 wakaba 1.82 <li>
1867    
1868 wakaba 1.144 <p>If <var title="">worker global scope</var> is not null, then
1869     run these steps:</p>
1870 wakaba 1.82
1871 wakaba 1.144 <ol><li><p>If <var title="">worker global scope</var>'s <code title=dom-WorkerGlobalScope-location><a href=#dom-workerglobalscope-location>location</a></code>
1872 wakaba 1.82 attribute represents an <span>absolute URL</span> that is not
1873 wakaba 1.139 exactly equal to <var title="">scriptURL</var>, then throw a
1874     <code>URL_MISMATCH_ERR</code> exception and abort all these
1875     steps.</li>
1876 wakaba 1.82
1877     <li><p>Associate <var title="">worker</var> with <var title="">worker global scope</var>.</li>
1878    
1879 wakaba 1.172 <li><p><span>Create a new <code>MessagePort</code>
1880     object</span> owned by <var title="">worker global
1881     scope</var>. Let this be the <var title="">inside
1882     port</var>.</li>
1883 wakaba 1.82
1884     <li><p><span>Entangle</span> <var title="">outside port</var>
1885     and <var title="">inside port</var>.</li>
1886    
1887     <li><p>Return <var title="">worker</var> and perform the next
1888     step asynchronously.</li>
1889    
1890     <li><p>Create an event that uses the <code>MessageEvent</code>
1891     interface, with the name <code title=event-connect>connect</code>, which does not bubble, is
1892     not cancelable, has no default action, has a <code title=dom-MessageEvent-data>data</code> attribute whose value
1893     is the empty string and has a <code title=dom-MessageEvent-ports>ports</code> attribute whose
1894     value is an array containing only the newly created port, and
1895     <span>queue a task</span> to dispatch the event at <var title="">worker global scope</var>.</li>
1896    
1897     <li>
1898    
1899     <p><a href="#add-a-document-to-the-worker's-documents" title="add a document to the worker's documents">Add to
1900     <var title="">worker global scope</var>'s list of <span>the
1901     worker's <code>Document</code>s</span></a> the
1902     <code>Document</code> objects in <var title="">docs</var>.</p>
1903    
1904     </li>
1905    
1906     <li>
1907    
1908 wakaba 1.176 <p>If the <span title="script's global object">global
1909     object</span> of the <span title=concept-script>script</span>
1910 wakaba 1.82 that invoked the constructor is a
1911     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object, add <var title="">worker global scope</var> to the list of <a href="#the-worker's-workers">the
1912     worker's workers</a> of the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>
1913 wakaba 1.176 object that is the <span title="script's global object">global
1914     object</span> of the <span title=concept-script>script</span>
1915 wakaba 1.82 that invoked the constructor.</p>
1916    
1917     </li>
1918    
1919     <li><p>Abort all these steps.</li>
1920    
1921 wakaba 1.130 </ol></li>
1922 wakaba 1.82
1923 wakaba 1.172 <li><p>Create a new <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code>
1924     object. Let <var title="">worker global scope</var> be this new
1925     object.</li>
1926 wakaba 1.82
1927     <li><p>Associate <var title="">worker</var> with <var title="">worker global scope</var>.</li>
1928    
1929     <li><p>Set the <code title=dom-SharedWorkerGlobalScope-name><a href=#dom-sharedworkerglobalscope-name>name</a></code> attribute of
1930     <var title="">worker global scope</var> to <var title="">name</var>.</li>
1931    
1932 wakaba 1.172 <li><p><span>Create a new <code>MessagePort</code> object</span>
1933 wakaba 1.82 owned by <var title="">worker global scope</var>. Let <var title="">inside port</var> be this new object.</li>
1934    
1935     <li><p><span>Entangle</span> <var title="">outside port</var> and
1936     <var title="">inside port</var>.</li>
1937    
1938 wakaba 1.130 </ol></li>
1939 wakaba 1.82
1940     <li><p>Return <var title="">worker</var> and perform the remaining
1941     steps asynchronously.</li>
1942    
1943     <li><p>Create an event that uses the <code>MessageEvent</code>
1944     interface, with the name <code title=event-connect>connect</code>, which does not bubble, is not
1945     cancelable, has no default action, has a <code title=dom-MessageEvent-data>data</code> attribute whose value is
1946     the empty string and has a <code title=dom-MessageEvent-ports>ports</code> attribute whose value
1947     is an array containing only the newly created port, and <span>queue
1948     a task</span> to dispatch the event at <var title="">worker global
1949     scope</var>.</li>
1950    
1951     <li>
1952    
1953     <p><a href="#add-a-document-to-the-worker's-documents" title="add a document to the worker's documents">Add to
1954     <var title="">worker global scope</var>'s list of <span>the
1955     worker's <code>Document</code>s</span></a> the
1956     <code>Document</code> objects in <var title="">docs</var>.</p>
1957    
1958     </li>
1959    
1960     <li>
1961    
1962 wakaba 1.176 <p>If the <span title="script's global object">global object</span>
1963 wakaba 1.82 of the <span title=concept-script>script</span> that invoked the
1964     constructor is a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object, add <var title="">worker global scope</var> to the list of <a href="#the-worker's-workers">the
1965     worker's workers</a> of the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>
1966 wakaba 1.176 object that is the <span title="script's global object">global
1967     object</span> of the <span title=concept-script>script</span>
1968 wakaba 1.82 that invoked the constructor.</p>
1969    
1970     </li>
1971    
1972     <li>
1973    
1974 wakaba 1.139 <p><a href=#run-a-worker>Run a worker</a> for <var title="">scriptURL</var>,
1975 wakaba 1.176 with the <span>script's browsing context</span> of the script that
1976 wakaba 1.139 invoked the method as the <var title="">owner browsing
1977 wakaba 1.181 context</var>, with the <span>origin</span> of the <span>entry
1978 wakaba 1.162 script</span> as the <var title="">owner origin</var>, and with
1979     <var title="">worker global scope</var> as the global scope.</p>
1980 wakaba 1.82
1981     </li>
1982    
1983 wakaba 1.130 </ol><p>This constructor must be visible when the <span>script's global
1984 wakaba 1.176 object</span> is either a <code>Window</code> object or an object
1985 wakaba 1.95 implementing the <code><a href=#workerutils>WorkerUtils</a></code> interface.</p>
1986 wakaba 1.104
1987     <p>The <span>task source</span> for the tasks mentioned above is the
1988     <span>DOM manipulation task source</span>.</p>
1989 wakaba 1.95
1990    
1991    
1992 wakaba 1.110 <h2 id=apis-available-to-workers><span class=secno>5 </span>APIs available to workers</h2>
1993 wakaba 1.82
1994 wakaba 1.125 <pre class=idl>[Supplemental, NoInterfaceObject]
1995     interface <dfn id=workerutils>WorkerUtils</dfn> {
1996     void <a href=#dom-workerglobalscope-importscripts title=dom-WorkerGlobalScope-importScripts>importScripts</a>(in DOMString... urls);
1997 wakaba 1.179 readonly attribute <a href=#workernavigator>WorkerNavigator</a> <a href=#dom-worker-navigator title=dom-worker-navigator>navigator</a>;
1998 wakaba 1.125 };
1999 wakaba 1.172 <a href=#workerutils>WorkerUtils</a> implements <span>WindowTimers</span>;</pre>
2000 wakaba 1.82
2001 wakaba 1.155 <p>The DOM APIs (<code>Node</code> objects, <code>Document</code>
2002 wakaba 1.82 objects, etc) are not available to workers in this version of this
2003     specification.</p>
2004    
2005    
2006 wakaba 1.110 <h3 id=importing-scripts-and-libraries><span class=secno>5.1 </span>Importing scripts and libraries</h3>
2007 wakaba 1.82
2008     <p>When a script invokes the <dfn id=dom-workerglobalscope-importscripts title=dom-WorkerGlobalScope-importScripts><code>importScripts(<var title="">urls</var>)</code></dfn> method on a
2009     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object, the user agent must run the
2010     following steps:</p>
2011    
2012 wakaba 1.130 <ol><li><p>If there are no arguments, return without doing
2013 wakaba 1.82 anything. Abort these steps.</li>
2014    
2015     <li><p><span title="resolve a url">Resolve</span> each
2016     argument.</li>
2017    
2018     <li><p>If any fail, throw a <code>SYNTAX_ERR</code>
2019     exception.</li>
2020    
2021     <!--
2022     <li><p>If any of the resulting <span title="absolute URL">absolute
2023     URLs</span> have an <span>origin</span> that is not the <span
2024     title="same origin">same</span> as the origin of the script that
2025 wakaba 1.172 invoked the method, then throw a <code>SECURITY_ERR</code>
2026     exception.</p></li>
2027 wakaba 1.82 -->
2028    
2029     <li>
2030    
2031     <p>Attempt to <span>fetch</span> each resource identified by the
2032 wakaba 1.176 resulting <span title="absolute URL">absolute URLs</span>, from
2033 wakaba 1.181 the <span>entry script</span>'s <span>origin</span>.</p> <!-- not
2034 wakaba 1.162 http-origin privacy sensitive -->
2035 wakaba 1.82
2036     </li>
2037    
2038     <li>
2039    
2040     <p>For each argument in turn, in the order given, starting with
2041     the first one, run these substeps:</p>
2042    
2043 wakaba 1.130 <ol><li>
2044 wakaba 1.82
2045     <p>Wait for the fetching attempt for the corresponding resource
2046     to complete.</p>
2047    
2048     <p>If the fetching attempt failed, throw a
2049     <code>NETWORK_ERR</code> exception and abort all these
2050     steps.</p>
2051    
2052 wakaba 1.172 <p>If the attempt succeeds, then convert the script resource to
2053     Unicode by assuming it was encoded as UTF-8, to obtain its <var title="">source</var>.</p>
2054 wakaba 1.82
2055     <p>Let <var title="">language</var> be JavaScript.</p>
2056    
2057     <p class=note>As with the worker's script, the script here is
2058     always assumed to be JavaScript, regardless of the MIME
2059 wakaba 1.154 type.</p>
2060 wakaba 1.82
2061     </li>
2062    
2063     <li>
2064    
2065     <p><span>Create a script</span>, using <var title="">source</var> as the script source and <var title="">language</var> as the scripting language, using the
2066 wakaba 1.174 same global object, browsing context, URL character encoding,
2067     base URL, and script group as the <span title=concept-script>script</span> that was created by the
2068 wakaba 1.82 worker's <a href=#run-a-worker>run a worker</a> algorithm.</p>
2069    
2070     <p>Let the newly created <span title=concept-script>script</span> run until it either
2071     returns, fails to parse, fails to catch an exception, or gets
2072     prematurely aborted by the "<a href=#kill-a-worker>kill a worker</a>" or
2073     "<a href=#terminate-a-worker>terminate a worker</a>" algorithms defined above.</p>
2074    
2075 wakaba 1.178 <p>If it failed to parse, then throw an ECMAScript
2076     <code>SyntaxError</code> exception and abort all these
2077     steps. <a href=#refsECMA262>[ECMA262]</a></p>
2078 wakaba 1.82
2079     <p>If an exception was raised or if the script was prematurely
2080     aborted, then abort all these steps, letting the exception or
2081     aborting continue to be processed by the script that called the
2082     <code title=dom-WorkerGlobalScope-importScripts><a href=#dom-workerglobalscope-importscripts>importScripts()</a></code>
2083     method.</p>
2084    
2085     <p>If the "<a href=#kill-a-worker>kill a worker</a>" or "<a href=#terminate-a-worker>terminate a
2086     worker</a>" algorithms abort the script then abort all these
2087     steps.</p>
2088    
2089     </li>
2090    
2091 wakaba 1.130 </ol></li>
2092 wakaba 1.82
2093 wakaba 1.179 </ol><h3 id=the-workernavigator-object><span class=secno>5.2 </span>The <code><a href=#workernavigator>WorkerNavigator</a></code> object</h3>
2094 wakaba 1.82
2095     <p>The <dfn id=dom-worker-navigator title=dom-worker-navigator><code>navigator</code></dfn> attribute
2096     of the <code><a href=#workerutils>WorkerUtils</a></code> interface must return an instance of
2097 wakaba 1.179 the <code><a href=#workernavigator>WorkerNavigator</a></code> interface, which represents the
2098     identity and state of the user agent (the client):</p>
2099    
2100     <pre class=idl>interface <dfn id=workernavigator>WorkerNavigator</dfn> {};
2101     <a href=#workernavigator>WorkerNavigator</a> implements <span>NavigatorID</span>;
2102     <a href=#workernavigator>WorkerNavigator</a> implements <span>NavigatorOnLine</span>;</pre>
2103    
2104     <p>Objects implementing the <code><a href=#workernavigator>WorkerNavigator</a></code> interface
2105     also implement the <code>NavigatorID</code> and
2106     <code>NavigatorOnLine</code> interfaces.
2107 wakaba 1.178
2108     <a href=#refsHTML5>[HTML5]</a>
2109    
2110     </p>
2111 wakaba 1.82
2112 wakaba 1.179 <p>This <code><a href=#workernavigator>WorkerNavigator</a></code> interface must not exist if the
2113     interface's <span>relevant namespace object</span> is a
2114     <code>Window</code> object. <a href=#refsWEBIDL>[WEBIDL]</a></p>
2115 wakaba 1.82
2116    
2117    
2118 wakaba 1.110 <h3 id=apis-defined-in-other-specifications><span class=secno>5.3 </span>APIs defined in other specifications</h3>
2119 wakaba 1.82
2120     <p>The <code title=dom-opendatabase>openDatabase()</code> and
2121     <code title=dom-opendatabase-sync>openDatabaseSync()</code>
2122 wakaba 1.178 methods are defined in the Web SQL Database specification. <a href=#refsWEBSQL>[WEBSQL]</a></p>
2123 wakaba 1.82
2124    
2125    
2126 wakaba 1.110 <h3 id=interface-objects-and-constructors><span class=secno>5.4 </span>Interface objects and constructors</h3>
2127 wakaba 1.82
2128     <p>There must be no interface objects and constructors available in
2129 wakaba 1.176 the global scope of scripts whose <span>script's global
2130     object</span> is a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object except for
2131 wakaba 1.82 the following:</p>
2132    
2133 wakaba 1.130 <ul><li><p><code>XMLHttpRequest</code> and all interface objects and
2134 wakaba 1.82 constructors defined by the XMLHttpRequest specifications, except
2135     that the <span>document response entity body</span> must always be
2136 wakaba 1.141 null. The <span><code>XMLHttpRequest</code> base URL</span> is the
2137     <span>script's base URL</span>; the
2138     <span><code>XMLHttpRequest</code> origin</span> is the script's
2139     <span>origin</span>. <a href=#refsXHR>[XHR]</a></li>
2140 wakaba 1.82
2141 wakaba 1.178 <li><p>The interface objects and constructors defined by this
2142     specification.</li>
2143 wakaba 1.82
2144 wakaba 1.178 <li><p>Constructors defined by specifications that explicitly say
2145     that they should be visible when the <span>script's global
2146     object</span> is a <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code>, a
2147     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code>, or an object implementing the
2148     <code><a href=#workerutils>WorkerUtils</a></code> interface; the interfaces of any objects
2149     with such constructors; and the interfaces of any objects made
2150     accessible through APIs exposed by those constructors or made
2151     accessible through interfaces to be implemented by any objects that
2152     are themselves accessible to scripts whose <span>script's global
2153     object</span> implements the <code><a href=#workerutils>WorkerUtils</a></code>
2154     interface.</li>
2155    
2156     </ul><p class=note>These requirements do not override the requirements
2157     defined by the Web IDL specification, in particular concerning the
2158     visibility of interfaces annotated with the <code title="">[NoInterfaceObject]</code> extended attribute.</p>
2159 wakaba 1.82
2160    
2161 wakaba 1.178 <h3 id=worker-locations><span class=secno>5.5 </span>Worker locations</h3>
2162 wakaba 1.82
2163     <pre class=idl>interface <dfn id=workerlocation>WorkerLocation</dfn> {
2164     readonly attribute DOMString <a href=#dom-workerlocation-href title=dom-WorkerLocation-href>href</a>;
2165     readonly attribute DOMString <a href=#dom-workerlocation-protocol title=dom-WorkerLocation-protocol>protocol</a>;
2166     readonly attribute DOMString <a href=#dom-workerlocation-host title=dom-WorkerLocation-host>host</a>;
2167     readonly attribute DOMString <a href=#dom-workerlocation-hostname title=dom-WorkerLocation-hostname>hostname</a>;
2168     readonly attribute DOMString <a href=#dom-workerlocation-port title=dom-WorkerLocation-port>port</a>;
2169     readonly attribute DOMString <a href=#dom-workerlocation-pathname title=dom-WorkerLocation-pathname>pathname</a>;
2170     readonly attribute DOMString <a href=#dom-workerlocation-search title=dom-WorkerLocation-search>search</a>;
2171     readonly attribute DOMString <a href=#dom-workerlocation-hash title=dom-WorkerLocation-hash>hash</a>;
2172     };</pre>
2173    
2174     <p>A <code><a href=#workerlocation>WorkerLocation</a></code> object represents an <span>absolute
2175     URL</span> set at its creation.</p>
2176    
2177     <p>The <dfn id=dom-workerlocation-href title=dom-WorkerLocation-href><code>href</code></dfn>
2178     attribute must return the <span>absolute URL</span> that the object
2179     represents.</p>
2180    
2181     <p>The <code><a href=#workerlocation>WorkerLocation</a></code> interface also has the complement
2182 wakaba 1.143 of <span>URL decomposition IDL attributes</span>, <dfn id=dom-workerlocation-protocol title=dom-WorkerLocation-protocol><code>protocol</code></dfn>,
2183 wakaba 1.82 <dfn id=dom-workerlocation-host title=dom-WorkerLocation-host><code>host</code></dfn>, <dfn id=dom-workerlocation-port title=dom-WorkerLocation-port><code>port</code></dfn>, <dfn id=dom-workerlocation-hostname title=dom-WorkerLocation-hostname><code>hostname</code></dfn>,
2184     <dfn id=dom-workerlocation-pathname title=dom-WorkerLocation-pathname><code>pathname</code></dfn>,
2185     <dfn id=dom-workerlocation-search title=dom-WorkerLocation-search><code>search</code></dfn>,
2186     and <dfn id=dom-workerlocation-hash title=dom-WorkerLocation-hash><code>hash</code></dfn>. These must
2187 wakaba 1.143 follow the rules given for URL decomposition IDL attributes, with the
2188 wakaba 1.82 <span title=concept-uda-input>input</span> being the
2189     <span>absolute URL</span> that the object represents (same as the
2190     <code title=dom-WorkerLocation-href><a href=#dom-workerlocation-href>href</a></code> attribute), and
2191     the <span title=concept-uda-setter>common setter action</span>
2192 wakaba 1.178 being a no-op, since the attributes are defined to be readonly.
2193    
2194     <a href=#refsHTML5>[HTML5]</a>
2195    
2196     </p>
2197 wakaba 1.179
2198     <p>The <code><a href=#workerlocation>WorkerLocation</a></code> interface must not exist if the
2199     interface's <span>relevant namespace object</span> is a
2200     <code>Window</code> object. <a href=#refsWEBIDL>[WEBIDL]</a></p>
2201    
2202 wakaba 1.147
2203 wakaba 1.166 <!--START vCard--><!--START vEvent-->
2204 wakaba 1.82
2205 wakaba 1.134 <h2 class=no-num id=references>References</h2><!--REFS-->
2206 wakaba 1.82
2207 wakaba 1.166 <!--END vCard--><!--END vEvent-->
2208 wakaba 1.128 <p>All references are normative unless marked "Non-normative".</p>
2209 wakaba 1.166 <!--START vCard--><!--START vEvent-->
2210 wakaba 1.128
2211 wakaba 1.182 <!-- XXX really should remove dates and version numbers from these references once and for all -->
2212    
2213 wakaba 1.130 <dl><dt id=refsDOMCORE>[DOMCORE]</dt>
2214 wakaba 1.129 <dd><cite><a href=http://www.w3.org/TR/DOM-Level-3-Core/>Document
2215     Object Model (DOM) Level 3 Core Specification</a></cite>, A. Le
2216     Hors, P. Le Hegaret, L. Wood, G. Nicol, J. Robie, M. Champion,
2217     S. Byrnes. W3C, April 2004.</dd>
2218     <!--
2219     <dd><cite><a href="http://simon.html5.org/specs/web-dom-core">Web
2220     DOM Core</a></cite>, S. Pieters. W3C, June 2009.</dd>
2221     -->
2222    
2223 wakaba 1.128 <dt id=refsDOMEVENTS>[DOMEVENTS]</dt>
2224     <!--
2225     <dd><cite><a
2226     href="http://www.w3.org/TR/DOM-Level-3-Events/">Document Object
2227     Model (DOM) Level 3 Events Specification</a></cite>,
2228     B. H&ouml;hrmann, P. Le Hegaret, T. Pixley. W3C, December
2229     2007.</dd>
2230     -->
2231     <dd><cite><a href=http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html>Document
2232     Object Model (DOM) Level 3 Events Specification</a></cite>,
2233     D. Schepers. W3C, July 2009.</dd>
2234    
2235     <dt id=refsECMA262>[ECMA262]</dt>
2236     <dd><cite><a href=http://www.ecma-international.org/publications/standards/Ecma-262.htm>ECMAScript
2237     Language Specification</a></cite>. ECMA, December 1999.</dd>
2238    
2239     <dt id=refsHTML5>[HTML5]</dt>
2240     <!--
2241 wakaba 1.142 <dd><cite><a href="http://www.w3.org/TR/html5/">HTML5</a></cite>,
2242 wakaba 1.128 I. Hickson, D. Hyatt. W3C, April 2009.</dd>
2243 wakaba 1.142 <dd><cite><a
2244     href="http://www.w3.org/html/wg/html5/">HTML5</a></cite>,
2245     I. Hickson, D. Hyatt. W3C, August 2009.</dd>
2246 wakaba 1.128 -->
2247 wakaba 1.142 <dd><cite><a href=http://www.whatwg.org/specs/web-apps/current-work/>HTML5</a></cite>,
2248     I. Hickson. WHATWG, August 2009.</dd>
2249 wakaba 1.128
2250 wakaba 1.129 <dt id=refsRFC2119>[RFC2119]</dt>
2251     <dd><cite><a href=http://www.ietf.org/rfc/rfc2119.txt>Key words for use in
2252     RFCs to Indicate Requirement Levels</a></cite>, S. Bradner. IETF, March
2253     1997.</dd>
2254    
2255 wakaba 1.178 <dt id=refsWEBSQL>[WEBSQL]</dt>
2256     <dd><cite><a href=http://dev.w3.org/html5/webdatabase/>Web SQL
2257     Database</a></cite>, I. Hickson. W3C, July 2009.</dd>
2258 wakaba 1.129
2259     <dt id=refsWEBIDL>[WEBIDL]</dt>
2260     <!--
2261     <dd><cite><a href="http://www.w3.org/TR/WebIDL/">Web
2262     IDL</a></cite>, C. McCormack. W3C, December 2008.</dd>
2263     -->
2264     <dd><cite><a href=http://dev.w3.org/2006/webapi/WebIDL/>Web
2265     IDL</a></cite>, C. McCormack. W3C, July 2009.</dd>
2266 wakaba 1.128
2267     <dt id=refsXHR>[XHR]</dt>
2268     <!--
2269     <dd><cite><a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest
2270     Object</a></cite>, A. van Kesteren. W3C, April
2271     2008.</dd>
2272     -->
2273 wakaba 1.141 <dd><cite><a href=http://dev.w3.org/2006/webapi/XMLHttpRequest-2/><code>XMLHttpRequest</code></a></cite>,
2274 wakaba 1.128 A. van Kesteren. W3C, June 2009.</dd>
2275    
2276 wakaba 1.166 </dl><!--END vCard--><!--END vEvent--><h2 class=no-num id=acknowledgements>Acknowledgements</h2> <!-- ACKS -->
2277 wakaba 1.82
2278     <p>Thanks to
2279    
2280     Aaron Boodman,
2281 wakaba 1.130 &#1040;&#1083;&#1077;&#1082;&#1089;&#1077;&#1081; &#1055;&#1088;&#1086;&#1089;&#1082;&#1091;&#1088;&#1103;&#1082;&#1086;&#1074; (Alexey Proskuryakov),
2282 wakaba 1.82 Anne van Kesteren,
2283     Ben Turner,
2284     Dmitry Titov,
2285     Drew Wilson,
2286     Jeremy Orlow,
2287     Jonas Sicking,
2288     Justin James,
2289     Kevin Hakanson,
2290     Maciej Stachowiak,
2291     Michael Nordman,
2292     Mike Smith,
2293    
2294     and
2295    
2296     Philip Taylor
2297    
2298     for their useful and substantial comments.</p>
2299    
2300     <p>Huge thanks to the whole Gears team, who pioneered this
2301     technology and whose experience has been a huge influence on this
2302     specification.</p>
2303    
2304    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24