/[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.5 - (hide annotations) (download) (as text)
Fri Jul 18 06:15:23 2008 UTC (17 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.4: +230 -102 lines
File MIME type: text/html
*** empty log message ***

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     <body class=draft>
9     <div class=head>
10     <p><a class=logo href="http://www.whatwg.org/" rel=home><img alt=WHATWG
11     src="/images/logo"></a></p>
12    
13     <h1 id=web-workers>Web Workers</h1>
14    
15 wakaba 1.5 <h2 class="no-num no-toc" id=draft>Draft Recommendation &mdash; 18 July
16 wakaba 1.1 2008</h2>
17    
18     <p>You can take part in this work. <a
19     href="http://www.whatwg.org/mailing-list">Join the working group's
20     discussion list.</a></p>
21    
22     <p><strong>Web designers!</strong> We have a <a
23     href="http://blog.whatwg.org/faq/">FAQ</a>, a <a
24     href="http://forums.whatwg.org/">forum</a>, and a <a
25     href="http://www.whatwg.org/mailing-list#help">help mailing list</a> for
26     you!</p>
27    
28     <dl>
29     <dt>This version:
30    
31     <dd><a
32 wakaba 1.5 href="http://www.whatwg.org/specs/web-workers/current-work/">http://whatwg.org/ww</a>
33 wakaba 1.1
34     <dt>Version history:
35    
36     <dd>Twitter messages (non-editorial changes only): <a
37     href="http://twitter.com/WHATWG">http://twitter.com/WHATWG</a>
38    
39     <dd>Commit-Watchers mailing list: <a
40     href="http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org">http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org</a>
41    
42     <dd>Interactive Web interface: <a
43     href="http://html5.org/tools/web-workers-tracker">http://html5.org/tools/web-workers-tracker</a>
44    
45     <dd>Subversion interface: <a
46     href="http://svn.whatwg.org/webworkers/">http://svn.whatwg.org/webworkers/</a>
47    
48     <dt>Issues:
49    
50     <dd>To send feedback: <a
51     href="http://www.whatwg.org/mailing-list">whatwg@whatwg.org</a>
52    
53     <dd>To view and vote on feedback: <a
54     href="http://www.whatwg.org/issues/">http://www.whatwg.org/issues/</a>
55    
56     <dt>Editor:
57    
58     <dd>Ian Hickson, Google, ian@hixie.ch
59     </dl>
60    
61     <p class=copyright>&copy; Copyright 2004-2008 Apple Computer, Inc.,
62     Mozilla Foundation, and Opera Software ASA.</p>
63    
64     <p class=copyright>You are granted a license to use, reproduce and create
65     derivative works of this document.</p>
66     </div>
67    
68     <hr>
69    
70     <h2 class="no-num no-toc" id=abstract>Abstract</h2>
71    
72     <p>This specification defines an API that allows Web application authors to
73     spawn background workers running scripts in parallel to their main page.
74     This allows for thread-like operation with message-passing as the
75     coordination mechanism.
76    
77     <h2 class="no-num no-toc" id=status>Status of this document</h2>
78    
79     <p><strong>This is a work in progress!</strong> This document is changing
80     on a daily if not hourly basis in response to comments and as a general
81     part of its development process. Comments are very welcome, please send
82     them to <a href="mailto:whatwg@whatwg.org">whatwg@whatwg.org</a>. Thank
83     you.
84    
85     <p>The current focus is in developing a first draft proposal.
86    
87     <p>Implementors should be aware that this specification is not stable.
88     <strong>Implementors who are not taking part in the discussions are likely
89     to find the specification changing out from under them in incompatible
90     ways.</strong> Vendors interested in implementing this specification
91     before it eventually reaches the call for implementations should join the
92     <a href="/mailing-list">WHATWG mailing list</a> and take part in the
93     discussions.
94    
95     <p>This specification is also being produced by the <a
96     href="http://www.w3.org/html/wg">W3C HTML WG</a>. The two specifications
97     are identical from the table of contents onwards.
98    
99     <h2 class="no-num no-toc" id=contents>Table of contents</h2>
100     <!--begin-toc-->
101    
102     <ul class=toc>
103     <li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
104     <ul class=toc>
105 wakaba 1.3 <li><a href="#tutorial"><span class=secno>1.1 </span>Tutorial</a>
106 wakaba 1.1
107 wakaba 1.2 <li><a href="#requirements"><span class=secno>1.2
108     </span>Requirements</a>
109 wakaba 1.1
110 wakaba 1.3 <li><a href="#conformance"><span class=secno>1.3 </span>Conformance
111 wakaba 1.1 requirements</a>
112     <ul class=toc>
113 wakaba 1.3 <li><a href="#dependencies"><span class=secno>1.3.1
114 wakaba 1.1 </span>Dependencies</a>
115     </ul>
116    
117 wakaba 1.3 <li><a href="#terminology"><span class=secno>1.4 </span>Terminology</a>
118     </ul>
119    
120 wakaba 1.5 <li><a href="#infrastructure"><span class=secno>2.
121     </span>Infrastructure</a>
122 wakaba 1.3 <ul class=toc>
123     <li><a href="#the-windowworker"><span class=secno>2.1 </span>The
124     <code>WindowWorker</code> interface</a>
125    
126     <li><a href="#the-queue"><span class=secno>2.2 </span>The queue of
127     events</a>
128    
129 wakaba 1.4 <li><a href="#the-workers"><span class=secno>2.3 </span>The worker's
130     ports</a>
131    
132     <li><a href="#processing"><span class=secno>2.4 </span>Processing
133 wakaba 1.3 model</a>
134 wakaba 1.5
135     <li><a href="#creating"><span class=secno>2.5 </span>Creating
136     workers</a>
137 wakaba 1.3 </ul>
138    
139 wakaba 1.5 <li><a href="#apis-available"><span class=secno>3. </span>APIs available
140     to workers</a>
141 wakaba 1.1
142     <li class=no-num><a href="#references">References</a>
143    
144     <li class=no-num><a href="#acknowledgements">Acknowledgements</a>
145     </ul>
146     <!--end-toc-->
147    
148     <hr>
149    
150     <h2 id=introduction><span class=secno>1. </span>Introduction</h2>
151    
152 wakaba 1.3 <h3 id=tutorial><span class=secno>1.1 </span>Tutorial</h3>
153 wakaba 1.1
154     <p><em>This section is non-normative.</em>
155    
156 wakaba 1.3 <p class=big-issue>This section is missing.
157    
158 wakaba 1.2 <h3 id=requirements><span class=secno>1.2 </span>Requirements</h3>
159 wakaba 1.1
160     <p><em>This section is non-normative.</em>
161 wakaba 1.2
162     <p>This specification aims to address the following use cases and
163     requirements:
164    
165     <ul>
166     <li>Background workers: A Web application needs to keep its data
167     synchronised with the server, both sending updates to the server and
168     receiving updates from the server, including handling buffering of
169     updates for when the application goes offline. The code to do this would
170     ideally be independent of the UI code.
171    
172     <li>URLs: Workers should be spawned from URLs, not from strings, since
173     script rarely has access to its own source.
174    
175     <li>Message queuing: Messages sent to a worker before the worker has
176     initialised should not be lost.
177    
178     <li>Workers should have access to timers.
179    
180     <li>Workers should have access to the network.
181    
182     <li>Workers should be able to use libraries.
183    
184     <li>Implementations should not have to expose <code>Node</code> or
185     <code>Document</code> objects to workers.
186    
187     <li>Workers should not share anything with the outside world. The objects
188     representing the worker in the worker itself and in the context that
189     created the worker should be different, for instance.
190    
191     <li>Shared workers: Multiple instances of the same Web application would
192     want to keep just one connection back to the server.
193    
194     <li>Capabilities granting: It should be possible for code running in one
195     iframe to negotiate a connection to another iframe, with that connection
196     granting certain rights (e.g. adding to an address book but not reading
197     from it).
198    
199     <li>Delegation: It should be possible for one worker to spawn another
200     worker and efficiently delagate a request to that worker, without the
201     caller being aware of the delagate and without the original worker having
202     to proxy all the messages.
203    
204     <li>Workers whose parents are not longer useful should be killed. Workers
205     should be able to detect this is about to happen and exit gracefully.
206     </ul>
207 wakaba 1.1
208 wakaba 1.3 <h3 id=conformance><span class=secno>1.3 </span>Conformance requirements</h3>
209 wakaba 1.1
210     <p>All diagrams, examples, and notes in this specification are
211     non-normative, as are all sections explicitly marked non-normative.
212     Everything else in this specification is normative.
213    
214     <p>The key words "MUST", "MUST NOT", "REQUIRED", <!--"SHALL", "SHALL
215     NOT",-->
216     "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the
217     normative parts of this document are to be interpreted as described in
218     RFC2119. For readability, these words do not appear in all uppercase
219     letters in this specification. <a href="#refsRFC2119">[RFC2119]</a></p>
220     <!-- XXX but they should be
221     marked up -->
222    
223     <p>Requirements phrased in the imperative as part of algorithms (such as
224     "strip any leading space characters" or "return false and abort these
225     steps") are to be interpreted with the meaning of the key word ("must",
226     "should", "may", etc) used in introducing the algorithm.
227    
228     <p>Some conformance requirements are phrased as requirements on attributes,
229     methods or objects. Such requirements are to be interpreted as
230     requirements on user agents.
231    
232     <p>Conformance requirements phrased as algorithms or specific steps may be
233     implemented in any manner, so long as the end result is equivalent. (In
234     particular, the algorithms defined in this specification are intended to
235     be easy to follow, and not intended to be performant.)
236    
237     <p>The only conformance class defined by this specification is user agents.
238    
239     <p>User agents may impose implementation-specific limits on otherwise
240     unconstrained inputs, e.g. to prevent denial of service attacks, to guard
241     against running out of memory, or to work around platform-specific
242     limitations.
243    
244 wakaba 1.3 <h4 id=dependencies><span class=secno>1.3.1 </span>Dependencies</h4>
245 wakaba 1.1
246     <p>This specification relies on several other underlying specifications.
247    
248     <dl>
249     <dt>HTML5
250    
251     <dd>
252     <p>Many fundamental concepts from HTML5 are used by this specification.
253     <a href="#refsHTML5">[HTML5]</a></p>
254    
255     <dt>ECMAScript
256    
257     <dd>
258     <p>This specification is intended to be used with JavaScript as the
259     scripting language. <a href="#refsJS">[JS]</a></p>
260    
261     <dt>WebIDL
262    
263     <dd>
264     <p>The IDL blocks in this specification use the semantics of the WebIDL
265     specification. <a href="#refsWebIDL">[WebIDL]</a></p>
266     </dl>
267    
268 wakaba 1.3 <h3 id=terminology><span class=secno>1.4 </span>Terminology</h3>
269 wakaba 1.1
270     <p>For simplicity, terms such as <em>shown</em>, <em>displayed</em>, and
271     <em>visible</em> might sometimes be used when referring to the way a
272     document is rendered to the user. These terms are not meant to imply a
273     visual medium; they must be considered to apply to other media in
274     equivalent ways.
275    
276 wakaba 1.3 <p>The construction "a <code title="">Foo</code> object", where <code
277     title="">Foo</code> is actually an interface, is sometimes used instead of
278     the more accurate "an object implementing the interface <code
279     title="">Foo</code>".
280 wakaba 1.1
281     <p>The term DOM is used to refer to the API set made available to scripts
282     in Web applications, and does not necessarily imply the existence of an
283     actual <code>Document</code> object or of any other <code>Node</code>
284     objects as defined in the DOM Core specifications. <a
285     href="#refsDOM3CORE">[DOM3CORE]</a>
286    
287     <p>A DOM attribute is said to be <em>getting</em> when its value is being
288     retrieved (e.g. by author script), and is said to be <em>setting</em> when
289     a new value is assigned to it.
290    
291     <p>If a DOM object is said to be <dfn id=live>live</dfn>, then that means
292     that any attributes returning that object must always return the same
293     object (not a new object each time), and the attributes and methods on
294     that object must operate on the actual underlying data, not a snapshot of
295     the data.
296    
297 wakaba 1.5 <h2 id=infrastructure><span class=secno>2. </span>Infrastructure</h2>
298 wakaba 1.3
299     <h3 id=the-windowworker><span class=secno>2.1 </span>The <code><a
300     href="#windowworker">WindowWorker</a></code> interface</h3>
301    
302     <pre
303     class=idl>[NoInterfaceObject] interface <dfn id=windowworker>WindowWorker</dfn> {
304 wakaba 1.5 readonly attribute DOMString <a href="#url" title=dom-WindowWorker-URL>URL</a>;
305     readonly attribute DOMString <a href="#name" title=dom-WindowWorker-name>name</a>;
306     readonly attribute boolean <a href="#closing" title=dom-WindowWorker-closing>closing</a>;
307     void <a href="#close" title=dom-WindowWorker-close>close</a>();
308 wakaba 1.4
309     // event handler attributes
310 wakaba 1.5 attribute <span>EventListener</span> <a href="#onattach" title=handler-WindowWorker-onattach>onattach</a>;
311     attribute <span>EventListener</span> <a href="#onunload" title=handler-WindowWorker-onunload>onunload</a>;
312 wakaba 1.3 };</pre>
313    
314 wakaba 1.5 <p>The <dfn id=url title=dom-WindowWorker-URL><code>URL</code></dfn>
315     attribute must return the value it was assigned when the <code><a
316     href="#windowworker">WindowWorker</a></code> object was created by the "<a
317     href="#run-a">run a worker</a>" algorithm. It gives the <span>absolute
318     URL</span> of the script that was used to initialize the worker.
319 wakaba 1.3
320 wakaba 1.5 <p>The <dfn id=name title=dom-WindowWorker-name><code>name</code></dfn>
321 wakaba 1.3 attribute must return the value it was assigned when the <code><a
322     href="#windowworker">WindowWorker</a></code> object was created by the "<a
323 wakaba 1.5 href="#run-a">run a worker</a>" algorithm. If it has a value that isn't
324     the empty string, its value represents the name that can be used to obtain
325     a reference to the worker using the <code
326     title=dom-WindowWorkerCreators-createNamedWorker><a
327     href="#createnamedworker">createNamedWorker()</a></code> method.
328 wakaba 1.3
329     <p>The <dfn id=closing
330 wakaba 1.5 title=dom-WindowWorker-closing><code>closing</code></dfn> attribute must
331 wakaba 1.3 return false until the "<a href="#kill-a">kill a worker</a>" processing
332     model defined below sets it to false.
333    
334 wakaba 1.4 <p>The following are the <span>event handler DOM attributes</span> that
335     must be supported by objects implementing the <code><a
336     href="#windowworker">WindowWorker</a></code> interface:
337    
338     <dl>
339 wakaba 1.5 <dt><dfn id=onattach
340     title=handler-WindowWorker-onattach><code>onattach</code></dfn>
341 wakaba 1.4
342     <dd>
343     <p>Must be invoked whenever a <code
344 wakaba 1.5 title=event-WindowWorker-attach>attach</code> event is targeted at or
345 wakaba 1.4 bubbles through the <code><a
346     href="#windowworker">WindowWorker</a></code> object.
347    
348     <dt><dfn id=onunload
349 wakaba 1.5 title=handler-WindowWorker-onunload><code>onunload</code></dfn>
350 wakaba 1.4
351     <dd>
352     <p>Must be invoked whenever a <code title=event-unload>unload</code>
353     event is targeted at or bubbles through the <code><a
354     href="#windowworker">WindowWorker</a></code> object.
355     </dl>
356    
357 wakaba 1.3 <h3 id=the-queue><span class=secno>2.2 </span>The queue of events</h3>
358    
359     <p>Each <code><a href="#windowworker">WindowWorker</a></code> object is
360     asssociated with a <dfn id=queue>queue of events</dfn>, which is initially
361     empty.
362    
363     <p>An event in the queue can be a DOM event or a timeout callback.
364    
365 wakaba 1.4 <p>All asynchronous callbacks and events that would be called or dispatched
366     in the worker must be added to the worker's queue, with the "<a
367     href="#run-a">run a worker</a>" processing model below taking care of
368     actually calling the callbacks or dispatching the events.
369    
370     <p>Once the <code><a href="#windowworker">WindowWorker</a></code>'s <code
371 wakaba 1.5 title=dom-WindowWorker-closing><a href="#closing">closing</a></code>
372 wakaba 1.4 attribute is set to true, the queue must discard anything else that would
373     be added to it. Effectively, once the <code
374 wakaba 1.5 title=dom-WindowWorker-closing><a href="#closing">closing</a></code>
375 wakaba 1.4 attribute is true, timers stop firing, notifications for all pending
376     asynchronous operations are dropped, etc.
377    
378     <h3 id=the-workers><span class=secno>2.3 </span>The worker's ports</h3>
379    
380     <p>Workers communicate with other workers and with <span title="browsing
381     context">browsing contexts</span> through <span title="channel
382     messaging">message channels</span> and their <code>MessagePort</code>
383     objects.
384    
385     <p>Each <code><a href="#windowworker">WindowWorker</a></code> <var
386     title="">worker</var> has a list of <dfn id=the-workers0>the worker's
387     ports</dfn>, which consists of all the <code>MessagePort</code> objects
388     that are entangled with another port and that have one (but only one) port
389     whose <code title=dom-MessagePort-ownerWindow>ownerWindow</code> is <var
390     title="">worker</var>. This list includes all the <code>MessagePort</code>
391     objects that are in events pending in the <a href="#queue">queue of
392     events</a>.
393    
394     <h3 id=processing><span class=secno>2.4 </span>Processing model</h3>
395 wakaba 1.3
396     <p>When a user agent is to <dfn id=run-a>run a worker</dfn> named <var
397 wakaba 1.4 title="">name</var> for a script with <span>URL</span> <var
398     title="">url</var>, a browsing context <var title="">owner browsing
399     context</var> and a <code>Document</code> <var title="">owner
400     document</var>, it must run the following steps in a completely separate
401     and parallel execution environment:
402 wakaba 1.3
403     <ol>
404     <li>
405 wakaba 1.4 <p>Attempt to <span>fetch</span><!-- XXX --> the resource identified by
406     <var title="">url</var>.</p>
407    
408     <p>If the attempt fails, then abort these steps and invoke the <a
409 wakaba 1.5 href="#worker" title="worker creation failed">error handling steps</a>
410 wakaba 1.4 defined by the algorithm that called this one.</p>
411    
412     <p>If the attempt succeeds, then let <var title="">script</var> be the
413     resource that was obtained.</p>
414    
415     <p class=note>As with <code>script</code> elements, the MIME type of the
416     script is ignored. Unlike with <code>script</code> elements, there is no
417     way to override the type. It's always assumed to be JavaScript.</p>
418     <!-- XXX people will complain about
419     this. I guess we might want to examine the MIME type... -->
420    
421    
422     <li>
423 wakaba 1.3 <p>Create a new <code><a href="#windowworker">WindowWorker</a></code>
424     object, <var title="">window</var>.</p>
425    
426     <li>
427 wakaba 1.5 <p>Set the <code title=dom-WindowWorker-URL><a href="#url">URL</a></code>
428     attribute of <var title="">window</var> to the value of <var
429     title="">url</var>.</p>
430    
431     <li>
432     <p>Set the <code title=dom-WindowWorker-name><a
433 wakaba 1.3 href="#name">name</a></code> attribute of <var title="">window</var> to
434     the value of <var title="">name</var>.</p>
435    
436     <li>
437     <p>Let <var title="">script</var>'s <span>script execution context</span>
438     (and thus also <span>global object</span>) be <var
439     title="">window</var>.</p>
440    
441     <li>
442     <p>Let <var title="">script</var>'s <span>script browsing context</span>
443     be <var title="">owner browsing context</var>.</p>
444    
445     <li>
446     <p>Let <var title="">script</var>'s <span>script document context</span>
447     be <var title="">owner document</var>.</p>
448    
449     <li>
450 wakaba 1.5 <p>Invoke the <a href="#success" title="worker creation
451     succeeded">success steps</a> defined by the algorithm that called this
452     one. (This will add an event to the <a href="#queue">queue of
453     events</a>.)</p>
454 wakaba 1.4
455     <li>
456     <p>Start monitoring <var title="">worker</var>, such that whenever the
457     <var title="">window</var> object's <code
458 wakaba 1.5 title=dom-WindowWorker-closing><a href="#closing">closing</a></code>
459 wakaba 1.4 attribute is false and all <a href="#the-workers0">the worker's
460     ports</a> have their <code title=dom-MessagePort-active>active</code>
461     attributes set to false, the user agent suspends execution of script in
462     that worker until such time as either the <code
463 wakaba 1.5 title=dom-WindowWorker-closing><a href="#closing">closing</a></code>
464 wakaba 1.4 attribute switches to true or one of the <code>MessagePort</code>
465     objects in the list of <a href="#the-workers0">the worker's ports</a>
466     has an <code title=dom-MessagePort-active>active</code> attribute with
467     the value true.</p>
468 wakaba 1.3
469     <li>
470 wakaba 1.4 <p>Start monitoring <var title="">worker</var>, such that as soon as the
471     list of <a href="#the-workers0">the worker's ports</a> becomes empty,
472     the <var title="">window</var> object's <code
473 wakaba 1.5 title=dom-WindowWorker-closing><a href="#closing">closing</a></code>
474 wakaba 1.4 attribute is set to true.</p>
475    
476     <li>
477     <p>Run <var title="">script</var> until it either returns, fails to catch
478     an exception, or gets prematurely aborted by the "<a href="#kill-a">kill
479     a worker</a>" algorithm below.</p>
480    
481     <p class=note>If the script gets aborted by the "<a href="#kill-a">kill a
482     worker</a>" algorithm, then that same algorithm will cause there to only
483     be a single event in the <a href="#queue">queue of events</a> at the
484     next step, namely the <code title=message-unload>unload</code> event.
485     However, if the event is ignored then it will become true as soon as
486     that port is garbage collected.</p>
487    
488     <li>
489     <p><i>Event loop</i>: Wait until either there is an event in the <a
490 wakaba 1.3 href="#queue">queue of events</a> associated with <var
491 wakaba 1.4 title="">window</var> or the <var title="">window</var> object's <code
492 wakaba 1.5 title=dom-WindowWorker-closing><a href="#closing">closing</a></code>
493 wakaba 1.4 attribute is set to true.</p>
494 wakaba 1.3
495     <li>
496     <p>Dispatch the oldest event or callback in the <a href="#queue">queue of
497 wakaba 1.4 events</a>, if any. The handling of this event or the execution of this
498     callback might get prematurely aborted by the "<a href="#kill-a">kill a
499     worker</a>" algorithm below.</p>
500 wakaba 1.3
501     <li>
502     <p>If there are any more events in the <a href="#queue">queue of
503     events</a> or if the <var title="">window</var> object's <code
504 wakaba 1.5 title=dom-WindowWorker-closing><a href="#closing">closing</a></code>
505 wakaba 1.3 attribute is set to false, then jump back to the step above labeled
506     <i>event loop</i>.</p>
507    
508     <li>
509     <p class=big-issue>timers, intervals, XMLHttpRequests, database
510     transactions, etc, must be killed; ports must be deactivated and
511 wakaba 1.4 unentangled (do not send unload)</p>
512 wakaba 1.3 </ol>
513    
514     <hr>
515    
516     <p>When a user agent is to <dfn id=kill-a>kill a worker</dfn>, it must run
517     the following steps in parallel with the worker's main loop (the "<a
518     href="#run-a">run a worker</a>" processing model defined above):
519    
520     <ol>
521     <li>
522     <p>Create an <code>Event</code> object with the event name <code
523     title=event-unload>unload</code>, which does not bubble and is not
524     cancelable, and add it to the worker's <code><a
525     href="#windowworker">WindowWorker</a></code> object's <a
526 wakaba 1.4 href="#queue">queue of events</a>, targetted at the <code><a
527     href="#windowworker">WindowWorker</a></code> object itself.
528    
529     <li>
530     <p>Set the worker's <code><a href="#windowworker">WindowWorker</a></code>
531 wakaba 1.5 object's <code title=dom-WindowWorker-closing><a
532 wakaba 1.4 href="#closing">closing</a></code> attribute to true.
533 wakaba 1.3
534     <li>
535 wakaba 1.4 <p>Wait a user-agent-defined amount of time. If the "<a href="#run-a">run
536     a worker</a>" processing model defined above immediately starts running
537     event listeners registered for <code title=event-unload>unload</code>
538     event, this time should not be zero &mdash; the idea is that the <code
539     title=event-unload>unload</code> event can be used to clean up when
540     shutting down unexpectedly.
541 wakaba 1.3
542     <li>
543     <p>If there are any events in the <a href="#queue">queue of events</a>
544     other than the <code title=event-unload>unload</code> event that this
545     algorithm just added, discard them without dispatching them.
546    
547     <li>
548     <p>If the <code title=event-unload>unload</code> event that this
549     algorithm just added hasn't yet been dispatched, then abort the script
550     currently running in the worker.
551    
552     <li>
553     <p>Wait a user-agent-defined amount of time.
554    
555     <li>
556     <p>Abort the script currently running in the worker (if any script is
557     running, then it will be a handler for the <code
558     title=event-unload>unload</code> event).
559     </ol>
560    
561 wakaba 1.4 <hr>
562    
563     <p>When a script invokes the <dfn id=close
564 wakaba 1.5 title=dom-WindowWorker-close><code>close()</code></dfn> method on a
565 wakaba 1.4 <code><a href="#windowworker">WindowWorker</a></code> object, the user
566     agent must run the following steps:
567    
568     <ol>
569     <li>
570     <p>Create an <code>Event</code> object with the event name <code
571     title=event-unload>unload</code>, which does not bubble and is not
572     cancelable, and add it to the <code><a
573     href="#windowworker">WindowWorker</a></code> object's <a
574     href="#queue">queue of events</a>, targetted at the <code><a
575     href="#windowworker">WindowWorker</a></code> object itself.
576    
577     <li>
578     <p>Set the worker's <code><a href="#windowworker">WindowWorker</a></code>
579 wakaba 1.5 object's <code title=dom-WindowWorker-closing><a
580 wakaba 1.4 href="#closing">closing</a></code> attribute to true.
581    
582     <li>
583     <p>For each <code>MessagePort</code> object that is entangled with
584     another port and that has one (but only one) port whose <code
585     title=dom-MessagePort-ownerWindow>ownerWindow</code> is the <code><a
586     href="#windowworker">WindowWorker</a></code> object on which the method
587     was invoked, run the following substeps:</p>
588    
589     <ol>
590     <li>
591     <p>Unentangle the two ports.
592    
593     <li>
594     <p>Set both ports' <code title=dom-MessagePort-active>active</code>
595     attribute to false.
596    
597     <li>
598     <p>At the next available opportunity, after any scripts have finished
599     executing<!-- XXX queue -->, <span>fire a simple event</span> called
600     <code title=event-unload>unload</code> at the other port (the one
601     whose <code title=dom-MessagePort-ownerWindow>ownerWindow</code> is
602     not the <code><a href="#windowworker">WindowWorker</a></code> object
603 wakaba 1.5 on which the <code title=dom-WindowWorker-close><a
604 wakaba 1.4 href="#close">close()</a></code> method was called).
605     </ol>
606     </ol>
607    
608 wakaba 1.5 <h3 id=creating><span class=secno>2.5 </span>Creating workers</h3>
609 wakaba 1.3
610     <pre
611     class=idl>[NoInterfaceObject] interface <dfn id=windowworkercreators>WindowWorkerCreators</dfn> {
612 wakaba 1.5 <span>MessagePort</span> <a href="#createworker" title=dom-WindowWorkerCreators-createWorker>createWorker</a>(in DOMString scriptURL);
613     <span>MessagePort</span> <a href="#createnamedworker" title=dom-WindowWorkerCreators-createNamedWorker>createNamedWorker</a>(in DOMString name, in DOMString scriptURL);
614 wakaba 1.3 };</pre>
615    
616     <p>Objects that implement the <code>Window</code> interface must also
617     implement the <code><a
618     href="#windowworkercreators">WindowWorkerCreators</a></code> interface.
619 wakaba 1.4
620     <hr>
621    
622 wakaba 1.5 <p>When the <dfn id=createworker
623     title=dom-WindowWorkerCreators-createWorker><code>createWorker(<var
624     title="">scriptURL</var>)</code></dfn> method is invoked, the user agent
625     must run the following steps:
626 wakaba 1.4
627     <ol>
628 wakaba 1.5 <li>
629     <p><span title="resolve a url">Resolve</span> the <var
630     title="">scriptURL</var> argument.
631    
632     <li>
633     <p>If this fails, throw a <code>SYNTAX_ERR</code> exception.
634    
635     <li>
636     <p>If the <span>origin</span> of the resulting <span>absolute URL</span>
637     is not the <span title="same origin">same</span> as the origin of the
638     script that invoked the method, then throw a <span>security
639     exception</span>.
640    
641     <li>
642     <p><a href="#create">Create a worker</a> from the resulting
643     <span>absolute URL</span> whose name is the empty string.
644    
645     <li>
646     <p>Return the <code>MessagePort</code> object returned from the <a
647     href="#create">create a worker</a> algorithm.
648 wakaba 1.4 </ol>
649    
650     <hr>
651    
652 wakaba 1.5 <p>When the <dfn id=createnamedworker
653     title=dom-WindowWorkerCreators-createNamedWorker><code>createNamedWorker(<var
654     title="">name</var>, <var title="">scriptURL</var>)</code></dfn> method is
655     invoked, the user agent must run the following steps:
656 wakaba 1.4
657     <ol>
658 wakaba 1.5 <li>
659     <p><span title="resolve a url">Resolve</span> the <var
660     title="">scriptURL</var> argument.
661    
662     <li>
663     <p>If this fails, throw a <code>SYNTAX_ERR</code> exception.
664    
665     <li>
666     <p>If the <span>origin</span> of the resulting <span>absolute URL</span>
667     is not the <span title="same origin">same</span> as the origin of the
668     script that invoked the method, then throw a <span>security
669     exception</span>.
670    
671     <li>
672     <p>If the <var title="">name</var> argument is the empty string, <a
673     href="#create">create a worker</a> from the resulting <span>absolute
674     URL</span>, whose name is the empty string, and return the
675     <code>MessagePort</code> object returned from the <a
676     href="#create">create a worker</a> algorithm. Then, abort these steps.
677    
678     <li>
679     <p>If there exists a worker whose <code title=dom-WindowWorker-closing><a
680     href="#closing">closing</a></code> attribute is false, whose <code
681     title=dom-WindowWorker-name><a href="#name">name</a></code> attribute is
682     exactly equal to the <var title="">name</var> argument, and whose <code
683     title=dom-WindowWorker-URL><a href="#url">URL</a></code> attribute has
684     the <span>same origin</span> as the resulting <span>absolute URL</span>,
685     then run these substeps:</p>
686    
687     <ol>
688     <li>
689     <p>If that worker's <code title=dom-WindowWorker-URL><a
690     href="#url">URL</a></code> attribute is not exactly equal to the
691     resulting <span>absolute URL</span>, then throw a
692     <code>URL_MISMATCH_ERR</code> exception and abort these steps. <span
693     class=big-issue>code 19</span>
694    
695     <li>
696     <p><span>Create a new <code>MessagePort</code> object</span> owned by
697     the <span>script execution context</span> of the script that invoked
698     the method.
699    
700     <li>
701     <p>Return that port.
702    
703     <li>
704     <p>Asynchronously, <a href="#attach" title="attach to a
705     worker">attach</a> to this preexisting worker, with the newly created
706     port.
707     </ol>
708    
709     <p>Otherwise, <a href="#create">create a worker</a> from the resulting
710     <span>absolute URL</span>, whose name is the value of the <var
711     title="">name</var> argument, and return the <code>MessagePort</code>
712     object returned from the <a href="#create">create a worker</a>
713     algorithm.</p>
714 wakaba 1.4 </ol>
715    
716     <hr>
717    
718 wakaba 1.5 <p>The steps to <dfn id=create>create a worker</dfn> from a
719     <span>URL</span> <var title="">url</var> and whose name is <var
720     title="">name</var>, in the context of a method call, are as follows:
721 wakaba 1.4
722     <ol>
723 wakaba 1.5 <li>
724     <p><span>Create a new <code>MessagePort</code> object</span> owned by the
725     <span>script execution context</span> of the script that invoked the
726     method.
727    
728     <li>
729     <p>Return that port.
730    
731     <li>
732     <p>In a parallel execution context (i.e. a separate thread or process or
733     equivalent construct), <a href="#run-a">run a worker</a> named <var
734     title="">name</var> for the script with <span>URL</span> <var
735     title="">url</var>, with the <span>script browsing context</span> of the
736     script that invoked the method as the <var title="">owner browsing
737     context</var> and with the <span>script document context</span> of the
738     script that invoked the method as the <var title="">owner
739     document</var>.</p>
740    
741     <p>If that algorithm invokes the steps for <dfn id=success title="worker
742     creation succeeded">success steps</dfn>, then <a href="#attach"
743     title="attach to a worker">attach</a> to this new worker, with the newly
744     created port.</p>
745    
746     <p>Otherwise, if the <dfn id=worker>worker creation failed</dfn>, then at
747     the next available opportunity, after any scripts have finished
748     executing<!-- XXX queue -->, <span>fire a simple event</span> called
749     <code title=event-error>error</code> at the newly created port.</p>
750 wakaba 1.4 </ol>
751    
752     <hr>
753    
754 wakaba 1.5 <p>The steps to <dfn id=attach>attach to a worker</dfn> given a
755     <code>MessagePort</code> object <var title="">port</var> are as follows:
756 wakaba 1.4
757     <ol>
758 wakaba 1.5 <li>
759     <p>If <var title="">port</var> would have been garbage collected, or if
760     the <span>active document</span> of the <code
761     title=dom-MessagePort-ownerWindow>ownerWindow</code> of <var
762     title="">port</var> is no longer the same <code>Document</code> object
763     as when <var title="">port</var> was created, then do nothing. Abort
764     these steps. If the worker was just created, it'll get killed
765     immediately.</p>
766    
767     <li>
768     <p><span>Create a new <code>MessagePort</code> object</span> owned by the
769     <code><a href="#windowworker">WindowWorker</a></code> of the worker.
770    
771     <li>
772     <p><span>Entangle</span> this newly created port and the port <var
773     title="">port</var> that was passed to these steps.
774    
775     <li>
776     <p>Set the <code title=dom-MessagePort-active>active</code> attribute of
777     both ports to true.
778    
779     <li>
780     <p>At the next available opportunity, after any scripts have finished
781     executing<!-- XXX queue -->, <span>fire a simple event</span> called
782     <code title=event-load>load</code> at <var title="">port</var>.
783    
784     <li>
785     <p>Create an event that uses the <code>MessageEvent</code> interface,
786     with the name <code title=event-attach>attach</code>, which does not
787     bubble, is cancelable, has no default action, has a <code
788     title=dom-MessageEvent-data>data</code> attribute whose value is the
789     empty string and has a <code
790     title=dom-MessageEvent-messagePort>messagePort</code> attribute whose
791     value is the newly created port, and add it to the worker's <code><a
792     href="#windowworker">WindowWorker</a></code> object's <a
793     href="#queue">queue of events</a>, targetted at the <code><a
794     href="#windowworker">WindowWorker</a></code> object itself.
795 wakaba 1.4 </ol>
796 wakaba 1.3
797 wakaba 1.5 <h2 id=apis-available><span class=secno>3. </span>APIs available to workers</h2>
798    
799     <p>Objects that implement the <code><a
800     href="#windowworker">WindowWorker</a></code> interface must also implement
801     the following interfaces:
802    
803     <ul>
804     <li>
805     <p>The <code>Window</code> interface, and interfaces that are required to
806     be implemented by objects implementing that interface, including:</p>
807    
808     <ul>
809     <li>The <code>WindowTimers</code> interface
810    
811     <li>The <code><a
812     href="#windowworkercreators">WindowWorkerCreators</a></code> interface
813     </ul>
814    
815     <li>The <code>EventTarget</code> interface.
816     </ul>
817 wakaba 1.3
818 wakaba 1.1 <h2 class=no-num id=references>References</h2>
819    
820     <p class=big-issue>This section will be written in a future
821     draft.<!--XXX-->
822    
823     <h2 class=no-num id=acknowledgements>Acknowledgements</h2>
824     <!-- ACKS -->
825    
826     <p>Thanks to Maciej Stachowiak and Mike Smith for their useful and
827     substantial comments.
828 wakaba 1.3
829     <p>Huge thanks to the whole Gears team, who pioneered this technology and
830     whose experience has been a huge influence on this specification.

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24