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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24