/[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.12 - (hide annotations) (download) (as text)
Wed Aug 27 06:16:52 2008 UTC (17 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.11: +643 -474 lines
File MIME type: text/html
make

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24