/[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.154 - (hide annotations) (download) (as text)
Sat Sep 19 06:17:22 2009 UTC (16 years, 6 months ago) by wakaba
Branch: MAIN
Changes since 1.153: +7 -13 lines
File MIME type: text/html
make

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24