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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24