/[suikacvs]/markup/html/html5/spec-ja/workers-non-normative.ja.html.u8
Suika

Contents of /markup/html/html5/spec-ja/workers-non-normative.ja.html.u8

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.156 - (hide annotations) (download)
Mon Aug 10 06:17:48 2009 UTC (16 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.155: +199 -74 lines
make

1 wakaba 1.156 <!DOCTYPE html><html lang=en-US-x-hixie><meta charset=utf-8>
2     <title>Web Workers</title>
3     <link href=http://www.whatwg.org/style/specification rel=stylesheet>
4 wakaba 1.111 <link href=ja-style rel=stylesheet>
5     <link href=only-ja-style rel="stylesheet" title="Show only Japanese text" id=style-only-ja>
6     <link href=both-en-ja-style rel="alternate stylesheet" title="Show both English and Japanese texts" id=style-both-en-ja>
7 wakaba 1.156 <script src=ja-script defer async></script>
8     <link href=http://www.whatwg.org/images/icon rel=icon>
9     </head>
10     <body class=draft>
11 wakaba 1.111 <div class=head>
12     <p class="has-ja-translation" data-ja-hash="7c0cfd95ed2e5f66067c25a5e7fec67c"><span class=en-original lang=en><a class=logo href=http://www.whatwg.org/ rel=home><img alt=WHATWG src=/images/logo></a></span><span class=ja-translation lang=ja><a class=logo href=http://www.whatwg.org/ rel=home><img lang=en alt=WHATWG
13     src=http://www.whatwg.org/images/logo></a></span></p>
14     <h1 class="no-ja-translation" data-ja-hash="6cb7eb9696d986359fa3a78c4b8e60dc"><span class=en-original lang=en>Web Workers</span></h1>
15 wakaba 1.156 <h2 class="no-num no-toc no-ja-translation" data-ja-hash="862e9dca5a15543c2771ad6a872f8022" id=draft-recommendation-—-date:-01-jan-1901><span class=en-original lang=en>Draft Recommendation — 9 August 2009</span></h2>
16 wakaba 1.111 <p class="has-ja-translation" data-ja-hash="5211c3fce4ddd8160d21446a73a092c1"><span class=en-original lang=en>You can take part in this work. <a href=http://www.whatwg.org/mailing-list>Join the working group's discussion list.</a></span><span class=ja-translation lang=ja>みなさんにも作業にご参加いただけます。 <a
17     href=http://www.whatwg.org/mailing-list>作業部会の議論用メイリング・リストに参加してください。</a></span></p>
18     <p class="has-ja-translation" data-ja-hash="f8e7b0fcec0268c81579638290279e82"><span class=en-original lang=en><strong>Web designers!</strong> We have a <a href=http://blog.whatwg.org/faq/>FAQ</a>, a <a href=http://forums.whatwg.org/>forum</a>, and a <a href=http://www.whatwg.org/mailing-list#help>help mailing list</a> for you!</span><span class=ja-translation lang=ja><strong>Web デザイナーのみなさん!</strong> みなさんのための <a
19     href=http://blog.whatwg.org/faq/ lang=en>FAQ</a>、<a
20     href=http://forums.whatwg.org/>掲示板</a>、<a
21     href=http://www.whatwg.org/mailing-list#help>ヘルプ用メイリング・リスト</a>があります!
22    
23     </span><p>
24    
25     <!-- Japanese-translation-only notes -->
26     <ins class="ja-note cover-ja-note" lang=ja>
27     <p>この文書は、 WHATWG 仕様書の日本語訳です。 正式な仕様書は英語版だけであり、この日本語訳はあくまで参考としてご利用ください。
28    
29     <p lang=en>This document is a non-normative Japanese translation of the WHATWG specification. Only the original English version is normative and this Japanese translation is non‐normative.
30    
31     <p>日本語訳は段落をダブルクリックすると編集できます。<a href="http://suika.fam.cx/~wakaba/pbin/accounts/add">アカウントを作成</a>して <code>spec-ja</code> グループに参加してください。編集結果はおよそ3時間おきに反映されます。また、原文の変更には毎日自動的に追随しています。 (<a href=notes>詳細</a>)
32    
33     <p lang=en>You can edit Japanese text by double-clicking the paragraph you'd like to edit. <a href="http://suika.fam.cx/~wakaba/pbin/accounts/add">Create an account</a> and join the <code>spec-ja</code> group. Any additions of and modifications to Japanese text will be applied to the document within about three hours. Any changes to the original English specification will automatically be incorporated to the document every day. (<a href=notes>Details</a>)
34    
35     <p><a href="http://wiki.whatwg.org/wiki/Translations">他の翻訳のリスト</a>もご覧ください。
36    
37     <p lang=en>See also the list of <a href="http://wiki.whatwg.org/wiki/Translations">translations</a>.
38    
39     <p><button type=button onclick="
40     document.getElementById ('style-only-ja').disabled = false;
41     document.getElementById ('style-both-en-ja').disabled = true;
42     ">日本語訳だけ表示 <span lang=en>Show only Japanese translation</span></button>
43     <p><button type=button onclick="
44     document.getElementById ('style-only-ja').disabled = true;
45     document.getElementById ('style-both-en-ja').disabled = false;
46     ">英和対訳表示 <span lang=en>Show both English and Japanese texts</span></button>
47     </ins>
48    
49     <p><span><!-- dummy --></span></p>
50 wakaba 1.156 <dl>
51     <dt class="has-ja-translation" data-ja-hash="87b044fafc6f01197a9a700e6fa28a69"><span class=en-original lang=en>This version:</span><span class=ja-translation lang=ja><ins class=ja-note>原文の</ins>この版</span></dt>
52 wakaba 1.111 <dd class="no-ja-translation" data-ja-hash="b1b00adfdf359bf303bf8c64476f2e91"><span class=en-original lang=en><a href=http://www.whatwg.org/specs/web-workers/current-work/>http://whatwg.org/ww</a></span></dd>
53     <dt class="has-ja-translation" data-ja-hash="8866e8de2efa7275a5dc8e942c1613c2"><span class=en-original lang=en>Version history:</span><span class=ja-translation lang=ja><ins class=ja-note>原文の</ins>改版履歴:</span></dt>
54     <dd class="has-ja-translation" data-ja-hash="fc2cb84da44565f149b710ac5dfb38f2"><span class=en-original lang=en>Twitter messages (non-editorial changes only): <a href=http://twitter.com/WHATWG>http://twitter.com/WHATWG</a></span><span class=ja-translation lang=ja><span lang=en>Twitter</span> メッセージ (編集上の変更以外): <a
55     href=http://twitter.com/WHATWG>http://twitter.com/WHATWG</a></span></dd>
56     <dd class="has-ja-translation" data-ja-hash="3a0facbd53f73c0877af4c6485a783af"><span class=en-original lang=en>Commit-Watchers mailing list: <a href=http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org>http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org</a></span><span class=ja-translation lang=ja>Commit-Watchers メイリング・リスト: <a
57     href=http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org>http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org</a></span></dd>
58     <dd class="has-ja-translation" data-ja-hash="5e1dbca74cface6f0d0ea523340e6a89" data-ja-real-hash="a5d87a842e49eed08d894d0148296604"><span class=en-original lang=en>Interactive Web interface: <a href=http://html5.org/tools/web-workers-tracker>http://html5.org/tools/web-workers-tracker</a></span><span class=ja-translation lang=ja>対話的 <span lang=en>Web</span> 界面: <a href=http://html5.org/tools/web-workers-tracker>http://html5.org/tools/web-workers-tracker</a></span></dd>
59     <dd class="has-ja-translation" data-ja-hash="ea5cbdd06bfb529e4a1bcfeac9cfbd61" data-ja-real-hash="fabeffa34fbe319f499e2c5fd49a414f"><span class=en-original lang=en>Subversion interface: <a href=http://svn.whatwg.org/webworkers/>http://svn.whatwg.org/webworkers/</a></span><span class=ja-translation lang=ja><span lang=en>Subversion</span> 界面: <a href=http://svn.whatwg.org/webworkers/>http://svn.whatwg.org/webworkers/</a></span></dd>
60     <dt class="has-ja-translation" data-ja-hash="8468b55db22971120cb71091ece7839e"><span class=en-original lang=en>Issues:</span><span class=ja-translation lang=ja>問題:</span></dt>
61     <dd class="has-ja-translation" data-ja-hash="80e92f8cfebdeaa7dd35236fded506f7"><span class=en-original lang=en>To send feedback: <a href=http://www.whatwg.org/mailing-list>[email protected]</a></span><span class=ja-translation lang=ja>フィードバックの送信先: <a
62     href=http://www.whatwg.org/mailing-list>[email protected]</a></span></dd>
63     <dd class="has-ja-translation" data-ja-hash="31c70a584b8b4195d95daffc76736dea"><span class=en-original lang=en>To view and vote on feedback: <a href=http://www.whatwg.org/issues/>http://www.whatwg.org/issues/</a></span><span class=ja-translation lang=ja>フィードバックの閲覧・投票: <a
64     href=http://www.whatwg.org/issues/>http://www.whatwg.org/issues/</a></span></dd>
65     <dt class="has-ja-translation" data-ja-hash="aa8d072dc59504320cfa92381f541a5f"><span class=en-original lang=en>Editor:</span><span class=ja-translation lang=ja>編集者:</span></dt>
66     <dd class="no-ja-translation" data-ja-hash="220fb2ab7924ad62bc8567b8b9c5f0f8"><span class=en-original lang=en>Ian Hickson, Google, [email protected]</span></dd>
67 wakaba 1.156 </dl>
68     <p class="copyright no-ja-translation" data-ja-hash="a440a2aa3629ba6d93ebbaea2d008aa2"><span class=en-original lang=en>© Copyright 2004-2008 Apple Computer, Inc.,
69 wakaba 1.111 Mozilla Foundation, and Opera Software ASA.</span></p>
70     <p class="copyright no-ja-translation" data-ja-hash="5419c8afab07265f61a6768f2680776d"><span class=en-original lang=en>You are granted a license to use, reproduce
71     and create derivative works of this document.</span></p>
72     </div>
73    
74 wakaba 1.156 <hr>
75    
76     <h2 class="no-num no-toc has-ja-translation" data-ja-hash="e353dbe42c8654f33588d4da0b517469" id=abstract><span class=en-original lang=en>Abstract</span><span class=ja-translation lang=ja>概要</span></h2>
77 wakaba 1.111
78     <p class="has-ja-translation" data-ja-hash="a4f61aa99f0d87d5d87b6e07071a74da"><span class=en-original lang=en>This specification defines an API that allows Web application
79     authors to spawn background workers running scripts in parallel to
80     their main page. This allows for thread-like operation with
81     message-passing as the coordination mechanism.</span><span class=ja-translation lang=ja>この仕様書は、 Web アプリケーションで、主たる頁とは並列に、
82     背景労働者スクリプトを走らせるための API を定義します。
83     これにより、メッセージ・パッシングによるスレッド的操作を協調機構として利用できるようになります。</span></p>
84    
85    
86     <h2 class="no-num no-toc has-ja-translation" data-ja-hash="c9bfd146532700356f3ff5ea6b1bf72e" id=status><span class=en-original lang=en>Status of this document</span><span class=ja-translation lang=ja>この文書の状態</span></h2>
87    
88     <p class="has-ja-translation" data-ja-hash="910f4ff57cc374ba46a8fecb18849de5"><span class=en-original lang=en><strong>This is a work in progress!</strong> This document is
89     changing on a daily if not hourly basis in response to comments and
90     as a general part of its development process. Comments are very
91     welcome, please send them to <a href=mailto:[email protected]>[email protected]</a>. Thank
92     you.</span><span class=ja-translation lang=ja><strong>この文書は作業中です!</strong>
93     この文書は、コメントへの対応や通常の開発の過程として、
94     毎時毎分とは言い過ぎですが毎日のペースで変更されています。
95     コメントは非常に歓迎していますので、
96     <a href=mailto:[email protected]>[email protected]</a>
97     へお送りください。よろしくお願いします。</span></p>
98    
99     <p class="has-ja-translation" data-ja-hash="5bb9ea777b965ca8d962ba2b6f663d46"><span class=en-original lang=en>The current focus is in developing a first draft proposal.</span><span class=ja-translation lang=ja>現在の焦点は、第1案の開発です。</span></p>
100    
101     <p class="has-ja-translation" data-ja-hash="f0a0e89202a0b75b7cf2314905ae258d"><span class=en-original lang=en>Implementors should be aware that this specification is not
102     stable. <strong>Implementors who are not taking part in the
103     discussions are likely to find the specification changing out from
104     under them in incompatible ways.</strong> Vendors interested in
105     implementing this specification before it eventually reaches the
106     call for implementations should join the <a href=/mailing-list>WHATWG mailing list</a> and take part in the
107     discussions.</span><span class=ja-translation lang=ja>実装者は、この仕様書が安定していないことに注意するべきです。
108     <strong>実装者は議論に参加しておかないと、
109     仕様がその実装とは非互換に変更されてしまうかもしれません。</strong>
110     この仕様書がいずれ実装呼び掛けの段階に達するのよりも前にこの仕様を実装したい販売者は、
111     <a href=http://www.whatwg.org/mailing-list>WHATWG メイリング・リスト</a>に参加し、
112     議論に加わるべきです。</span></p>
113    
114     <p class="no-ja-translation" data-ja-hash="739dc8d532ab9ebbd8a5ba09015898cc"><span class=en-original lang=en>This specification is also being produced by the <a href=http://www.w3.org/2008/webapps/>W3C Web Apps WG</a>. The two
115     specifications are identical from the table of contents onwards.</span></p>
116    
117     <h2 class="no-num no-toc has-ja-translation" data-ja-hash="598b8ae10dfce818e73d3218daddbdae" id=contents><span class=en-original lang=en>Table of contents</span><span class=ja-translation lang=ja>目次
118     </span></h2>
119    
120     <!--begin-toc-->
121     <ol class=toc>
122     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="e8340d3e813afc18cffdf99dd3a546e3"><span class=en-original lang=en><a href=#introduction><span class=secno>1 </span>Introduction</a>
123     </span><ol>
124     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="1f928c91e5f5cc18f353953a9057c45e"><span class=en-original lang=en><a href=#scope><span class=secno>1.1 </span>Scope</a></span></li>
125     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="d9aa6a9a8b1af17de823ae3bc43e4cfa"><span class=en-original lang=en><a href=#tutorial><span class=secno>1.2 </span>Tutorial</a>
126     </span><ol>
127     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="4cc3646bed3970b883d0e3670dc846be"><span class=en-original lang=en><a href=#a-background-number-crunching-worker><span class=secno>1.2.1 </span>A background number-crunching worker</a></span></li>
128     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="d6b18f36ab82a61c165ccf567ef56b09"><span class=en-original lang=en><a href=#a-worker-for-updating-a-client-side-database><span class=secno>1.2.2 </span>A worker for updating a client-side database</a></span></li>
129     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="5d6e6c3a38a06321f9ff944393eb85c8"><span class=en-original lang=en><a href=#worker-used-for-background-i/o><span class=secno>1.2.3 </span>Worker used for background I/O</a></span></li>
130     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="00a7ff1b4687e65bfd54d8f34ac6c51b"><span class=en-original lang=en><a href=#shared-workers><span class=secno>1.2.4 </span>Shared workers</a></span></li>
131     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="0165a00ce6ba433bb49fb40d83e80072"><span class=en-original lang=en><a href=#delegation><span class=secno>1.2.5 </span>Delegation</a></span></li>
132     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="b073b1b0d03d81d0427c4bbb5a1056dc"><span class=en-original lang=en><a href=#providing-libraries><span class=secno>1.2.6 </span>Providing libraries</a></span></ol></ol></li>
133 wakaba 1.139 <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="adf81d9200d74ed3c0f2c032a0531bf6"><span class=en-original lang=en><a href=#conformance-requirements><span class=secno>2 </span>Conformance requirements</a>
134 wakaba 1.111 </span><ol>
135 wakaba 1.139 <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="b161941cca2282efa472ccf0fc205795"><span class=en-original lang=en><a href=#dependencies><span class=secno>2.1 </span>Dependencies</a></span></ol></li>
136     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="50b097cb49254c35d708954ba4f90f62"><span class=en-original lang=en><a href=#terminology><span class=secno>3 </span>Terminology</a></span></li>
137     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="211638ee3831cd03e9865c803584d48d"><span class=en-original lang=en><a href=#infrastructure><span class=secno>4 </span>Infrastructure</a>
138     </span><ol>
139     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="f3f7863eb788bc470f20764d323ff03a"><span class=en-original lang=en><a href=#the-global-scope><span class=secno>4.1 </span>The global scope</a>
140 wakaba 1.111 </span><ol>
141 wakaba 1.139 <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="07444422623a61768c995caee39d6f3f"><span class=en-original lang=en><a href=#the-workerglobalscope-abstract-interface><span class=secno>4.1.1 </span>The <code>WorkerGlobalScope</code> abstract interface</a></span></li>
142     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="ffb909cb8c908fc02c8383085a89f4b3"><span class=en-original lang=en><a href=#dedicated-workers-and-the-dedicatedworkerglobalscope-interface><span class=secno>4.1.2 </span>Dedicated workers and the <code>DedicatedWorkerGlobalScope</code> interface</a></span></li>
143     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="4ce24e9ab32d066fc7ea5182fd496649"><span class=en-original lang=en><a href=#shared-workers-and-the-sharedworkerglobalscope-inteface><span class=secno>4.1.3 </span>Shared workers and the <code>SharedWorkerGlobalScope</code> inteface</a></span></ol></li>
144     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="2d6e1e5868fff5fcbb2e9fc349fef7f1"><span class=en-original lang=en><a href=#base-urls-and-origins-of-workers><span class=secno>4.2 </span>Base URLs and origins of workers</a></span></li>
145     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="1e7058220085c30c6bb2a12a3c89679e"><span class=en-original lang=en><a href=#decoding-scripts><span class=secno>4.3 </span>Decoding scripts</a></span></li>
146     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="e2bf69c265f0577e8eda8540795eac46"><span class=en-original lang=en><a href=#the-event-loop><span class=secno>4.4 </span>The event loop</a></span></li>
147     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="2b43c40d7feeeee8ea12fd0c23d99809"><span class=en-original lang=en><a href="#the-worker's-lifetime"><span class=secno>4.5 </span>The worker's lifetime</a></span></li>
148     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="5446f38a420881f029c7a587e3b49523"><span class=en-original lang=en><a href=#processing-model><span class=secno>4.6 </span>Processing model</a></span></li>
149     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="d8bba28047e39857c758bfb25576078e"><span class=en-original lang=en><a href=#runtime-script-errors><span class=secno>4.7 </span>Runtime script errors</a></span></li>
150     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="e415bb73deb1eb37d58b2c426c2891bf"><span class=en-original lang=en><a href=#creating-workers><span class=secno>4.8 </span>Creating workers</a>
151 wakaba 1.111 </span><ol>
152 wakaba 1.139 <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="fd7fce5cf761f81e7ccde31c886c4e88"><span class=en-original lang=en><a href=#the-abstractworker-abstract-interface><span class=secno>4.8.1 </span>The <code>AbstractWorker</code> abstract interface</a></span></li>
153     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="174a24e7617617691c1fea0de7a19411"><span class=en-original lang=en><a href=#dedicated-workers-and-the-worker-interface><span class=secno>4.8.2 </span>Dedicated workers and the <code>Worker</code> interface</a></span></li>
154     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="4ffcaeb7e6840a21cd2cce4bda60ecdd"><span class=en-original lang=en><a href=#shared-workers-and-the-sharedworker-interface><span class=secno>4.8.3 </span>Shared workers and the <code>SharedWorker</code> interface</a></span></ol></ol></li>
155     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="a47f7c0f403c3aa899ecde08deff9a43"><span class=en-original lang=en><a href=#apis-available-to-workers><span class=secno>5 </span>APIs available to workers</a>
156 wakaba 1.111 </span><ol>
157 wakaba 1.139 <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="37e9da5ea67ea86a29b62f8e0d1111ef"><span class=en-original lang=en><a href=#importing-scripts-and-libraries><span class=secno>5.1 </span>Importing scripts and libraries</a></span></li>
158     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="91054561db04b2213a3534dc54ef2c3b"><span class=en-original lang=en><a href=#the-navigator-object><span class=secno>5.2 </span>The <code title=worker-Navigator>Navigator</code> object</a></span></li>
159     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="7f0a8a7686a8cd5685cb93c1f3f82741"><span class=en-original lang=en><a href=#apis-defined-in-other-specifications><span class=secno>5.3 </span>APIs defined in other specifications</a></span></li>
160     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="8dda0154835b8739bd1ada5c0b5c089f"><span class=en-original lang=en><a href=#interface-objects-and-constructors><span class=secno>5.4 </span>Interface objects and constructors</a></span></li>
161     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="aae8cb440e8679d879f0df57ac164dc0"><span class=en-original lang=en><a href=#worker-locations><span class=secno>5.5 </span>Worker locations</a></span></ol></li>
162 wakaba 1.111 <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="721ff2a311123f40dbb5fe64d58f47d3"><span class=en-original lang=en><a class=no-num href=#references>References</a></span></li>
163     <li><p class="no-ja-translation ja-translation-inserted" data-ja-hash="e3edbd0e5dae2337ce9018ac56f33463"><span class=en-original lang=en><a class=no-num href=#acknowledgements>Acknowledgements</a></span></ol>
164     <!--end-toc-->
165 wakaba 1.156 <hr>
166     <h2 id=introduction class="has-ja-translation" data-ja-hash="0b79795d3efc95b9976c7c5b933afce2"><span class=en-original lang=en><span class=secno>1 </span>Introduction</span><span class=ja-translation lang=ja><span class=secno>1 </span>はじめに</span></h2>
167 wakaba 1.111
168     <h3 id=scope class="has-ja-translation" data-ja-hash="5d113f2038d289f391614c39043629e8"><span class=en-original lang=en><span class=secno>1.1 </span>Scope</span><span class=ja-translation lang=ja><span class=secno>1.1 </span>適用範囲</span></h3>
169    
170 wakaba 1.135 <p class="no-ja-translation" data-ja-hash="2b52ab89148ac538f9c9380fc5da5b2f"><span class=en-original lang=en><i>This section is non-normative.</i></span></p>
171 wakaba 1.111
172     <p class="no-ja-translation" data-ja-hash="2f78689edd39ccffc1a21b979c376f45"><span class=en-original lang=en>This specification defines an API for running scripts in the
173     background independently of any user interface scripts.</span></p>
174    
175     <p class="no-ja-translation" data-ja-hash="f41b6868a33d2c4d265857efdf426694"><span class=en-original lang=en>This allows for long-running scripts that are not interrupted by
176     scripts that respond to clicks or other user interactions, and
177     allows long tasks to be executed without yielding to keep the page
178     responsive.</span></p>
179    
180     <p class="no-ja-translation" data-ja-hash="52e3c8127ee80a92ae3709986b8f2450"><span class=en-original lang=en>Workers (as these background scripts are called herein) are
181     relatively heavy-weight, and are not intended to be used in large
182     numbers. For example, it would be inappropriate to launch one worker
183     for each pixel of a four megapixel image. The examples below show
184     some appropriate uses of workers.</span></p>
185    
186     <p class="no-ja-translation" data-ja-hash="497e60abbf38e141b92f7017f71dc302"><span class=en-original lang=en>Generally, workers are expected to be long-lived, have a high
187     start-up performance cost, and a high per-instance memory cost.</span></p>
188    
189    
190     <h3 id=tutorial class="has-ja-translation" data-ja-hash="368fe771261fcb18f7988833c9294a20"><span class=en-original lang=en><span class=secno>1.2 </span>Tutorial</span><span class=ja-translation lang=ja><span class=secno>1.2 </span>解説</span></h3>
191    
192 wakaba 1.135 <p class="no-ja-translation" data-ja-hash="2b52ab89148ac538f9c9380fc5da5b2f"><span class=en-original lang=en><i>This section is non-normative.</i></span></p>
193 wakaba 1.111
194     <p class="has-ja-translation" data-ja-hash="c98bec741e84294c9feae0d581f897b6"><span class=en-original lang=en>There are a variety of uses that workers can be put to. The
195     following subsections show various examples of this use.</span><span class=ja-translation lang=ja>労働者は色々なことに使えます。次の各節では、色々な使い方の例を示します。</span></p>
196    
197     <h4 id=a-background-number-crunching-worker class="has-ja-translation" data-ja-hash="03100d1ee403be709f47c37e6b55c758"><span class=en-original lang=en><span class=secno>1.2.1 </span>A background number-crunching worker</span><span class=ja-translation lang=ja><span class=secno>1.2.1 </span>数値処理背景労働者</span></h4>
198    
199 wakaba 1.135 <p class="no-ja-translation" data-ja-hash="2b52ab89148ac538f9c9380fc5da5b2f"><span class=en-original lang=en><i>This section is non-normative.</i></span></p>
200 wakaba 1.111
201     <p class="has-ja-translation" data-ja-hash="6656ef1c2fd445878e165388d704a723"><span class=en-original lang=en>The simplest use of workers is for performing a computationally
202     expensive task without interrupting the user interface.</span><span class=ja-translation lang=ja>労働者の一番単純な用法は、計算的に高価な仕事を利用者界面を中断させずに実行するというものです。</span></p>
203    
204 wakaba 1.156 <p class="no-ja-translation" data-ja-hash="5e43c9fa7e36ce901f020c289e77c2b2"><span class=en-original lang=en>In this example, the main document spawns a worker to
205     (naïvely) compute prime numbers, and progressively displays the
206     most recently found prime number.</span></p>
207 wakaba 1.111
208     <p class="has-ja-translation" data-ja-hash="97bcf42c4070cbcef605cfa277d832fb"><span class=en-original lang=en>The main page is as follows:</span><span class=ja-translation lang=ja>主たる頁は次の通りです。</span></p>
209    
210     <pre class="no-ja-translation" data-ja-hash="45b861d46157f155d38040db723bafd1"><span class=en-original lang=en>&lt;!DOCTYPE HTML&gt;
211     &lt;html&gt;
212     &lt;head&gt;
213     &lt;title&gt;Worker example: One-core computation&lt;/title&gt;
214     &lt;/head&gt;
215     &lt;body&gt;
216     &lt;p&gt;The highest prime number discovered so far is: &lt;output id="result"&gt;&lt;/output&gt;&lt;/p&gt;
217     &lt;script&gt;
218     var worker = new Worker('worker.js');
219     worker.onmessage = function (event) {
220     document.getElementById('result').textContent = event.data;
221     };
222     &lt;/script&gt;
223     &lt;/body&gt;
224     &lt;/html&gt;</span></pre>
225    
226     <p class="no-ja-translation" data-ja-hash="64b5d9bd2853f85edab220de5a199787"><span class=en-original lang=en>The <code title=dom-Worker><a href=#dom-worker>Worker()</a></code> constructor call
227     creates a worker and returns a <code><a href=#worker>Worker</a></code> object
228     representing that worker, which is used to communicate with the
229     worker. That object's <code title=handler-Worker-onmessage><a href=#handler-worker-onmessage>onmessage</a></code> event handler
230     attribute allows the code to receive messages from the worker.</span></p>
231    
232     <p class="has-ja-translation" data-ja-hash="12a62a74d5156b6d85136f5fc41a4ee1"><span class=en-original lang=en>The worker itself is as follows:</span><span class=ja-translation lang=ja>労働者自体は次の通りです。</span></p>
233    
234     <pre class="no-ja-translation" data-ja-hash="35390f08d92125ad461fd6bb5969cb0c"><span class=en-original lang=en>var n = 1;
235     search: while (true) {
236     n += 1;
237     for (var i = 2; i &lt;= Math.sqrt(n); i += 1)
238     if (n % i == 0)
239     continue search;
240     // found a prime!
241     postMessage(n);
242     }</span></pre>
243    
244     <p class="no-ja-translation" data-ja-hash="48faeab09946f0578b4b421f4cf0a5db"><span class=en-original lang=en>The bulk of this code is simply an unoptimized search for a prime
245     number. To send a message back to the page, the <code title=dom-DedicatedWorkerGlobalScope-postMessage><a href=#dom-dedicatedworkerglobalscope-postmessage>postMessage()</a></code>
246     method is used to post a message when a prime is found.</span></p>
247    
248     <p class="has-ja-translation" data-ja-hash="add583522732edb8aca6202c451ddb27" data-ja-real-hash="19ee793c62fc7bda7447ccda3a91b44e"><span class=en-original lang=en><a href=http://www.whatwg.org/demos/workers/primes/page.html>View this example online</a>.</span><span class=ja-translation lang=ja><a href=http://www.whatwg.org/demos/workers/primes/page.html>この例をオンラインで表示する</a>。</span></p>
249    
250    
251    
252     <h4 id=a-worker-for-updating-a-client-side-database class="has-ja-translation" data-ja-hash="be08cb921deb5e88f7dcb3edbd9f0274"><span class=en-original lang=en><span class=secno>1.2.2 </span>A worker for updating a client-side database</span><span class=ja-translation lang=ja><span class=secno>1.2.2 </span>クライアント側データベースの更新のための労働者</span></h4>
253    
254 wakaba 1.135 <p class="no-ja-translation" data-ja-hash="2b52ab89148ac538f9c9380fc5da5b2f"><span class=en-original lang=en><i>This section is non-normative.</i></span></p>
255 wakaba 1.111
256     <p class="no-ja-translation" data-ja-hash="e8e4acfb27dabd6fd72aa5a4af7b7d25"><span class=en-original lang=en>In this example, the main document spawns a worker whose only
257     task is to listen for notifications from the server, and, when
258     appropriate, either add or remove data from the client-side
259     database.</span></p>
260    
261     <p class="has-ja-translation" data-ja-hash="88e890f11b614dc40f4d2453a66ec94f"><span class=en-original lang=en>Since no communication occurs between the worker and the main
262     page, the main page can start the worker by just doing:</span><span class=ja-translation lang=ja>労働者と主たる頁の間に通信は発生しませんので、
263     主たる頁は単に次のようにするだけで労働者を開始できます。</span></p>
264    
265     <pre class="no-ja-translation" data-ja-hash="c87d2a32789642a7a7353364dffa7c04"><span class=en-original lang=en>&lt;script&gt;
266     new Worker('worker.js');
267     &lt;/script&gt;</span></pre>
268    
269     <p class="has-ja-translation" data-ja-hash="12a62a74d5156b6d85136f5fc41a4ee1"><span class=en-original lang=en>The worker itself is as follows:</span><span class=ja-translation lang=ja>労働者自体は次の通りです。</span></p>
270    
271     <pre class="no-ja-translation" data-ja-hash="cfd35229b68e597b6a21322a3e3c1aea"><span class=en-original lang=en>var server = new WebSocket('ws://whatwg.org/database');
272     var database = openDatabase('demobase', '1.0', 'Demo Database', 10240);
273     server.onmessage = function (event) {
274     // data is in the format "command key value"
275     var data = event.data.split(' ');
276     switch (data[0]) {
277     case '+':
278     database.transaction(function(tx) {
279     tx.executeSql('INSERT INTO pairs (key, value) VALUES (?, ?)', data[1], data[2]);
280     });
281     case '-':
282     database.transaction(function(tx) {
283     tx.executeSql('DELETE FROM pairs WHERE key=? AND value=?', data[1], data[2]);
284     });
285     }
286     };</span></pre>
287    
288     <p class="no-ja-translation" data-ja-hash="df7990f8fb4ac6850b65c14c08446f5c"><span class=en-original lang=en>This connects to the server using the <code>WebSocket</code>
289     mechanism and opens the local database (which, we presume, has been
290     created earlier). The worker then just listens for messages from the
291     server and acts on them as appropriate, forever (or until the main
292     page is closed).</span></p>
293    
294     <p class="no-ja-translation" data-ja-hash="f0d091179997558acbbf256bd7379b3d"><span class=en-original lang=en><a href=http://www.whatwg.org/demos/workers/database-updater/page.html>View
295     this example online</a>. (This example will not actually function,
296     since the server does not actually exist and the database is not
297     created by this sample code.)</span></p>
298    
299    
300    
301     <h4 id=worker-used-for-background-i/o class="no-ja-translation" data-ja-hash="26a2e24494eb4f94591467b79f68f6f2"><span class=en-original lang=en><span class=secno>1.2.3 </span>Worker used for background I/O</span></h4>
302    
303 wakaba 1.135 <p class="no-ja-translation" data-ja-hash="2b52ab89148ac538f9c9380fc5da5b2f"><span class=en-original lang=en><i>This section is non-normative.</i></span></p>
304 wakaba 1.111
305     <p class="has-ja-translation" data-ja-hash="eb288220a303d56acd4e151bca42fe6e"><span class=en-original lang=en>In this example, the main document uses two workers, one for
306     fetching stock updates for at regular intervals, and one for
307     fetching performing search queries that the user requests.</span><span class=ja-translation lang=ja>この例では、主たる文書は2つの労働者を使います。
308     1つは一定間隔で株価の更新を取得するためのもので、もう1つは利用者の要求した検索の照会を行う取得のためのものです。</span></p>
309    
310     <p class="has-ja-translation" data-ja-hash="97bcf42c4070cbcef605cfa277d832fb"><span class=en-original lang=en>The main page is as follows:</span><span class=ja-translation lang=ja>主たる頁は次の通りです。</span></p>
311    
312     <pre class="no-ja-translation" data-ja-hash="a4e743797f3cad5ba0d0016878e0e28c"><span class=en-original lang=en>&lt;!DOCTYPE HTML&gt;
313     &lt;html&gt;
314     &lt;head&gt;
315     &lt;title&gt;Worker example: Stock ticker&lt;/title&gt;
316     &lt;script&gt;
317     // TICKER
318     var symbol = 'GOOG'; // default symbol to watch
319     var ticker = new Worker('ticker.js');
320    
321     // SEARCHER
322     var searcher = new Worker('searcher.js');
323     function search(query) {
324     searcher.postMessage(query);
325     }
326    
327     // SYMBOL SELECTION UI
328     function select(newSymbol) {
329     symbol = newSymbol;
330     ticker.postMessage(symbol);
331     }
332     &lt;/script&gt;
333     &lt;/head&gt;
334     &lt;body onload="search('')"&gt;
335     &lt;p&gt;&lt;output id="symbol"&gt;&lt;/output&gt; &lt;output id="value"&gt;&lt;/output&gt;&lt;/p&gt;
336     &lt;script&gt;
337     ticker.onmessage = function (event) {
338     var data = event.data.split(' ');
339     document.getElementById('symbol').textContent = data[0];
340     document.getElementById('value').textContent = data[1];
341     };
342     ticker.postMessage(symbol);
343     &lt;/script&gt;
344     &lt;p&gt;&lt;label&gt;Search: &lt;input type="text" autofocus oninput="search(this.value)"&gt;&lt;/label&gt;&lt;/p&gt;
345     &lt;ul id="results"&gt;&lt;/ul&gt;
346     &lt;script&gt;
347     searcher.onmessage = function (event) {
348     var data = event.data.split(' ');
349     var results = document.getElementById('results');
350     while (results.hasChildNodes()) // clear previous results
351     results.removeChild(results.firstChild);
352     for (var i = 0; i &lt; data.length; i += 1) {
353     // add a list item with a button for each result
354     var li = document.createElement('li');
355     var button = document.createElement('button');
356     button.value = data[i];
357     button.type = 'button';
358     button.onclick = function () { select(this.value); };
359     button.textContent = data[i];
360     li.appendChild(button);
361     results.appendChild(li);
362     }
363     };
364     &lt;/script&gt;
365     &lt;p&gt;(The data in this example is not real. Try searching for "Google" or "Apple".)&lt;/p&gt;
366     &lt;/body&gt;
367     &lt;/html&gt;</span></pre>
368    
369     <p class="has-ja-translation" data-ja-hash="4cc7e781e44db82f8bd32020954bb94a"><span class=en-original lang=en>The two workers use a common library for performing the actual
370     network calls. This library is as follows:</span><span class=ja-translation lang=ja>両労働者は実際のネットワークの呼び出しを行う共通のライブラリーを使います。
371     このライブラリーは次の通りです。</span></p>
372    
373     <pre class="no-ja-translation" data-ja-hash="764d750a19834bf904d276466724339c"><span class=en-original lang=en>function get(url) {
374     try {
375     var xhr = new XMLHttpRequest();
376     xhr.open('GET', url, false);
377     xhr.send();
378     return xhr.responseText;
379     } catch (e) {
380     return ''; // turn all errors into empty results
381     }
382     }</span></pre>
383    
384     <p class="has-ja-translation" data-ja-hash="ee10423864c33d68e8676bf88cb75046"><span class=en-original lang=en>The stock updater worker is as follows:</span><span class=ja-translation lang=ja>株価更新者の労働者は次の通りです。</span></p>
385    
386     <pre class="no-ja-translation" data-ja-hash="66ef47eaf421ea8066871b71807859be"><span class=en-original lang=en>importScripts('io.js');
387     var timer;
388     var symbol;
389     function update() {
390     postMessage(symbol + ' ' + get('stock.cgi?' + symbol));
391     timer = setTimeout(update, 10000);
392     }
393     onmessage = function (event) {
394     if (timer)
395     clearTimeout(timer);
396     symbol = event.data;
397     update();
398     };</span></pre>
399    
400     <p class="has-ja-translation" data-ja-hash="aa6a78ceb7b91cdf90925cc36c6c6676"><span class=en-original lang=en>The search query worker is as follows:</span><span class=ja-translation lang=ja>検索の照会の労働者は次の通りです。</span></p>
401    
402     <pre class="no-ja-translation" data-ja-hash="ac0353e2a69ae5ffdc861cca404ef9f0"><span class=en-original lang=en>importScripts('io.js');
403     onmessage = function (event) {
404     postMessage(get('search.cgi?' + event.data));
405     };</span></pre>
406    
407     <p class="has-ja-translation" data-ja-hash="add583522732edb8aca6202c451ddb27" data-ja-real-hash="5855651f68b535b77cb2b82bed593472"><span class=en-original lang=en><a href=http://www.whatwg.org/demos/workers/stocks/page.html>View this example online</a>.</span><span class=ja-translation lang=ja><a href=http://www.whatwg.org/demos/workers/stocks/page.html>この例をオンラインで表示する</a>。</span></p>
408    
409    
410     <h4 id=shared-workers class="has-ja-translation" data-ja-hash="634755c2f50b08b49a82f30428b1a961"><span class=en-original lang=en><span class=secno>1.2.4 </span>Shared workers</span><span class=ja-translation lang=ja><span class=secno>1.2.4 </span>共有労働者</span></h4>
411    
412 wakaba 1.135 <p class="no-ja-translation" data-ja-hash="2b52ab89148ac538f9c9380fc5da5b2f"><span class=en-original lang=en><i>This section is non-normative.</i></span></p>
413 wakaba 1.111
414     <p class="no-ja-translation" data-ja-hash="2ec2b66f1e8130c8e0552d348a633841"><span class=en-original lang=en>In this example, multiple windows (viewers) can be opened that
415     are all viewing the same map. All the windows share the same map
416     information, with a single worker coordinating all the viewers. Each
417     viewer can move around independently, but if they set any data on
418     the map, all the viewers are updated.</span></p>
419    
420     <p class="has-ja-translation" data-ja-hash="2bf6969d7d27e56c707ae9970fdd476f"><span class=en-original lang=en>The main page isn't interesting, it merely provides a way to open
421     the viewers:</span><span class=ja-translation lang=ja>主たる頁は特に何もなく、単に表示器を開くためだけのものです。</span></p>
422    
423     <pre class="no-ja-translation" data-ja-hash="e27ef9096d7661be60af654b55813524"><span class=en-original lang=en>&lt;!DOCTYPE HTML&gt;
424     &lt;html&gt;
425     &lt;head&gt;
426     &lt;title&gt;Workers example: Multiviewer&lt;/title&gt;
427     &lt;script&gt;
428     function openViewer() {
429     window.open('viewer.html');
430     }
431     &lt;/script&gt;
432     &lt;/head&gt;
433     &lt;body&gt;
434     &lt;p&gt;&lt;button type=button onclick="openViewer()"&gt;Open a new
435     viewer&lt;/button&gt;&lt;/p&gt;
436     &lt;p&gt;Each viewer opens in a new window. You can have as many viewers
437     as you like, they all view the same data.&lt;/p&gt;
438     &lt;/body&gt;
439     &lt;/html&gt;</span></pre>
440    
441     <p class="has-ja-translation" data-ja-hash="cee02afe1e87e7182f5219ccf54757ca"><span class=en-original lang=en>The viewer is more involved:</span><span class=ja-translation lang=ja>表示器はもっと色々しています。</span></p>
442    
443     <pre class="no-ja-translation" data-ja-hash="6f90bb09ab3ecf0dc089f72f0f7bf32b"><span class=en-original lang=en>&lt;!DOCTYPE HTML&gt;
444     &lt;html&gt;
445     &lt;head&gt;
446     &lt;title&gt;Workers example: Multiviewer viewer&lt;/title&gt;
447     &lt;script&gt;
448     var worker = new SharedWorker('worker.js', 'core');
449    
450     // CONFIGURATION
451     function configure(event) {
452     if (event.data.substr(0, 4) != 'cfg ') return;
453     var name = event.data.substr(4).split(' ', 1);
454     // update display to mention our name is name
455     document.getElementsByTagName('h1')[0].textContent += ' ' + name;
456     // no longer need this listener
457     worker.port.removeEventListener('message', configure, false);
458     }
459     worker.port.addEventListener('message', configure, false);
460    
461     // MAP
462     function paintMap(event) {
463     if (event.data.substr(0, 4) != 'map ') return;
464     var data = event.data.substr(4).split(',');
465     // display tiles data[0] .. data[8]
466     var canvas = document.getElementById('map');
467     var context = canvas.getContext('2d');
468     for (var y = 0; y &lt; 3; y += 1) {
469     for (var x = 0; x &lt; 3; x += 1) {
470     var tile = data[y * 3 + x];
471     if (tile == '0')
472     context.fillStyle = 'green';
473     else
474     context.fillStyle = 'maroon';
475     fillRect(x * 50, y * 50, 50, 50);
476     }
477     }
478     }
479     worker.port.addEventListener('message', paintMap, false);
480    
481     // PUBLIC CHAT
482     function updatePublicChat(event) {
483     if (event.data.substr(0, 4) != 'txt ') return;
484     var name = event.data.substr(4).split(' ', 1);
485     var message = event.data.substr(4 + length(name) + 1);
486     // display "&lt;name&gt; message" in public chat
487     var dialog = document.getElementById('public');
488     var dt = document.createElement('dt');
489     dt.textContent = name;
490     dialog.appendChild(dt);
491     var dd = document.createElement('dd');
492     dd.textContent = message;
493     dialog.appendChild(dd);
494     }
495     worker.port.addEventListener('message', updatePublicChat, false);
496    
497     // PRIVATE CHAT
498     function startPrivateChat(event) {
499     if (event.data.substr(0, 4) != 'msg ') return;
500     var name = event.data.substr(4).split(' ', 1);
501     var port = event.ports[0];
502     // display a private chat UI
503     var ul = document.getElementById('private');
504     var li = document.createElement('li');
505     var h3 = document.createElement('h3');
506     h3.textContent = 'Private chat with ' + name;
507     li.appendChild(h3);
508     var dialog = document.createElement('dialog');
509     var addMessage = function(name, message) {
510     var dt = document.createElement('dt');
511     dt.textContent = name;
512     dialog.appendChild(dt);
513     var dd = document.createElement('dd');
514     dd.textContent = message;
515     dialog.appendChild(dd);
516     };
517     port.onmessage = function (event) {
518     addMessage(name, event.data);
519     };
520     li.appendChild(dialog);
521     var form = document.createElement('form');
522     var p = document.createElement('p');
523     var input = document.createElement('input');
524     input.size = 50;
525     p.appendChild(input);
526     p.appendChild(document.createTextNode(' '));
527     var button = document.createElement('button');
528     button.textContent = 'Post';
529     p.appendChild(button);
530     form.onsubmit = function () {
531     port.postMessage(input.value);
532     addMessage('me', input.value);
533     input.value = '';
534     return false;
535     };
536     form.appendChild(p);
537     li.appendChild(form);
538     }
539     worker.port.addEventListener('message', startPrivateChat, false);
540     &lt;/script&gt;
541     &lt;/head&gt;
542     &lt;body&gt;
543     &lt;h1&gt;Viewer&lt;/h1&gt;
544     &lt;h2&gt;Map&lt;/h2&gt;
545     &lt;p&gt;&lt;canvas id="map" height=150 width=150&gt;&lt;/canvas&gt;&lt;/p&gt;
546     &lt;p&gt;
547     &lt;button type=button onclick="worker.port.postMessage('mov left')"&gt;Left&lt;/button&gt;
548     &lt;button type=button onclick="worker.port.postMessage('mov up')"&gt;Up&lt;/button&gt;
549     &lt;button type=button onclick="worker.port.postMessage('mov down')"&gt;Down&lt;/button&gt;
550     &lt;button type=button onclick="worker.port.postMessage('mov right')"&gt;Right&lt;/button&gt;
551     &lt;button type=button onclick="worker.port.postMessage('set 0')"&gt;Set 0&lt;/button&gt;
552     &lt;button type=button onclick="worker.port.postMessage('set 1')"&gt;Set 1&lt;/button&gt;
553     &lt;/p&gt;
554     &lt;h2&gt;Public Chat&lt;/h2&gt;
555     &lt;dialog id="public"&gt;&lt;/dialog&gt;
556     &lt;form onsubmit="worker.port.postMessage('txt ' + message.value); message.value = ''; return false;"&gt;
557     &lt;p&gt;
558     &lt;input type="text" name="message" size="50"&gt;
559     &lt;button&gt;Post&lt;/button&gt;
560     &lt;/p&gt;
561     &lt;/form&gt;
562     &lt;h2&gt;Private Chat&lt;/h2&gt;
563     &lt;ul id="private"&gt;&lt;/ul&gt;
564     &lt;/body&gt;
565     &lt;/html&gt;
566     </span></pre>
567    
568     <p class="has-ja-translation" data-ja-hash="397850dab731150b72d5f0276dab0081"><span class=en-original lang=en>There are several key things worth noting about the way the
569     viewer is written.</span><span class=ja-translation lang=ja>表示器の書き方についていくつか注意したい重要な点があります。</span></p>
570    
571     <p class="has-ja-translation" data-ja-hash="8bc9c1f9e0e102128838ea8c31c51306"><span class=en-original lang=en><strong>Multiple listeners</strong>. Instead of a single message
572     processing function, the code here attaches multiple event
573     listeners, each one performing a quick check to see if it is
574     relevant for the message. In this example it doesn't make much
575     difference, but if multiple authors wanted to collaborate using a
576     single port to communicate with a worker, it would allow for
577     independent code instead of changes having to all be made to a
578     single event handling function.</span><span class=ja-translation lang=ja><strong>複数の聴取器</strong>。この符号では、メッセージ処理関数を1つ用意する代わりに、
579     複数の事象聴取器を付与し、それぞれが、それがメッセージに関連するかどうかを見るためにさらりと検査を行っています。
580     この例では大きな違いにはなりませんが、複数の著者が労働者と通信するために1つのポートを使って協調したい場合には、
581     独立した符号にできるので変更がある度に1つの事象取扱関数をいじらざるを得なくて済みます。</span></p>
582    
583     <p class="no-ja-translation" data-ja-hash="ce2f17c1c25589a0d4507c6fa9c1f532"><span class=en-original lang=en>Registering event listeners in this way also allows you to
584     unregister specific listeners when you are done with them, as is
585     done with the <code title="">configure()</code> method in this
586     example.</span></p>
587    
588     <p class="has-ja-translation" data-ja-hash="4eb1fa2095f65662225da4c52db274f1"><span class=en-original lang=en>Finally, the worker:</span><span class=ja-translation lang=ja>最後に、労働者は次のようになります。</span></p>
589    
590 wakaba 1.156 <pre class="no-ja-translation" data-ja-hash="2a6833ffcfe9252a21a8582ad69a4adf"><span class=en-original lang=en>var nextName = 0;
591 wakaba 1.111 function getNextName() {
592     // this could use more friendly names
593     // but for now just return a number
594     return nextName++;
595     }
596    
597     var map = [
598     [0, 0, 0, 0, 0, 0, 0],
599     [1, 1, 0, 1, 0, 1, 1],
600     [0, 1, 0, 1, 0, 0, 0],
601     [0, 1, 0, 1, 0, 1, 1],
602     [0, 0, 0, 1, 0, 0, 0],
603     [1, 0, 0, 1, 1, 1, 1],
604     [1, 1, 0, 1, 1, 0, 1],
605     ];
606    
607     function wrapX(x) {
608     if (x &lt; 0) return wrapX(x + map[0].length);
609     if (x &gt;= map[0].length) return wrapX(x - map[0].length);
610     return x;
611     }
612    
613     function wrapY(y) {
614     if (y &lt; 0) return wrapY(y + map.length);
615     if (y &gt;= map[0].length) return wrapY(y - map.length);
616     return y;
617     }
618    
619     function sendMapData(callback) {
620     var data = '';
621     for (var y = viewer.y-1; y &lt;= viewer.y+1; y += 1) {
622     for (var x = viewer.x-1; x &lt;= viewer.x+1; x += 1) {
623     if (data != '')
624     data += ',';
625     data += map[y][x];
626     }
627     }
628     callback('map ' + data);
629     }
630    
631     var viewers = {};
632     onconnect = function (event) {
633     event.ports[0]._name = getNextName();
634     event.ports[0]._data = { port: event.port, x: 0, y: 0, };
635     viewers[event.ports[0]._name] = event.port._data;
636     event.ports[0].postMessage('cfg ' + name);
637     event.ports[0].onmessage = getMessage;
638     sendMapData(event.ports[0].postMessage);
639     };
640    
641     function getMessage(event) {
642     switch (event.data.substr(0, 4)) {
643     case 'mov ':
644     var direction = event.data.substr(4);
645     var dx = 0;
646     var dy = 0;
647     switch (direction) {
648     case 'up': dy = -1; break;
649     case 'down': dy = 1; break;
650     case 'left': dx = -1; break;
651     case 'right': dx = 1; break;
652     }
653     event.target._data.x = wrapX(event.target._data.x + dx);
654     event.target._data.y = wrapY(event.target._data.y + dy);
655     sendMapData(event.target.postMessage);
656     break;
657     case 'set ':
658     var value = event.data.substr(4);
659     map[event.target._data.y][event.target._data.x] = value;
660     for (var viewer in viewers)
661     sendMapData(viewers[viewer].port.postMessage);
662     break;
663     case 'txt ':
664     var name = event.target._name;
665     var message = event.data.substr(4);
666     for (var viewer in viewers)
667     viewers[viewer].port.postMessage('txt ' + name + ' ' + message);
668     break;
669     case 'msg ':
670     var party1 = event._data;
671     var party2 = viewers[event.data.substr(4).split(' ', 1)];
672     if (party2) {
673     var channel = new MessageChannel();
674     party1.port.postMessage('msg ' + party2.name, [channel.port1]);
675     party2.port.postMessage('msg ' + party1.name, [channel.port2]);
676     }
677     break;
678     }
679     }</span></pre>
680    
681     <p class="no-ja-translation" data-ja-hash="80f59a8dae1df6b25c537e5041683f5d"><span class=en-original lang=en><strong>Connecting to multiple pages</strong>. The script uses
682     the <code title=handler-SharedWorkerGlobalScope-onconnect><a href=#handler-sharedworkerglobalscope-onconnect>onconnect</a></code>
683     event listener to listen for multiple connections.</span></p>
684    
685     <p class="has-ja-translation" data-ja-hash="5ce666b6338718b46fb0dee22dbea88c"><span class=en-original lang=en><strong>Direct channels</strong>. When the worker receives a
686     "msg" message from one viewer naming another viewer, it sets up a
687     direct connection between the two, so that the two viewers can
688     communicate directly without the worker having to proxy all the
689     messages.</span><span class=ja-translation lang=ja><strong>直接通信路</strong>。労働者がある閲覧器から他の閲覧器を名指した「msg」メッセージを受信した時は、
690     両者間の直接の接続を設定し、労働者がすべてのメッセージを仲介せずとも両閲覧器が直接通信できるようにします。</span></p>
691    
692     <p class="has-ja-translation" data-ja-hash="add583522732edb8aca6202c451ddb27" data-ja-real-hash="8d892cfe0423f9a15e275e47c6b45600"><span class=en-original lang=en><a href=http://www.whatwg.org/demos/workers/multiviewer/page.html>View this example online</a>.</span><span class=ja-translation lang=ja><a href=http://www.whatwg.org/demos/workers/multiviewer/page.html>この例をオンラインで表示する</a>。</span></p>
693    
694    
695     <h4 id=delegation class="has-ja-translation" data-ja-hash="57b11d3816e9f83adb4dd2ecb2a311b5"><span class=en-original lang=en><span class=secno>1.2.5 </span>Delegation</span><span class=ja-translation lang=ja><span class=secno>1.2.5 </span>委譲</span></h4>
696    
697 wakaba 1.135 <p class="no-ja-translation" data-ja-hash="2b52ab89148ac538f9c9380fc5da5b2f"><span class=en-original lang=en><i>This section is non-normative.</i></span></p>
698 wakaba 1.111
699     <p class="no-ja-translation" data-ja-hash="318b797bf0c9a2cdaa476f36993911b4"><span class=en-original lang=en>With multicore CPUs becoming prevalent, one way to obtain better
700     performance is to split computationally expensive tasks amongst
701     multiple workers. In this example, a computationally expensive task
702     that is to be performed for every number from 1 to 10,000,000 is
703     farmed out to ten subworkers.</span></p>
704    
705     <p class="has-ja-translation" data-ja-hash="c5074121435848ef6ad420f030cb5060"><span class=en-original lang=en>The main page is as follows, it just reports the result:</span><span class=ja-translation lang=ja>主たる頁は次の通りで、単に結果を報告するだけです。</span></p>
706    
707     <pre class="no-ja-translation" data-ja-hash="45b861d46157f155d38040db723bafd1"><span class=en-original lang=en>&lt;!DOCTYPE HTML&gt;
708     &lt;html&gt;
709     &lt;head&gt;
710     &lt;title&gt;Worker example: One-core computation&lt;/title&gt;
711     &lt;/head&gt;
712     &lt;body&gt;
713     &lt;p&gt;The highest prime number discovered so far is: &lt;output id="result"&gt;&lt;/output&gt;&lt;/p&gt;
714     &lt;script&gt;
715     var worker = new Worker('worker.js');
716     worker.onmessage = function (event) {
717     document.getElementById('result').textContent = event.data;
718     };
719     &lt;/script&gt;
720     &lt;/body&gt;
721     &lt;/html&gt;</span></pre>
722    
723     <p class="has-ja-translation" data-ja-hash="12a62a74d5156b6d85136f5fc41a4ee1"><span class=en-original lang=en>The worker itself is as follows:</span><span class=ja-translation lang=ja>労働者自体は次の通りです。</span></p>
724    
725     <pre class="no-ja-translation" data-ja-hash="c2f14df3c3648ecb143c9e271b6721df"><span class=en-original lang=en>// settings
726     var num_workers = 10;
727     var items_per_worker = 1000000;
728    
729     // start the workers
730     var result = 0;
731     var pending_workers = num_workers;
732     for (var i = 0; i &lt; num_workers; i += 1) {
733     var worker = new Worker('core.js');
734     worker.postMessage(i * items_per_worker);
735     worker.postMessage((i+1) * items_per_worker);
736     worker.onmessage = storeResult;
737     }
738    
739     // handle the results
740     function storeResult(event) {
741     result += 1*event.data;
742     pending_workers -= 1;
743     if (pending_workers &lt;= 0)
744     postMessage(result); // finished!
745     }</span></pre>
746    
747     <p class="has-ja-translation" data-ja-hash="f9236b42d2a99d988b848353511797fc"><span class=en-original lang=en>It consists of a loop to start the subworkers, and then a handler
748     that waits for all the subworkers to respond.</span><span class=ja-translation lang=ja>これは部分労働者を開始するループと、
749     すべての部分労働者が応答するのを待つ取扱器から成っています。</span></p>
750    
751     <p class="has-ja-translation" data-ja-hash="53f3483f6fffa25f7c6963e58d683f43"><span class=en-original lang=en>The subworkers are implemented as follows:</span><span class=ja-translation lang=ja>部分労働者は次のように実装します。</span></p>
752    
753     <pre class="no-ja-translation" data-ja-hash="90fc569c1c634a87b725ebbe4cc1e2f4"><span class=en-original lang=en>var start;
754     onmessage = getStart;
755     function getStart(event) {
756     start = 1*event.data;
757     onmessage = getEnd;
758     }
759    
760     var end;
761     function getEnd(event) {
762     end = 1*event.data;
763     onmessage = null;
764     work();
765     }
766    
767     function work() {
768     var result = 0;
769     for (var i = start; i &lt; end; i += 1) {
770     // perform some complex calculation here
771     result += 1;
772     }
773     postMessage(result);
774     close();
775     }</span></pre>
776    
777     <p class="has-ja-translation" data-ja-hash="fbf1b083b03c85854a8e892ef8add172"><span class=en-original lang=en>They receive two numbers in two events, perform the computation
778     for the range of numbers thus specified, and then report the result
779     back to the parent.</span><span class=ja-translation lang=ja>部分労働者は2つの事象で2つの数を受信し、指定された数の範囲の計算を行った後、
780     結果を親に報告します。
781     </span></p>
782    
783     <p class="has-ja-translation" data-ja-hash="add583522732edb8aca6202c451ddb27" data-ja-real-hash="4318fb9a581a7c14e58bfb2d61809f0c"><span class=en-original lang=en><a href=http://www.whatwg.org/demos/workers/multicore/page.html>View this example online</a>.</span><span class=ja-translation lang=ja><a href=http://www.whatwg.org/demos/workers/multicore/page.html>この例をオンラインで表示する</a>。</span></p>
784    
785    
786     <h4 id=providing-libraries class="has-ja-translation" data-ja-hash="6c37218e175bff77f69bd84b1ab5da58"><span class=en-original lang=en><span class=secno>1.2.6 </span>Providing libraries</span><span class=ja-translation lang=ja><span class=secno>1.2.6 </span>ライブラリーの提供</span></h4>
787    
788 wakaba 1.135 <p class="no-ja-translation" data-ja-hash="2b52ab89148ac538f9c9380fc5da5b2f"><span class=en-original lang=en><i>This section is non-normative.</i></span></p>
789 wakaba 1.111
790     <p class="no-ja-translation" data-ja-hash="12371907fb7e8389f76fabaf7a5f8303"><span class=en-original lang=en>Suppose that a cryptography library is made available that
791     provides three tasks:</span></p>
792    
793 wakaba 1.156 <dl>
794    
795     <dt class="has-ja-translation" data-ja-hash="6ea027035e660e254aba77f4bd9cb6e7"><span class=en-original lang=en>Generate a public/private key pair</span><span class=ja-translation lang=ja>公開鍵・秘密鍵の組の生成</span></dt>
796 wakaba 1.111
797     <dd class="no-ja-translation" data-ja-hash="cf9020803baa896d8a183fe324563704"><span class=en-original lang=en>Takes a port, on which it will send two messages, first the
798     public key and then the private key.</span></dd>
799    
800     <dt class="no-ja-translation" data-ja-hash="fb7dd035a8141087578088ce61f9db22"><span class=en-original lang=en>Given a plaintext and a public key, return the corresponding cyphertext</span></dt>
801    
802     <dd class="no-ja-translation" data-ja-hash="1d31efc883e22a218f807161c65291f0"><span class=en-original lang=en>Takes a port, to which any number of messages can be sent, the
803     first giving the public key, and the remainder giving the
804     plaintext, each of which is encrypted and then sent on that same
805     channel as the cyphertext. The user can close the port when it is
806     done encrypting content.</span></dd>
807    
808     <dt class="no-ja-translation" data-ja-hash="11ea02c6f203744166e5a89e81a81337"><span class=en-original lang=en>Given a cyphertext and a private key, return the corresponding plaintext</span></dt>
809    
810     <dd class="no-ja-translation" data-ja-hash="c157fe0e540c248dc1db29edbd80ff82"><span class=en-original lang=en>Takes a port, to which any number of messages can be sent, the
811     first giving the private key, and the remainder giving the
812     cyphertext, each of which is decrypted and then sent on that same
813     channel as the plaintext. The user can close the port when it is
814     done decrypting content.</span></dd>
815    
816 wakaba 1.156 </dl>
817    
818     <p class="has-ja-translation" data-ja-hash="0e39ac88e71e60206c341926e3785dcd"><span class=en-original lang=en>The library itself is as follows:</span><span class=ja-translation lang=ja>ライブラリー自体は次のようになります。</span></p>
819 wakaba 1.111
820     <pre class="no-ja-translation" data-ja-hash="6c23fb6fef8f715101d908de56f2cb63"><span class=en-original lang=en>function handleMessage(e) {
821     if (e.data == "genkeys")
822     genkeys(e.ports[0]);
823     else if (e.data == "encrypt")
824     encrypt(e.ports[0]);
825     else if (e.data == "decrypt")
826     decrypt(e.ports[0]);
827     }
828    
829     function genkeys(p) {
830     var keys = _generateKeyPair();
831     p.postMessage(keys[0]);
832     p.postMessage(keys[1]);
833     }
834    
835     function encrypt(p) {
836     var key, state = 0;
837     p.onmessage = function (e) {
838     if (state == 0) {
839     key = e.data;
840     state = 1;
841     } else {
842     p.postMessage(_encrypt(key, e.data));
843     }
844     };
845     }
846    
847     function decrypt(p) {
848     var key, state = 0;
849     p.onmessage = function (e) {
850     if (state == 0) {
851     key = e.data;
852     state = 1;
853     } else {
854     p.postMessage(_decrypt(key, e.data));
855     }
856     };
857     }
858    
859     // support being used as a shared worker as well as a dedicated worker
860     if (this.onmessage) // dedicated worker
861     onmessage = handleMessage;
862     else // shared worker
863     onconnect = function (e) { e.port.onmessage = handleMessage; }
864    
865    
866     // the "crypto" functions:
867    
868     function _generateKeyPair() {
869     return [Math.random(), Math.random()];
870     }
871    
872     function _encrypt(k, s) {
873     return 'encrypted-' + k + ' ' + s;
874     }
875    
876     function _decrypt(k, s) {
877     return s.substr(s.indexOf(' ')+1);
878     }</span></pre>
879    
880     <p class="no-ja-translation" data-ja-hash="e6e3003b829ed060f5926d1763f29c2e"><span class=en-original lang=en>Note that the crypto functions here are just stubs and don't do
881     real cryptography.</span></p>
882    
883     <p class="has-ja-translation" data-ja-hash="76f1d5866d92bc1036d1198cf4eda428"><span class=en-original lang=en>This library could be used as follows:</span><span class=ja-translation lang=ja>このライブラリーは次のように使うことができます。</span></p>
884    
885     <pre class="no-ja-translation" data-ja-hash="e88a411ca9b20f088116732dc0db6171"><span class=en-original lang=en>&lt;!DOCTYPE HTML&gt;
886     &lt;html&gt;
887     &lt;head&gt;
888     &lt;title&gt;Worker example: Crypto library&lt;/title&gt;
889     &lt;script&gt;
890     var crytoLib = new Worker('libcrypto-v1.js'); // or could use 'libcrypto-v2.js'
891     function getKeys() {
892     var state = 0;
893     cryptoLib.startConversation("genkeys").onmessage = function (e) {
894     if (state == 0)
895     document.getElementById('public').value = e.data;
896     else if (state == 1)
897     document.getElementById('private').value = e.data;
898     state += 1;
899     };
900     }
901     function enc() {
902     var port = cryptoLib.startConversation("encrypt");
903     port.postMessage(document.getElementById('public').value);
904     port.postMessage(document.getElementById('input').value);
905     port.onmessage = function (e) {
906     document.getElementById('input').value = e.data;
907     port.close();
908     };
909     }
910     function dec() {
911     var port = cryptoLib.startConversation("decrypt");
912     port.postMessage(document.getElementById('private').value);
913     port.postMessage(document.getElementById('input').value);
914     port.onmessage = function (e) {
915     document.getElementById('input').value = e.data;
916     port.close();
917     };
918     }
919     &lt;/script&gt;
920     &lt;style&gt;
921     textarea { display: block; }
922     &lt;/style&gt;
923     &lt;/head&gt;
924     &lt;body onload="getKeys()"&gt;
925     &lt;fieldset&gt;
926     &lt;legend&gt;Keys&lt;/legend&gt;
927     &lt;p&gt;&lt;label&gt;Public Key: &lt;textarea id="public"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
928     &lt;p&gt;&lt;label&gt;Private Key: &lt;textarea id="private"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
929     &lt;/fieldset&gt;
930     &lt;p&gt;&lt;label&gt;Input: &lt;textarea id="input"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
931     &lt;p&gt;&lt;button onclick="enc()"&gt;Encrypt&lt;/button&gt; &lt;button onclick="dec()"&gt;Decrypt&lt;/button&gt;&lt;/p&gt;
932     &lt;/body&gt;
933     &lt;/html&gt;</span></pre>
934    
935     <p class="no-ja-translation" data-ja-hash="13181de825fa0e152c5a954e55715a15"><span class=en-original lang=en>A later version of the API, though, might want to offload all the
936     crypto work onto subworkers. This could be done as follows:</span></p>
937    
938     <pre class="no-ja-translation" data-ja-hash="4700bd96e4f3524347953c148b483479"><span class=en-original lang=en>function handleMessage(e) {
939     if (e.data == "genkeys")
940     genkeys(e.ports[0]);
941     else if (e.data == "encrypt")
942     encrypt(e.ports[0]);
943     else if (e.data == "decrypt")
944     decrypt(e.ports[0]);
945     }
946    
947     function genkeys(p) {
948     var generator = new Worker('libcrypto-v2-generator.js');
949     generator.postMessage('', [p]);
950     }
951    
952     function encrypt(p) {
953     p.onmessage = function (e) {
954     var key = e.data;
955     var encryptor = new Worker('libcrypto-v2-encryptor.js');
956     encryptor.postMessage(key, [p]);
957     };
958     }
959    
960     function encrypt(p) {
961     p.onmessage = function (e) {
962     var key = e.data;
963     var decryptor = new Worker('libcrypto-v2-decryptor.js');
964     decryptor.postMessage(key, [p]);
965     };
966     }
967    
968     // support being used as a shared worker as well as a dedicated worker
969     if (this.onmessage) // dedicated worker
970     onmessage = handleMessage;
971     else // shared worker
972     onconnect = function (e) { e.ports[0].onmessage = handleMessage };
973     </span></pre>
974    
975     <p class="has-ja-translation" data-ja-hash="fc1d14c413a94a9015153067739845e7"><span class=en-original lang=en>The little subworkers would then be as follows.</span><span class=ja-translation lang=ja>小部分労働者は次の通りです。</span></p>
976    
977     <p class="has-ja-translation" data-ja-hash="66f9c4d246b0081919ced7e46c4a9db2"><span class=en-original lang=en>For generating key pairs:</span><span class=ja-translation lang=ja>鍵組の生成用:</span></p>
978    
979     <pre class="no-ja-translation" data-ja-hash="7fcbde64ee437c101414bcc98d9e1ee0"><span class=en-original lang=en>onmessage = function (e) {
980     var k = _generateKeyPair();
981     e.ports[0].postMessage(k[0]);
982     e.ports[0].postMessage(k[1]);
983     close();
984     }
985    
986     function _generateKeyPair() {
987     return [Math.random(), Math.random()];
988     }</span></pre>
989    
990     <p class="has-ja-translation" data-ja-hash="1f07f24df05f20de47483db4dfde2017"><span class=en-original lang=en>For encrypting:</span><span class=ja-translation lang=ja>暗号化用:</span></p>
991    
992     <pre class="no-ja-translation" data-ja-hash="94aaf906f90e9b3539c4219ef2be60cf"><span class=en-original lang=en>onmessage = function (e) {
993     var key = e.data;
994     e.ports[0].onmessage = function (e) {
995     var s = e.data;
996     postMessage(_encrypt(key, s));
997     }
998     }
999    
1000     function _encrypt(k, s) {
1001     return 'encrypted-' + k + ' ' + s;
1002     }</span></pre>
1003    
1004     <p class="has-ja-translation" data-ja-hash="abf884f40593747f458e7d7400b1eb21"><span class=en-original lang=en>For decrypting:</span><span class=ja-translation lang=ja>解読用:</span></p>
1005    
1006     <pre class="no-ja-translation" data-ja-hash="c91e2f3055da293b534ac3c10648b23e"><span class=en-original lang=en>onmessage = function (e) {
1007     var key = e.data;
1008     e.ports[0].onmessage = function (e) {
1009     var s = e.data;
1010     postMessage(_decrypt(key, s));
1011     }
1012     }
1013    
1014     function _decrypt(k, s) {
1015     return s.substr(s.indexOf(' ')+1);
1016     }</span></pre>
1017    
1018 wakaba 1.156 <p class="no-ja-translation" data-ja-hash="4717fab8e5897d153b74cf80c9e4bde3"><span class=en-original lang=en>Notice how the users of the API don't have to even know that this
1019     is happening — the API hasn't changed; the library can
1020 wakaba 1.111 delegate to subworkers without changing its API, even though it is
1021     accepting data using message channels.</span></p>
1022    
1023     <p class="has-ja-translation" data-ja-hash="add583522732edb8aca6202c451ddb27" data-ja-real-hash="22a665d401474bea0ab24f5873ba4d61"><span class=en-original lang=en><a href=http://www.whatwg.org/demos/workers/crypto/page.html>View this example online</a>.</span><span class=ja-translation lang=ja><a href=http://www.whatwg.org/demos/workers/crypto/page.html>この例をオンラインで表示する</a>。</span></p>
1024    
1025    
1026    
1027    
1028     <h2 id=conformance-requirements class="has-ja-translation" data-ja-hash="05644f41fb2fbf61aaab52464b2edf3b"><span class=en-original lang=en><span class=secno>2 </span>Conformance requirements</span><span class=ja-translation lang=ja><span class=secno>2 </span>適合性要件</span></h2>
1029    
1030     <p class="has-ja-translation" data-ja-hash="8b0f72fe04577949924ab1e2997e0d8b"><span class=en-original lang=en>All diagrams, examples, and notes in this specification are
1031     non-normative, as are all sections explicitly marked non-normative.
1032     Everything else in this specification is normative.</span><span class=ja-translation lang=ja>この仕様書のすべての図、例示、注意書き、ならびに規定の一部ではないと明記したすべての節は、
1033     規定の一部ではありません。
1034     この仕様書のそれ以外の部分はすべて規定の一部です。</span></p>
1035    
1036     <p class="has-ja-translation" data-ja-hash="8adc9958d29b879426b71b5b9eae46db"><span class=en-original lang=en>The key words "MUST", "MUST NOT", "REQUIRED", <!--"SHALL", "SHALL
1037     NOT",--> "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
1038     "OPTIONAL" in the normative parts of this document are to be
1039     interpreted as described in RFC2119. For readability, these words do
1040     not appear in all uppercase letters in this specification. <a href=#refsRFC2119>[RFC2119]</a></span><span class=ja-translation lang=ja>この文書の規定の部分にあるキーワード「<em class=rfc2119 title="MUST">しなければなりません</em>」、
1041     「<em class=rfc2119 title="MUST NOT">してはなりません</em>」、
1042     「<em class=rfc2119 title="REQUIRED">必須です</em>」、<!--"SHALL", "SHALL
1043     NOT",-->「<em class=rfc2119 title="SHOULD">するべきです</em>」、
1044     「<em class=rfc2119 title="SHOULD NOT">するべきではありません</em>」、
1045     「<em class=rfc2119 title="RECOMMENDED">推奨します</em>」、「<em class=rfc2119 title="MAY">して構いません</em>」、
1046     「<em class=rfc2119 title="OPTIONAL">任意です</em>」は、 RFC 2119 で説明されているように解釈します。
1047     この仕様書<ins class=ja-note>の原文</ins>では、
1048     可読性の観点から、
1049     これらの語<ins class=ja-note>の原語</ins>のすべて大文字による表記は行っていません。
1050     <a href=#refsRFC2119>[RFC2119]</a></span></p>
1051    
1052     <p class="has-ja-translation" data-ja-hash="63dc4357c416e0e0f292a5f662ca71ab"><span class=en-original lang=en>Requirements phrased in the imperative as part of algorithms
1053     (such as "strip any leading space characters" or "return false and
1054     abort these steps") are to be interpreted with the meaning of the
1055     key word ("must", "should", "may", etc) used in introducing the
1056     algorithm.</span><span class=ja-translation lang=ja>算法の一部として<ins class=ja-note>動作の指示の形で (原文では</ins>命令形で<ins class=ja-note>) </ins>記述された要件
1057     (例えば「先頭の間隔文字をすべて除去します」や「偽を返し、これらの段階を停止します」)
1058     は、算法を紹介するに当たって使われたキーワード (<em class=rfc2119 title="MUST">しなければなりません</em>、
1059     <em class=rfc2119 title="SHOULD">するべきです</em>、<em class=rfc2119 title="MAY">して構いません</em>など) の意味により解釈します。</span></p>
1060    
1061     <p class="has-ja-translation" data-ja-hash="a5a0db584980ce3f2448983d6188b2d1"><span class=en-original lang=en>Some conformance requirements are phrased as requirements on
1062     attributes, methods or objects. Such requirements are to be
1063     interpreted as requirements on user agents.</span><span class=ja-translation lang=ja>いくつかの適合性要件は属性やメソッドやオブジェクトの要件として説明されています。
1064     そのような要件は、利用者エージェントに関する要件として解釈します。</span></p>
1065    
1066     <p class="has-ja-translation" data-ja-hash="27386c326b98d878b3c408c60b6095b0"><span class=en-original lang=en>Conformance requirements phrased as algorithms or specific steps
1067     may be implemented in any manner, so long as the end result is
1068     equivalent. (In particular, the algorithms defined in this
1069     specification are intended to be easy to follow, and not intended to
1070     be performant.)</span><span class=ja-translation lang=ja>算法や特定の段階として説明されている適合性要件は、
1071     最終的な結果が等価である限り、任意の方法で実装して<em class=rfc2119 title="MAY">構いません</em>。
1072     (特に、この仕様書で定義されている算法は追うのを簡単にしており、
1073     高性能であることを目指してはいません。)</span></p>
1074    
1075     <p class="has-ja-translation" data-ja-hash="e42931a32a5e7ad458e3ca1b87d741d9"><span class=en-original lang=en>The only conformance class defined by this specification is user
1076     agents.</span><span class=ja-translation lang=ja>この仕様書で定義する唯一の適合性の級は利用者エージェントです。</span></p>
1077    
1078     <p class="has-ja-translation" data-ja-hash="57959e6c42e8d5141b11e501bf60cc2f"><span class=en-original lang=en>User agents may impose implementation-specific limits on
1079     otherwise unconstrained inputs, e.g. to prevent denial of service
1080     attacks, to guard against running out of memory, or to work around
1081     platform-specific limitations.</span><span class=ja-translation lang=ja>利用者エージェントは、サービス拒否攻撃を防ぐため、
1082     記憶容量を使い尽くすことを防ぐため、
1083     あるいは環境特有の制限に対応するためなどの目的で、
1084     別段の制約のない入力に対して実装特有の制限を設けて<em class=rfc2119 title="MAY">構いません</em>。</span></p>
1085    
1086    
1087 wakaba 1.139 <h3 id=dependencies class="has-ja-translation" data-ja-hash="896f4eaa4f12972b56ed9cdd9a90b949"><span class=en-original lang=en><span class=secno>2.1 </span>Dependencies</span><span class=ja-translation lang=ja><span class=secno>2.1 </span>依存性</span></h3>
1088 wakaba 1.111
1089     <p class="has-ja-translation" data-ja-hash="8dc27a34324d9e41d25c6bbbc2d2551c"><span class=en-original lang=en>This specification relies on several other underlying
1090     specifications.</span><span class=ja-translation lang=ja>この仕様書は、他のいくつかの下位の仕様書に依存しています。</span></p>
1091    
1092 wakaba 1.156 <dl>
1093    
1094     <dt class="no-ja-translation" data-ja-hash="6bff62b10d884fb77428cfe168cd783d"><span class=en-original lang=en>HTML5</span></dt>
1095 wakaba 1.111
1096     <dd>
1097    
1098     <p class="has-ja-translation" data-ja-hash="99d7a97f59faf316f6125ad288390f21"><span class=en-original lang=en>Many fundamental concepts from HTML5 are used by this
1099     specification. <a href=#refsHTML5>[HTML5]</a></span><span class=ja-translation lang=ja>この仕様書では、 HTML5 の多くの基礎的な概念を使用します。
1100     <a href=#refsHTML5>[HTML5]</a></span></p>
1101    
1102     </dd>
1103    
1104     <dt class="no-ja-translation" data-ja-hash="21838f6e93b1a2157b16dcb6281ff225"><span class=en-original lang=en>WebIDL</span></dt>
1105    
1106     <dd>
1107    
1108     <p class="has-ja-translation" data-ja-hash="a9c4aac7340973a8cba95e916539c5d9"><span class=en-original lang=en>The IDL blocks in this specification use the semantics of the
1109     WebIDL specification. <a href=#refsWebIDL>[WebIDL]</a></span><span class=ja-translation lang=ja>この仕様書の IDL ブロックは、WebIDL 仕様書における意味を用います。 <a href=#refsWebIDL>[WebIDL]</a></span></p>
1110    
1111     </dd>
1112    
1113 wakaba 1.156 </dl>
1114    
1115    
1116     <h2 id=terminology class="has-ja-translation" data-ja-hash="e182a8a3f2adf774fb1c959df71b8600"><span class=en-original lang=en><span class=secno>3 </span>Terminology</span><span class=ja-translation lang=ja><span class=secno>3 </span>用語</span></h2>
1117 wakaba 1.111
1118     <p class="has-ja-translation" data-ja-hash="f99630e4a7f12f2c4ecb88e02bf4a644"><span class=en-original lang=en>The construction "a <code title="">Foo</code> object", where
1119     <code title="">Foo</code> is actually an interface, is sometimes
1120     used instead of the more accurate "an object implementing the
1121     interface <code title="">Foo</code>".</span><span class=ja-translation lang=ja>「<code title="">Foo</code> オブジェクト」という構文 (<code title="">Foo</code>
1122     は実際には界面) を時々使いますが、より正確な「界面 <code title="">Foo</code>
1123     を実装しているオブジェクト」の代わりに用いています。</span></p>
1124    
1125     <p class="has-ja-translation" data-ja-hash="12e69607f07368ff572adb4dffcc8535"><span class=en-original lang=en>The term DOM is used to refer to the API set made available to
1126     scripts in Web applications, and does not necessarily imply the
1127     existence of an actual <code>Document</code> object or of any other
1128     <code>Node</code> objects as defined in the DOM Core
1129     specifications. <a href=#refsDOM3CORE>[DOM3CORE]</a></span><span class=ja-translation lang=ja>DOM という語は、 Web アプリケーションでスクリプトに利用可能とされている API
1130     の集合を指して用い、必ずしも DOM 中核仕様書で定義されている実際の
1131     <code>Document</code> オブジェクトその他の <code>Node</code>
1132     オブジェクトの存在を暗示してはいません。<a
1133     href=#refsDOM3CORE>[DOM3CORE]</a></span></p>
1134    
1135     <p class="has-ja-translation" data-ja-hash="5b9242da79aeab74bccc57781ac3103e"><span class=en-original lang=en>A DOM attribute is said to be <em>getting</em> when its value is
1136     being retrieved (e.g. by author script), and is said to be
1137     <em>setting</em> when a new value is assigned to it.</span><span class=ja-translation lang=ja>DOM 属性は、その値が (例えば著者のスクリプトにより) 取り出される時<em>取得される</em>といい、
1138     新しい値がその属性に割り当てられる時<em>設定される</em>といいます。</span></p>
1139    
1140     <p class="no-ja-translation" data-ja-hash="63fe78b97a0b5051e1ffbf6ee2f1e483"><span class=en-original lang=en>The term "JavaScript" is used to refer to ECMA262, rather than
1141     the official term ECMAScript, since the term JavaScript is more
1142     widely known. <a href=#refsECMA262>[ECMA262]</a></span></p>
1143    
1144    
1145 wakaba 1.139 <h2 id=infrastructure class="has-ja-translation" data-ja-hash="cba4f4cee5c6a3e6d8be8da68fa1234e"><span class=en-original lang=en><span class=secno>4 </span>Infrastructure</span><span class=ja-translation lang=ja><span class=secno>4 </span>基盤</span></h2>
1146 wakaba 1.111
1147     <p class="no-ja-translation" data-ja-hash="f38a96d03c61f343169a402b5c779db8"><span class=en-original lang=en>There are two kinds of workers; dedicated workers, and shared
1148     workers. Dedicated workers, once created, and are linked to their
1149     creator; but message ports can be used to communicate from a
1150     dedicated worker to multiple other browsing contexts or
1151     workers. Shared workers, on the other hand, are named, and once
1152     created any script running in the same <span>origin</span> can
1153     obtain a reference to that worker and communicate with it.</span></p>
1154    
1155    
1156 wakaba 1.139 <h3 id=the-global-scope class="has-ja-translation" data-ja-hash="16d7670f16b3aaf6130252e8f11702eb"><span class=en-original lang=en><span class=secno>4.1 </span>The global scope</span><span class=ja-translation lang=ja><span class=secno>4.1 </span>大域作用域</span></h3>
1157 wakaba 1.111
1158     <p class="has-ja-translation" data-ja-hash="216dee088449fef485a489ea8a7432f4"><span class=en-original lang=en>The global scope is the "inside" of a worker.</span><span class=ja-translation lang=ja>大域作用域は労働者の「内側」です。</span></p>
1159    
1160 wakaba 1.139 <h4 id=the-workerglobalscope-abstract-interface class="has-ja-translation" data-ja-hash="fe5227371e801f4ac588d0d07472a900" data-ja-real-hash="be491e4df478a7115eae60853f3c23aa"><span class=en-original lang=en><span class=secno>4.1.1 </span>The <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> abstract interface</span><span class=ja-translation lang=ja><span class=secno>4.1.1 </span><code><a href=#workerglobalscope>WorkerGlobalScope</a></code> 抽象界面</span></h4>
1161 wakaba 1.111
1162 wakaba 1.154 <pre class="idl no-ja-translation" data-ja-hash="e3d0f4444473b31bbffb7bd44e6f1016"><span class=en-original lang=en>interface <dfn id=workerglobalscope>WorkerGlobalScope</dfn> {
1163 wakaba 1.111 readonly attribute <a href=#workerglobalscope>WorkerGlobalScope</a> <a href=#dom-workerglobalscope-self title=dom-WorkerGlobalScope-self>self</a>;
1164     readonly attribute <a href=#workerlocation>WorkerLocation</a> <a href=#dom-workerglobalscope-location title=dom-WorkerGlobalScope-location>location</a>;
1165    
1166     void <a href=#dom-workerglobalscope-close title=dom-WorkerGlobalScope-close>close</a>();
1167 wakaba 1.137 <!-- v2-onclose attribute <span>Function</span> <span title="handler-WorkerGlobalScope-onclose">onclose</span>;
1168     --> attribute <span>Function</span> <a href=#handler-workerglobalscope-onerror title=handler-WorkerGlobalScope-onerror>onerror</a>;
1169 wakaba 1.154 };
1170     <a href=#workerglobalscope>WorkerGlobalScope</a> implements <a href=#workerutils>WorkerUtils</a>;</span></pre>
1171 wakaba 1.111
1172     <p class="no-ja-translation" data-ja-hash="d82fd6989aa746efef0cf182479d5e41"><span class=en-original lang=en>Objects implementing the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> interface
1173     must also implement the <code>EventTarget</code> interface.</span></p>
1174    
1175     <p class="no-ja-translation" data-ja-hash="0a5104552951765122b762e943a821b0"><span class=en-original lang=en>The <dfn id=dom-workerglobalscope-self title=dom-WorkerGlobalScope-self><code>self</code></dfn> attribute
1176     must return the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object itself.</span></p>
1177    
1178 wakaba 1.112 <p class="no-ja-translation" data-ja-hash="e48d78d83311d57328ab69a17167fffc"><span class=en-original lang=en>The <dfn id=dom-workerglobalscope-location title=dom-WorkerGlobalScope-location><code>location</code></dfn>
1179 wakaba 1.111 attribute must return the <code><a href=#workerlocation>WorkerLocation</a></code> object created
1180     for the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object when the worker was
1181     created. It represents the <span>absolute URL</span> of the script
1182 wakaba 1.112 that was used to initialize the worker, after any redirects.</span></p>
1183 wakaba 1.111
1184 wakaba 1.156 <hr>
1185    
1186     <p class="no-ja-translation" data-ja-hash="c205c04fbfcc56617b82329c66dbda4a"><span class=en-original lang=en>When a script invokes the <dfn id=dom-workerglobalscope-close title=dom-WorkerGlobalScope-close><code>close()</code></dfn>
1187 wakaba 1.111 method on a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object, the user agent
1188     must run the following steps (atomically):</span></p>
1189    
1190 wakaba 1.156 <ol>
1191    
1192     <li><p class="no-ja-translation" data-ja-hash="af4d5ddb9edfb1a69b29ed3140620794"><span class=en-original lang=en>Discard any <span title=concept-task>tasks</span> that
1193 wakaba 1.111 have been added to the <span>event loop</span>'s <span title="task
1194     queue">task queues</span>.</span></p>
1195    
1196     <!-- v2-onclose
1197     <li><p class="no-ja-translation" data-ja-hash="8d73b86033e135135fa4dd2f2193b43e"><span class=en-original lang=en><span>Queue a task</span> to <span>fire a simple
1198     event</span> called <code title="event-close">close</code> at the
1199     <code>WorkerGlobalScope</code> object.</span></p></li>
1200     -->
1201    
1202     <li><p class="no-ja-translation" data-ja-hash="1e713e7163b783674600c93aed418557"><span class=en-original lang=en>Set the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's
1203     <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag to
1204     true. (This prevents any further tasks from being queued.)</span></li>
1205    
1206     <li><p class="no-ja-translation" data-ja-hash="37da2c132b44ba85602699d1ef93c598"><span class=en-original lang=en>Disentangle all the ports in the list of <a href="#the-worker's-ports">the worker's
1207     ports</a>.</span></li>
1208    
1209 wakaba 1.156 </ol>
1210    
1211     <p class="no-ja-translation" data-ja-hash="82e59a1ba6d95a68947e7065fd8ac80b"><span class=en-original lang=en>The following are the <span>event handler attributes</span> (and their corresponding <span title="event handler event type">event handler event types</span>)
1212 wakaba 1.111 that must be supported, as DOM attributes, by objects implementing
1213     the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> interface:</span></p>
1214    
1215 wakaba 1.156 <table>
1216     <thead>
1217     <tr><th class="no-ja-translation" data-ja-hash="c85726f0c6ba202006ec1f912e68aa76"><span class=en-original lang=en><span title="event handler attributes">event handler attribute</span> </span><th class="no-ja-translation" data-ja-hash="3fc98eebba71602c62d8b2fd74645dc9"><span class=en-original lang=en><span>Event handler event type</span>
1218     </span><tbody>
1219     <!-- v2-onclose <tr><td class="no-ja-translation" data-ja-hash="8299f4100f9c690ddf7935714f58b453"><span class=en-original lang=en><dfn title="handler-WorkerGlobalScope-onclose"><code>onclose</code></dfn> </span><td class="no-ja-translation" data-ja-hash="e899358e829911a25c083ed9bc6519e6"><span class=en-original lang=en> <code title="event-close">close</code> -->
1220     </span><tr><td class="no-ja-translation" data-ja-hash="08a21be8031dd240d32ac8ab2b17a9ac"><span class=en-original lang=en><dfn id=handler-workerglobalscope-onerror title=handler-WorkerGlobalScope-onerror><code>onerror</code></dfn> </span><td class="no-ja-translation" data-ja-hash="bf1b78c16e7c3a3de662d83f487bffff"><span class=en-original lang=en> <code title=event-error>error</code>
1221     </span></table>
1222    
1223    
1224     <h4 id=dedicated-workers-and-the-dedicatedworkerglobalscope-interface class="no-ja-translation" data-ja-hash="a4b427f41de050a77385a1705efbb7c1"><span class=en-original lang=en><span class=secno>4.1.2 </span>Dedicated workers and the <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> interface</span></h4>
1225 wakaba 1.111
1226 wakaba 1.154 <pre class="idl no-ja-translation" data-ja-hash="bfd4cc74d5de30a3a56b69105fa0d527"><span class=en-original lang=en>[Supplemental, NoInterfaceObject]
1227     interface <dfn id=dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</dfn> : <a href=#workerglobalscope>WorkerGlobalScope</a> {
1228     void <a href=#dom-dedicatedworkerglobalscope-postmessage title=dom-DedicatedWorkerGlobalScope-postMessage>postMessage</a>(in any message, optional in <span>MessagePortArray</span> ports);<!--
1229 wakaba 1.111 <span>MessagePort</span> <span title="dom-DedicatedWorkerGlobalScope-startConversation">startConversation</span>(in any message);-->
1230 wakaba 1.137 attribute <span>Function</span> <a href=#handler-dedicatedworkerglobalscope-onmessage title=handler-DedicatedWorkerGlobalScope-onmessage>onmessage</a>;
1231 wakaba 1.111 };</span></pre>
1232    
1233     <p class="no-ja-translation" data-ja-hash="2b76e99642dd9984f9a5fb8a280c921c"><span class=en-original lang=en><code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> objects act as if they
1234     had an implicit <code>MessagePort</code> associated with them. This
1235     port is part of a channel that is set up when the worker is created,
1236     but it is not exposed. This object must never be garbage collected
1237     before the <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> object.</span></p>
1238    
1239     <p class="no-ja-translation" data-ja-hash="3737098ad5998864275d8ee619bd864e"><span class=en-original lang=en>All messages received by that port must immediately be retargeted
1240     at the <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> object.</span></p>
1241    
1242     <p class="no-ja-translation" data-ja-hash="8156ab5347965f42a9531625b8096a00"><span class=en-original lang=en>The <dfn id=dom-dedicatedworkerglobalscope-postmessage title=dom-DedicatedWorkerGlobalScope-postMessage><code>postMessage()</code></dfn><!--
1243     and <dfn
1244     title="dom-DedicatedWorkerGlobalScope-startConversation"><code>startConversation()</code></dfn>-->
1245     method<!--s (startConversation)--> on
1246     <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> objects must act as if, when
1247     invoked, it<!--/they (startConversation)--> immediately invoked the
1248     method of the same name on the port, with the same arguments, and
1249     returned the same return value.</span></p>
1250    
1251     <p class="no-ja-translation" data-ja-hash="4485ef1302525e70204d808989daff0e"><span class=en-original lang=en>The following are the <span>event handler attributes</span> (and
1252     their corresponding <span title="event handler event type">event
1253     handler event types</span>) that must be supported, as DOM
1254     attributes, by objects implementing the
1255     <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> interface:</span></p>
1256    
1257 wakaba 1.156 <table>
1258     <thead>
1259     <tr><th class="no-ja-translation" data-ja-hash="c85726f0c6ba202006ec1f912e68aa76"><span class=en-original lang=en><span title="event handler attributes">event handler attribute</span> </span><th class="no-ja-translation" data-ja-hash="3fc98eebba71602c62d8b2fd74645dc9"><span class=en-original lang=en><span>Event handler event type</span>
1260     </span><tbody>
1261     <tr><td class="no-ja-translation" data-ja-hash="0d8bd2da6a52d641c317fac6d1c953b2"><span class=en-original lang=en><dfn id=handler-dedicatedworkerglobalscope-onmessage title=handler-DedicatedWorkerGlobalScope-onmessage><code>onmessage</code></dfn> </span><td class="no-ja-translation" data-ja-hash="fe07e2527bf13c457386ab4807af84a0"><span class=en-original lang=en> <code title=event-message>message</code>
1262     </span></table>
1263    
1264     <p class="no-ja-translation" data-ja-hash="0c348925ec14031682913edd79ceb3d3"><span class=en-original lang=en>For the purposes of the <span>offline application cache</span>
1265 wakaba 1.111 networking model, a dedicated worker is an extension of the
1266     <span>cache host</span> from which it was created.</span></p>
1267    
1268    
1269    
1270 wakaba 1.139 <h4 id=shared-workers-and-the-sharedworkerglobalscope-inteface class="no-ja-translation" data-ja-hash="6ab8095d66816337c244beec43a0e6d4"><span class=en-original lang=en><span class=secno>4.1.3 </span>Shared workers and the <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> inteface</span></h4>
1271 wakaba 1.111
1272 wakaba 1.154 <pre class="idl no-ja-translation" data-ja-hash="d50871df68a2c60553b6a55d6cd199bc"><span class=en-original lang=en>[Supplemental, NoInterfaceObject]
1273     interface <dfn id=sharedworkerglobalscope>SharedWorkerGlobalScope</dfn> : <a href=#workerglobalscope>WorkerGlobalScope</a> {
1274 wakaba 1.111 readonly attribute DOMString <a href=#dom-sharedworkerglobalscope-name title=dom-SharedWorkerGlobalScope-name>name</a>;
1275     readonly attribute <span>ApplicationCache</span> <a href=#dom-sharedworkerglobalscope-applicationcache title=dom-SharedWorkerGlobalScope-applicationCache>applicationCache</a>;
1276 wakaba 1.137 attribute <span>Function</span> <a href=#handler-sharedworkerglobalscope-onconnect title=handler-SharedWorkerGlobalScope-onconnect>onconnect</a>;
1277 wakaba 1.111 };</span></pre>
1278    
1279     <p class="has-ja-translation" data-ja-hash="9d344498c69a5ed60029b76fb274beb2"><span class=en-original lang=en>Shared workers receive message ports through <code title=event-WorkerGlobalScope-connect>connect</code> events on
1280     their global object for each connection.</span><span class=ja-translation lang=ja>共有労働者は、各接続について大域オブジェクトの <code
1281     title=event-WorkerGlobalScope-connect>connect</code> 事象を通じてメッセージ・ポートを受信します。</span></p>
1282    
1283     <p class="no-ja-translation" data-ja-hash="582a890c60947f33bddb73ed33bb32f9"><span class=en-original lang=en>The <dfn id=dom-sharedworkerglobalscope-name title=dom-SharedWorkerGlobalScope-name><code>name</code></dfn>
1284     attribute must return the value it was assigned when the
1285     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object was created by the
1286     "<a href=#run-a-worker>run a worker</a>" algorithm. Its value represents the name
1287     that can be used to obtain a reference to the worker using the
1288     <code><a href=#sharedworker>SharedWorker</a></code> constructor.</span></p>
1289    
1290     <p class="no-ja-translation" data-ja-hash="89036f99dca015c66728e21089b984b0"><span class=en-original lang=en>The following are the <span>event handler attributes</span> (and
1291     their corresponding <span title="event handler event type">event
1292     handler event types</span>) that must be supported, as DOM
1293     attributes, by objects implementing the
1294     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> interface:</span></p>
1295    
1296 wakaba 1.156 <table>
1297     <thead>
1298     <tr><th class="no-ja-translation" data-ja-hash="c85726f0c6ba202006ec1f912e68aa76"><span class=en-original lang=en><span title="event handler attributes">event handler attribute</span> </span><th class="no-ja-translation" data-ja-hash="3fc98eebba71602c62d8b2fd74645dc9"><span class=en-original lang=en><span>Event handler event type</span>
1299     </span><tbody>
1300     <tr><td class="no-ja-translation" data-ja-hash="f198960aead81a70dcfd8fe22ce3e5c3"><span class=en-original lang=en><dfn id=handler-sharedworkerglobalscope-onconnect title=handler-SharedWorkerGlobalScope-onconnect><code>onconnect</code></dfn> </span><td class="no-ja-translation" data-ja-hash="01a017777bf3db29f5ec26ca1ad7aced"><span class=en-original lang=en> <code title=event-connect>connect</code>
1301     </span></table>
1302    
1303     <p class="no-ja-translation" data-ja-hash="ac81324d4bd9e8a1090d3db7e2e34ca9"><span class=en-original lang=en>For the purposes of the <span>offline application cache</span>
1304 wakaba 1.111 networking model, a shared worker is its own <span>cache
1305     host</span>. The <a href=#run-a-worker>run a worker</a> algorithm takes care of
1306     associating the worker with an <span>application cache</span>.</span></p>
1307    
1308     <p class="note no-ja-translation" data-ja-hash="eb3d6f833d8fb42a6cea6890baeaf796"><span class=en-original lang=en>The <dfn id=dom-sharedworkerglobalscope-applicationcache title=dom-SharedWorkerGlobalScope-applicationCache><code>applicationCache</code></dfn>
1309     attribute returns the <code>ApplicationCache</code> object for the
1310     worker.</span></p><!-- normative conf criteria is in the appcache section
1311     -->
1312    
1313    
1314 wakaba 1.139 <h3 id=base-urls-and-origins-of-workers class="has-ja-translation" data-ja-hash="87cf5066db3fe786def6b713cf422c90"><span class=en-original lang=en><span class=secno>4.2 </span>Base URLs and origins of workers</span><span class=ja-translation lang=ja><span class=secno>4.2 </span>労働者の基底 URL と起源</span></h3>
1315 wakaba 1.111
1316     <p class="no-ja-translation" data-ja-hash="5d71247ae9c7e88e4244d78062ed4760"><span class=en-original lang=en>Both the <span>origin</span> and <span>effective script
1317     origin</span> of scripts running in workers are the
1318     <span>origin</span> of the <span>absolute URL</span> given in that
1319     the worker's <code title=dom-WorkerGlobalScope-location><a href=#dom-workerglobalscope-location>location</a></code> attribute
1320     represents.</span></p>
1321    
1322    
1323 wakaba 1.139 <h3 id=decoding-scripts class="no-ja-translation" data-ja-hash="857fdf8086147b470ea754e3a4f6c667"><span class=en-original lang=en><span class=secno>4.3 </span>Decoding scripts</span></h3>
1324 wakaba 1.111
1325     <p class="no-ja-translation" data-ja-hash="4356cf7102f2b838e2b8201769e8d8ed"><span class=en-original lang=en>When a user agent is to <dfn id=decode-a-script-resource>decode a script resource</dfn> to
1326     obtain its source in Unicode, it must run the following steps:</span></p>
1327    
1328 wakaba 1.156 <ol>
1329    
1330     <li>
1331 wakaba 1.111
1332     <p class="no-ja-translation" data-ja-hash="6571036d6f54aff003088a24c671dfc7"><span class=en-original lang=en>Let <var title="">character encoding</var> be <i title="">unknown</i>.</span></p>
1333    
1334     </li>
1335    
1336     <li>
1337    
1338     <p class="no-ja-translation" data-ja-hash="26531f4017a22df14ccb6d1eee6264e7"><span class=en-original lang=en>For each of the rows in the following table, starting with the
1339     first one and going down, if the resource has as many or more
1340     bytes available than the number of bytes in the first column, and
1341     the first bytes of the resource match the bytes given in the first
1342     column, then let <var title="">character encoding</var> be the
1343     encoding given in the cell in the second column of that row:</span></p>
1344    
1345     <!-- this table is present in several forms in this file; keep them in sync -->
1346 wakaba 1.156 <table>
1347     <thead>
1348     <tr>
1349     <th class="has-ja-translation" data-ja-hash="cedd90a7eefcd8a4c28ead96824a8c5a"><span class=en-original lang=en>Bytes in Hexadecimal
1350 wakaba 1.111 </span><span class=ja-translation lang=ja>バイトの十六進数表現</span><th class="has-ja-translation" data-ja-hash="169a6f6b44766410bffebf76ff3dcf17"><span class=en-original lang=en>Encoding
1351 wakaba 1.156 </span><span class=ja-translation lang=ja>符号化</span><tbody>
1352     <!-- nobody uses this
1353 wakaba 1.111 <tr>
1354     <td class="no-ja-translation" data-ja-hash="3b523bf4f5c7a5f0ff3963fdad8049a9"><span class=en-original lang=en>00 00 FE FF
1355     </span><td class="no-ja-translation" data-ja-hash="59e7c7bf45f69d917450ae560a578a4f"><span class=en-original lang=en>UTF-32BE
1356     </span><tr>
1357     <td class="no-ja-translation" data-ja-hash="e25d985f134390f54047573f4a1eca7e"><span class=en-original lang=en>FF FE 00 00
1358     </span><td class="no-ja-translation" data-ja-hash="83039ece36f32fba267280c8de26edf5"><span class=en-original lang=en>UTF-32LE
1359 wakaba 1.156 -->
1360     </span><tr>
1361     <td class="no-ja-translation" data-ja-hash="d9594f5bb7f7387cd1c6d8cb69fb5774"><span class=en-original lang=en>FE FF
1362 wakaba 1.111 </span><td class="no-ja-translation" data-ja-hash="58ee3e3038c435c19dfa106ac8b67d73"><span class=en-original lang=en>UTF-16BE
1363 wakaba 1.156 </span><tr>
1364     <td class="no-ja-translation" data-ja-hash="3d748bc0fd7caa28cb9bd697c840f46f"><span class=en-original lang=en>FF FE
1365 wakaba 1.111 </span><td class="no-ja-translation" data-ja-hash="600ebb464ff7e548ff5a09c2c12f551b"><span class=en-original lang=en>UTF-16LE
1366 wakaba 1.156 </span><tr>
1367     <td class="no-ja-translation" data-ja-hash="5d1b4e645efa35016b709ffbd308e29d"><span class=en-original lang=en>EF BB BF
1368 wakaba 1.111 </span><td class="no-ja-translation" data-ja-hash="ae3b3df9970b49b6523e608759bc957d"><span class=en-original lang=en>UTF-8
1369     <!-- nobody uses this
1370     --></span><!--<tr>
1371     <td class="no-ja-translation" data-ja-hash="7d1cd1d79b5ca7151c2153c016bc5c49"><span class=en-original lang=en>DD 73 66 73
1372     </span><td class="no-ja-translation" data-ja-hash="48ad579645de9a10a9a6f78fab81fb65"><span class=en-original lang=en>UTF-EBCDIC
1373     -->
1374 wakaba 1.156 </span></table>
1375    
1376     <p class="note no-ja-translation" data-ja-hash="9a59482dc82872c443907eeed8818b89"><span class=en-original lang=en>This step looks for Unicode Byte Order Marks
1377 wakaba 1.111 (BOMs).</span></p>
1378    
1379     </li>
1380    
1381     <li>
1382    
1383     <p class="no-ja-translation" data-ja-hash="1bdaa4e7198023dcf4f7984a4898619a"><span class=en-original lang=en>If <var title="">character encoding</var> is still <i title="">unknown</i>, apply the <span>algorithm for extracting an
1384     encoding from a Content-Type</span> to the resource's <span title=Content-Type>Content Type metadata</span>; if this returns
1385     an encoding, and the user agent supports that encoding, then let
1386     <var title="">character encoding</var> be that encoding.</span></p>
1387    
1388     </li>
1389    
1390     <li>
1391    
1392     <p class="no-ja-translation" data-ja-hash="6bbc467e6929571d61a6b95004cf9974"><span class=en-original lang=en>If <var title="">character encoding</var> is still <i title="">unknown</i>, then let <var title="">character
1393     encoding</var> be UTF-8.</span></p>
1394    
1395     </li>
1396    
1397     <li>
1398    
1399     <p class="no-ja-translation" data-ja-hash="178b2c0b2c79b7e38b80e13f0fac6983"><span class=en-original lang=en>Convert the resource to Unicode using the character encoding
1400     given by <var title="">character encoding</var>.</span></p>
1401    
1402     <p class="no-ja-translation" data-ja-hash="ee427dae6dec0a6bf731b3069f9a4abd"><span class=en-original lang=en>Return the text that is so obtained.</span></p>
1403    
1404     </li>
1405    
1406 wakaba 1.156 </ol>
1407    
1408    
1409     <h3 id=the-event-loop class="no-ja-translation" data-ja-hash="96715962ce61ea28085d7e170ec30e73"><span class=en-original lang=en><span class=secno>4.4 </span>The event loop</span></h3>
1410 wakaba 1.111
1411 wakaba 1.112 <p class="no-ja-translation" data-ja-hash="9da3324200d63a62412fc5bc671f7d95"><span class=en-original lang=en>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object has an <span>event
1412     loop</span> distinct from those defined for <span title="unit of
1413     related similar-origin browsing contexts">units of related
1414     similar-origin browsing contexts</span>. This <span>event
1415     loop</span> has no associated <span>browsing context</span>, and its
1416     <span title="task queue">task queues</span> only have events,
1417     callbacks, and networking activity as <span title=concept-task>tasks</span>. The processing model of these
1418     <span title="event loop">event loops</span> is defined below in the
1419     <a href=#run-a-worker>run a worker</a> algorithm.</span></p>
1420 wakaba 1.111
1421     <p class="no-ja-translation" data-ja-hash="084ed34f256b8b7e4ff2b85cd92ca33b"><span class=en-original lang=en>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object also has a <dfn id=dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</dfn> flag, which must
1422     initially be false, but which can get set to true by the algorithms
1423     in the processing model section below.</span></p>
1424    
1425     <p class="no-ja-translation" data-ja-hash="35f0c99f177dce8acd9669a371da6ba3"><span class=en-original lang=en>Once the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set to
1426     true, the <span>event loop</span>'s <span title="task queue">task
1427     queues</span> must discard any further <span title=concept-task>tasks</span> that would be added to them (tasks
1428     already on the queue are unaffected unless otherwise
1429     specified). Effectively, once the <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is true,
1430     timers stop firing, notifications for all pending asynchronous
1431     operations are dropped, etc.</span></p>
1432    
1433    
1434 wakaba 1.133
1435 wakaba 1.139 <h3 id="the-worker's-lifetime" class="no-ja-translation" data-ja-hash="74a0efe3050847567026cd8638e4d2d6"><span class=en-original lang=en><span class=secno>4.5 </span>The worker's lifetime</span></h3>
1436 wakaba 1.111
1437     <p class="has-ja-translation" data-ja-hash="15eb0638e0de7d0e159c1214c48ba569"><span class=en-original lang=en>Workers communicate with other workers and with <span title="browsing context">browsing contexts</span> through <span title="channel messaging">message channels</span> and their
1438     <code>MessagePort</code> objects.</span><span class=ja-translation lang=ja>労働者は、メッセージ通信路とその <code>MessagePort</code>
1439     オブジェクトを通じて、他の労働者や閲覧文脈と通信します。</span></p>
1440    
1441     <p class="no-ja-translation" data-ja-hash="2c7d1a4ce717326e596bad596f0fc0bb"><span class=en-original lang=en>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> <var title="">worker global
1442     scope</var> has a list of <dfn id="the-worker's-ports">the worker's ports</dfn>, which
1443     consists of all the <code>MessagePort</code> objects that are
1444     entangled with another port and that have one (but only one) port
1445     owned by <var title="">worker global scope</var>. This list includes
1446     <!--all the <code>MessagePort</code> objects that are in events
1447     pending in the <span>event loop</span>, as well as (commented out
1448     because in practice it makes no difference either way as far as I
1449     can tell, and it would be hard to strictly implement since these
1450     ports might not yet be across the thread boundary)--> the implicit
1451     <code>MessagePort</code> in the case of <a href=#dedicatedworkerglobalscope title=DedicatedWorkerGlobalScope>dedicated workers</a>.</span></p>
1452    
1453     <p class="no-ja-translation" data-ja-hash="1aeb90a4b706e7a9ff09953cd49aed7c"><span class=en-original lang=en>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> also has a list of <dfn id="the-worker's-workers">the
1454     worker's workers</dfn>. Initially this list is empty; it is
1455     populated when the worker creates or obtains further workers.</span></p>
1456    
1457     <p class="no-ja-translation" data-ja-hash="065bd87a93010cf4e435c95f2e540af5"><span class=en-original lang=en>Finally, each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> also has a list of
1458     <dfn id="the-worker's-documents">the worker's <code>Document</code>s</dfn>. Initially this list
1459     is empty; it is populated when the worker is created.</span></p>
1460    
1461     <p class="no-ja-translation" data-ja-hash="6a8fe8066ddde02f0b3e6e22079bbd7e"><span class=en-original lang=en>Whenever a <code>Document</code> <var title="">d</var> is <dfn id="add-a-document-to-the-worker's-documents" title="add a document to the worker's documents">added to the
1462     worker's <code>Document</code>s</dfn>, the user agent must, for each
1463     worker in the list of <a href="#the-worker's-workers">the worker's workers</a> whose list
1464     of <a href="#the-worker's-documents">the worker's <code>Document</code>s</a> does not contain
1465     <var title="">d</var>, <a href="#add-a-document-to-the-worker's-documents" title="add a document to the worker's
1466     documents">add <var title="">d</var> to <var title="">q</var>'s
1467     <code>WorkerGlobalScope</code> owner's list of <span>the worker's
1468     <code>Document</code>s</span></a>.</span></p> <!-- suggestions welcome
1469     on making this sentence into understandable English -->
1470    
1471     <p class="no-ja-translation" data-ja-hash="c556389e6b192b4ac768940df1b3cffc"><span class=en-original lang=en>Whenever a <code>Document</code> object is <span title="discard a
1472     Document">discarded</span>, it must be removed from the list of
1473     <a href="#the-worker's-documents">the worker's <code>Document</code>s</a> of each worker
1474     whose list contains that <code>Document</code>.</span></p>
1475    
1476     <p class="no-ja-translation" data-ja-hash="db482587a227e92fd91bc6be1c81ddb3"><span class=en-original lang=en>Given a <span>script's global scope</span> <var title="">o</var>
1477     when creating or obtaining a worker, the <dfn id=list-of-relevant-document-objects-to-add>list of relevant
1478     <code>Document</code> objects to add</dfn> depends on the type of
1479     <var title="">o</var>. If <var title="">o</var> is a
1480     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object (i.e. if we are creating a
1481     nested worker), then the relevant <code>Document</code>s are the
1482     <code>Document</code>s that are in <var title="">o</var>'s own list
1483     of <a href="#the-worker's-documents">the worker's <code>Document</code>s</a>. Otherwise, <var title="">o</var> is a <code>Window</code> object, and the relevant
1484     <code>Document</code> is just the <code>Document</code> that is the
1485     <span>active document</span> of the <code>Window</code> object <var title="">o</var>.</span></p>
1486    
1487 wakaba 1.156 <hr>
1488    
1489     <p class="no-ja-translation" data-ja-hash="ea771ae7f86ae7c85f1418763117fa28"><span class=en-original lang=en>A worker is said to be a <dfn id=permissible-worker>permissible worker</dfn> if its
1490 wakaba 1.111 list of <a href="#the-worker's-documents">the worker's <code>Document</code>s</a> is not
1491     empty.</span></p>
1492    
1493     <p class="no-ja-translation" data-ja-hash="e7407e6349a298d2bf4d87d06d147420"><span class=en-original lang=en>A worker is said to be a <dfn id=protected-worker>protected worker</dfn> if it is a
1494     <a href=#permissible-worker>permissible worker</a> and either it has outstanding
1495     timers, database transactions, or network connections, or its list
1496     of <a href="#the-worker's-ports">the worker's ports</a> is not empty, or its
1497     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> is actually a
1498     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object (i.e. the worker is a
1499     shared worker).</span></p>
1500    
1501     <p class="no-ja-translation" data-ja-hash="1a7b06a4fed1c22378b6b6f6ca13ffc2"><span class=en-original lang=en>A worker is said to be an <dfn id=active-needed-worker>active needed worker</dfn> if any
1502     of the <code>Document</code> objects in <a href="#the-worker's-documents">the worker's
1503     <code>Document</code>s</a> are <span>fully active</span>.</span></p>
1504    
1505     <p class="no-ja-translation" data-ja-hash="4182e47a8cba3978170630845be09eed"><span class=en-original lang=en>A worker is said to be a <dfn id=suspendable-worker>suspendable worker</dfn> if it is
1506     not an <a href=#active-needed-worker>active needed worker</a> but it is a
1507     <a href=#permissible-worker>permissible worker</a>.</span></p>
1508    
1509    
1510 wakaba 1.139 <h3 id=processing-model class="has-ja-translation" data-ja-hash="4eeffb677544f6c8799408c6b9021b4c"><span class=en-original lang=en><span class=secno>4.6 </span>Processing model</span><span class=ja-translation lang=ja><span class=secno>4.6 </span>処理モデル</span></h3>
1511 wakaba 1.111
1512     <p class="no-ja-translation" data-ja-hash="c45c1611a5572d560022f94383f4daf7"><span class=en-original lang=en>When a user agent is to <dfn id=run-a-worker>run a worker</dfn> for a script with
1513     <span>URL</span> <var title="">url</var>, a browsing context <var title="">owner browsing context</var>, and with global scope <var title="">worker global scope</var>, it must run the following
1514     steps:</span></p>
1515    
1516 wakaba 1.156 <ol>
1517    
1518     <li>
1519 wakaba 1.111
1520     <p class="no-ja-translation" data-ja-hash="699e58187adc9ee37990500a66c83a8f"><span class=en-original lang=en>Create a completely separate and parallel execution environment
1521     (i.e. a separate thread or process or equivalent construct), and
1522     run the rest of these steps asynchronously in that context.</span></p>
1523    
1524     </li>
1525    
1526     <li><p class="no-ja-translation" data-ja-hash="d41742425aaafe5999e11ca90b26f088"><span class=en-original lang=en>If <var title="">worker global scope</var> is actually a
1527     <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object (i.e. the worker is a
1528     shared worker), and there are any <span title="relevant application
1529     cache">relevant application caches</span> that are identified by a
1530     manifest URL with the <span>same origin</span> as <var title="">url</var> and that have <var title="">url</var> as one of
1531     their entries, <em>not</em> excluding entries marked as <span title=concept-appcache-foreign>foreign</span>, then associate the
1532     <var title="">worker global scope</var> with the <span title=concept-appcache-selection>most appropriate application
1533     cache</span> of those that match.</span></li>
1534    
1535     <li>
1536    
1537     <p class="no-ja-translation" data-ja-hash="83920af54821d7c307267e9565d86ea3"><span class=en-original lang=en>Attempt to <span>fetch</span> the resource identified by <var title="">url</var>.</span></p>
1538    
1539 wakaba 1.112 <p class="no-ja-translation" data-ja-hash="26478052fa0ac3c2e89f64956f73b55f"><span class=en-original lang=en>If the attempt fails, or if the attempt involves any redirects
1540     to URIs that do not have the <span>same origin</span> as <var title="">url</var> (even if the final URI is at the <span>same
1541     origin</span> as the original <var title="">url</var>), then for
1542     each <code><a href=#worker>Worker</a></code> or <code><a href=#sharedworker>SharedWorker</a></code> object
1543     associated with <var title="">worker global scope</var>,
1544     <span>queue a task</span> to <span>fire a simple event</span>
1545     called <code title=event-error>error</code> at that
1546     object. Abort these steps.</span></p>
1547 wakaba 1.111
1548     <p class="no-ja-translation" data-ja-hash="a2c139226de4390d75b561512be824a7"><span class=en-original lang=en>If the attempt succeeds, then <a href=#decode-a-script-resource title="decode a script
1549     resource">decode the script resource</a> to obtain its <var title="">source</var>.</span></p>
1550    
1551     <p class="no-ja-translation" data-ja-hash="c880bce97c5a1aadccd8989fc4ec8551"><span class=en-original lang=en>Let <var title="">language</var> be JavaScript.</span></p>
1552    
1553     <p class="note has-ja-translation" data-ja-hash="5ba762159d9de3f8bd326fe0bcfac206"><span class=en-original lang=en>As with <code>script</code> elements, the MIME
1554     type of the script is ignored. Unlike with <code>script</code>
1555     elements, there is no way to override the type. It's always
1556     assumed to be JavaScript.</span><span class=ja-translation lang=ja><code>script</code> 要素と同様に、スクリプトの MIME 型は無視します。
1557     <code>script</code> 要素とは異なり、
1558     型を上書きする方法はありません。スクリプトは常に JavaScript
1559     と仮定します。</span></p> <!-- XXX people will complain about
1560     this. I guess we might want to examine the MIME type... -->
1561    
1562     </li>
1563    
1564     <li>
1565    
1566     <p class="no-ja-translation" data-ja-hash="604d3f52a6756f627f0e747b0d06e6ae"><span class=en-original lang=en>A new <span title=concept-script>script</span> is now
1567     created, as follows.</span></p>
1568    
1569     <p class="no-ja-translation" data-ja-hash="2dfcd0f76cde607de6cc88d70f390825"><span class=en-original lang=en>Create a new <span>script execution environment</span>
1570     set up as appropriate for the scripting language <var title="">language</var>.</span></p>
1571    
1572     <p class="no-ja-translation" data-ja-hash="fdf8b5f9ba18a31a8f48670142f51442"><span class=en-original lang=en>Parse/compile/initialize <var title="">source</var> using that
1573     <span>script execution environment</span>, as appropriate for <var title="">language</var>, and thus obtain a <span>list of code
1574     entry-points</span>; set the <i>initial code entry-point</i> to
1575     the entry-point for any executable code to be immediately run.</span></p>
1576    
1577     <p class="no-ja-translation" data-ja-hash="129927904de4572e52f5bc380711aa10"><span class=en-original lang=en>Set the <span>script's global object</span> to <var title="">worker global scope</var>.</span></p>
1578    
1579     <p class="no-ja-translation" data-ja-hash="02eeb9a0f925368a93666886c94bf9bf"><span class=en-original lang=en>Set the <span>script's browsing context</span> to <var title="">owner browsing context</var>.</span></p>
1580    
1581     <p class="no-ja-translation" data-ja-hash="104fe9ff67aec2141cd0733499cfef92"><span class=en-original lang=en>Set the <span>script's URL character encoding</span> to
1582     UTF-8. (This is just used for encoding non-ASCII characters in the
1583     query component of URLs.)</span></p>
1584    
1585     <p class="no-ja-translation" data-ja-hash="7570c80d1bbf45f73eb74befed51740d"><span class=en-original lang=en>Set the <span>script's base URL</span> to <var title="">url</var>.</span></p>
1586    
1587     </li>
1588    
1589     <li>
1590    
1591     <p class="no-ja-translation" data-ja-hash="6ae721aad21a83f4d53f37c8e20baaf4"><span class=en-original lang=en><strong>Closing orphan workers</strong>: Start monitoring the
1592     worker such that no sooner than it stops being either a
1593     <a href=#protected-worker>protected worker</a> or a <a href=#suspendable-worker>suspendable
1594     worker</a>, and no later than it stops being a
1595     <a href=#permissible-worker>permissible worker</a>, <var title="">worker global
1596     scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set
1597     to true<!-- v2-onclose and <span title="queue a task">a task is
1598     queued</span> to <span>fire a simple event</span> called <code
1599     title="event-close">close</code> at <var title="">worker global
1600     scope</var>-->.</span></p>
1601    
1602     </li>
1603    
1604     <li>
1605    
1606     <p class="no-ja-translation" data-ja-hash="24a8fa04f32239e0dafc1e98e466d6b4"><span class=en-original lang=en><strong>Suspending workers</strong>: Start monitoring the
1607     worker, such that whenever <var title="">worker global
1608     scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is false
1609     and the worker is a <a href=#suspendable-worker>suspendable worker</a>, the user
1610     agent suspends execution of script in that worker until such time
1611     as either the <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag switches
1612     to true or the worker stops being a <a href=#suspendable-worker>suspendable
1613     worker</a>.</span></p>
1614    
1615     </li>
1616    
1617     <li>
1618    
1619     <p class="no-ja-translation" data-ja-hash="4321156bbce7d4613215c6cd962a1dc4"><span class=en-original lang=en><span title="jump to a code entry-point">Jump</span> to the
1620     <span title=concept-script>script</span>'s <i>initial code
1621     entry-point</i>, and let that run until it either returns, fails
1622     to catch an exception, or gets prematurely aborted by the
1623     "<a href=#kill-a-worker>kill a worker</a>" or "<a href=#terminate-a-worker>terminate a worker</a>"
1624     algorithms defined below.</span></p>
1625    
1626 wakaba 1.151 <!-- v2-onclose
1627     <p class="note no-ja-translation" data-ja-hash="e632e340409f851c9423aafe27afe24f"><span class=en-original lang=en>If the script gets aborted by the "<span>kill a
1628     worker</span>" algorithm, then that same algorithm will cause
1629     there to only be a single <span title="concept-task">task</span>
1630 wakaba 1.111 in the <span>event loop</span> at the next step, namely the task
1631 wakaba 1.151 for the <code title="message-close">close</code> event. The
1632     "<span>terminate a worker</span>" algorithm removes all the
1633 wakaba 1.111 events.</span></p>
1634 wakaba 1.151 -->
1635 wakaba 1.111
1636     </li>
1637    
1638     <li><p class="no-ja-translation" data-ja-hash="cfc4a3473c7cde1f5a4133c349682bab"><span class=en-original lang=en>If <var title="">worker global scope</var> is actually a
1639     <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> object (i.e. the worker is
1640     a dedicated worker), then enable the <span>port message
1641     queue</span> of the worker's implicit port.</span></li>
1642    
1643     <li>
1644    
1645     <p class="no-ja-translation" data-ja-hash="ac8f871c5ad85c37527bc69c91141970"><span class=en-original lang=en><i title="">Event loop</i>: Wait until either there is a <span title=concept-task>task</span> in one of the <span>event
1646     loop</span>'s <span title="task queue">task queues</span> or <var title="">worker global scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set
1647     to true.</span></p>
1648    
1649     </li>
1650    
1651     <li>
1652    
1653     <p class="no-ja-translation" data-ja-hash="bcc803e78dd6f07ff20eaa1ca0d23303"><span class=en-original lang=en>Run the oldest task on one of the <span>event loop</span>'s
1654     <span title="task queue">task queues</span>, if any. The user
1655     agent may pick any <span>task queue</span>.</span></p>
1656    
1657     <p class="note no-ja-translation" data-ja-hash="2a401c207ed88f5206b2eb8a90fc91a6"><span class=en-original lang=en>The handling of events or the execution of
1658     callbacks might get prematurely aborted by the "<a href=#kill-a-worker>kill a
1659     worker</a>" or "<a href=#terminate-a-worker>terminate a worker</a>" algorithms
1660     defined below.</span></p>
1661    
1662     </li>
1663    
1664     <li>
1665    
1666     <p class="no-ja-translation" data-ja-hash="0a62cf7225c4d215f05940236b695d05"><span class=en-original lang=en>Remove the task run in the previous step, if any, from its
1667     <span>task queue</span>.</span></p>
1668    
1669     </li>
1670    
1671     <li>
1672    
1673     <p class="no-ja-translation" data-ja-hash="779764122a6b7c3177782cbb51d5c914"><span class=en-original lang=en>If there are any more events in the <span>event loop</span>'s
1674     <span title="task queue">task queues</span> or if <var title="">worker global scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set
1675     to false, then jump back to the step above labeled <i>event
1676     loop</i>.</span></p>
1677    
1678     </li>
1679    
1680     <li>
1681    
1682     <p class="no-ja-translation" data-ja-hash="fb906768fcbbd4867b29825a7893fe6e"><span class=en-original lang=en>If there are any outstanding transactions that have callbacks
1683     that involve <span title=concept-script>scripts</span> whose
1684     <span title="script's global object">global object</span> is the
1685     <var title="">worker global scope</var>, roll them back (without
1686     invoking any of the callbacks).</span></p>
1687    
1688     </li>
1689    
1690     <li>
1691    
1692     <p class="no-ja-translation" data-ja-hash="77a63b1af244b3bfda62ba8d7bf76ea9"><span class=en-original lang=en>Empty the <var title="">worker global scope</var>'s <span>list
1693     of active timeouts</span> and its <span>list of active
1694     intervals</span>.</span></p>
1695    
1696     </li>
1697    
1698     <!-- v2-onclose
1699     <li>
1700    
1701     <p class="no-ja-translation" data-ja-hash="4cd03dfffdcf4808bf404c9bf5107eff"><span class=en-original lang=en>For each <code>Worker</code> or <code>SharedWorker</code>
1702     object associated with <var title="">worker global scope</var>,
1703     <span>queue a task</span> to <span>fire a simple event</span>
1704     called <code title="event-close">close</code> at that object.</span></p>
1705    
1706     </li>
1707     -->
1708 wakaba 1.156 </ol>
1709    
1710     <hr>
1711    
1712     <p class="no-ja-translation" data-ja-hash="cd7920afdad85f0228b3501a68536c9a"><span class=en-original lang=en>When a user agent is to <dfn id=kill-a-worker>kill a worker</dfn> it must
1713 wakaba 1.111 run the following steps in parallel with the worker's main loop (the
1714     "<a href=#run-a-worker>run a worker</a>" processing model defined above):</span></p>
1715    
1716 wakaba 1.156 <ol>
1717    
1718     <!-- v2-onclose
1719 wakaba 1.111 <li><p class="no-ja-translation" data-ja-hash="6806774d3d9a55fb29d85301b3552ad6"><span class=en-original lang=en>If the worker's <code>WorkerGlobalScope</code> object's
1720     <span title="dom-WorkerGlobalScope-closing">closing</span> flag is
1721     false, <span>queue a task</span> to <span>fire a simple
1722     event</span> called <code title="event-close">close</code> at the
1723     worker's <code>WorkerGlobalScope</code> object.</span></p></li>
1724 wakaba 1.156 -->
1725    
1726     <li><p class="no-ja-translation" data-ja-hash="4cc11724db0ff9175e61747ac0b27285"><span class=en-original lang=en>Set the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag to
1727 wakaba 1.111 true.</span></li>
1728    
1729     <!-- v2-onclose
1730     <li><p class="no-ja-translation" data-ja-hash="4e3c7a6ff9a9f675020d75a10705eecc"><span class=en-original lang=en>Wait a user-agent-defined amount of time. If the "<span>run
1731     a worker</span>" processing model defined above immediately starts
1732     running event listeners registered for the <code
1733     title="event-close">close</code> event, this time should not be
1734     zero &mdash; the idea is that the <code
1735     title="event-close">close</code> event can be used to clean up
1736     when shutting down unexpectedly.</span></p></li>
1737     -->
1738    
1739     <li><p class="no-ja-translation" data-ja-hash="09b4e752d892d358db0eb9f001f5a26c"><span class=en-original lang=en>If there are any <span title=concept-task>tasks</span>
1740     queued in the <span>event loop</span>'s <span title="task
1741     queue">task queues</span><!-- v2-onclose other than the <code
1742     title="event-close">close</code> event that this algorithm just
1743     added-->, discard them without processing them.</span></li>
1744    
1745     <!-- v2-onclose
1746     <li><p class="no-ja-translation" data-ja-hash="f62a56e5aab0f0d08a9fa1e63f1983c5"><span class=en-original lang=en>If the <code title="event-close">close</code> event that
1747     this algorithm just queued hasn't yet been dispatched, then abort
1748     the script currently running in the worker.</span></p></li>
1749     -->
1750    
1751     <li><p class="has-ja-translation" data-ja-hash="a53f0acde0e4a21781c4b31d5a0f110a"><span class=en-original lang=en>Wait a user-agent-defined amount of time.</span><span class=ja-translation lang=ja>利用者エージェント定義の時間、待ちます。</span></li>
1752    
1753     <li><p class="no-ja-translation" data-ja-hash="fbb7fecc04423fb209634e5473bd7ec1"><span class=en-original lang=en>Abort the script currently running in the worker<!--
1754     v2-onclose (if any script is running, then it will be a handler for
1755     the <code title="event-close">close</code> event)-->.</span></li>
1756    
1757 wakaba 1.156 </ol>
1758    
1759     <p class="no-ja-translation" data-ja-hash="065b6253058d6c118693257b76ed3444"><span class=en-original lang=en>User agents may invoke the "<a href=#kill-a-worker>kill a worker</a>"
1760 wakaba 1.111 processing model on a worker at any time, e.g. in response to user
1761     requests, in response to CPU quota management, or when a worker
1762     stops being an <a href=#active-needed-worker>active needed worker</a> if the worker
1763     continues executing even after its <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag was
1764     set to true.</span></p>
1765    
1766 wakaba 1.156 <hr>
1767    
1768     <p class="no-ja-translation" data-ja-hash="af2a7479f3a6fc4f418bd8e7255c63be"><span class=en-original lang=en>When a user agent is to <dfn id=terminate-a-worker>terminate a worker</dfn> it must run
1769 wakaba 1.111 the following steps in parallel with the worker's main loop (the
1770     "<a href=#run-a-worker>run a worker</a>" processing model defined above):</span></p>
1771    
1772 wakaba 1.156 <ol>
1773    
1774     <li><p class="no-ja-translation" data-ja-hash="4cc11724db0ff9175e61747ac0b27285"><span class=en-original lang=en>Set the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's
1775 wakaba 1.111 <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag to
1776     true.</span></li>
1777    
1778     <li><p class="no-ja-translation" data-ja-hash="a9cf50df3de2e3788a3125ace8cf61f5"><span class=en-original lang=en>If there are any <span title=concept-task>tasks</span>
1779     queued in the <span>event loop</span>'s <span title="task
1780     queue">task queues</span>, discard them without processing
1781     them.</span></li>
1782    
1783     <li><p class="has-ja-translation" data-ja-hash="fcb471f3c8cace3a86095dcb29d25515"><span class=en-original lang=en>Abort the script currently running in the worker.</span><span class=ja-translation lang=ja>労働者中で現在走っているスクリプトを停止します。</span></li>
1784    
1785     <li><p class="no-ja-translation" data-ja-hash="533246b74ff40190332c8ca473d635b5"><span class=en-original lang=en>If the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object is
1786     actually a <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code> object (i.e. the
1787     worker is a dedicated worker), then empty the <span>port message
1788     queue</span> of the port that the worker's implicit port is
1789     entangled with.</span></li>
1790    
1791 wakaba 1.156 </ol>
1792    
1793     <hr>
1794    
1795     <p class="no-ja-translation" data-ja-hash="232ca3945fb57a3baa9cc0675ff99caa"><span class=en-original lang=en>The <span>task source</span> for the tasks mentioned above is the
1796 wakaba 1.133 <span>DOM manipulation task source</span>.</span></p>
1797    
1798    
1799 wakaba 1.139 <h3 id=runtime-script-errors class="has-ja-translation" data-ja-hash="eb260f04266c3b94080b5c3f88c55a31"><span class=en-original lang=en><span class=secno>4.7 </span>Runtime script errors</span><span class=ja-translation lang=ja><span class=secno>4.7 </span>実行時スクリプト誤り</span></h3>
1800 wakaba 1.111
1801 wakaba 1.137 <p class="no-ja-translation" data-ja-hash="7bd3f1cdf85033908e9608a3f27fc9d1"><span class=en-original lang=en>Whenever an uncaught runtime script error occurs in one of the
1802     worker's scripts, if the error did not occur while handling a
1803     previous script error, the user agent must <span>report the
1804     error</span> using the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <code title=handler-WorkerGlobalScope-onerror><a href=#handler-workerglobalscope-onerror>onerror</a></code>
1805     attribute. <a href=#refsHTML5>[HTML5]</a></span></p>
1806 wakaba 1.111
1807 wakaba 1.137 <p class="no-ja-translation" data-ja-hash="1d4d18d12610442bca7072503caba230"><span class=en-original lang=en>For shared workers, if the error is still <i title=concept-error-nothandled>not handled</i> afterwards, or if
1808 wakaba 1.120 the error occurred while handling a previous script error, the error
1809 wakaba 1.137 should be reported to the user. <a href=#refsHTML5>[HTML5]</a></span></p>
1810 wakaba 1.111
1811 wakaba 1.120 <p class="no-ja-translation" data-ja-hash="44fbeda15b001a0dc82fe40089bb81bb"><span class=en-original lang=en>For dedicated workers, if the error is still <i title=concept-error-nothandled>not handled</i> afterwards, or if
1812     the error occurred while handling a previous script error, the user
1813 wakaba 1.111 agent must <span>queue a task</span> to <a href=#fire-a-worker-error-event>fire a worker error
1814     event</a> at the <code><a href=#worker>Worker</a></code> object associated with the
1815     worker.</span></p>
1816    
1817     <p class="no-ja-translation" data-ja-hash="c96676fcc4ab90893eca070f70c76249"><span class=en-original lang=en>When the user agent is to <dfn id=fire-a-worker-error-event>fire a worker error event</dfn> at
1818     a <code><a href=#worker>Worker</a></code> object, it must dispatch an event that uses
1819     the <code><a href=#errorevent>ErrorEvent</a></code> interface, with the name <code title=event-error>error</code>, that doesn't bubble and is
1820     cancelable, with its <code title=dom-ErrorEvent-message><a href=#dom-errorevent-message>message</a></code>, <code title=dom-ErrorEvent-filename><a href=#dom-errorevent-filename>filename</a></code>, and <code title=dom-ErrorEvent-lineno><a href=#dom-errorevent-lineno>lineno</a></code> attributes set
1821     appropriately. The default action of this event depends on whether
1822     the <code><a href=#worker>Worker</a></code> object is itself in a worker. If it is, and
1823     that worker is also a dedicated worker, then the user agent must
1824     again <span>queue a task</span> to <a href=#fire-a-worker-error-event>fire a worker error
1825     event</a> at the <code><a href=#worker>Worker</a></code> object associated with
1826     <em>that</em> worker. Otherwise, then the error should be reported
1827     to the user.</span></p>
1828    
1829 wakaba 1.133 <p class="no-ja-translation" data-ja-hash="232ca3945fb57a3baa9cc0675ff99caa"><span class=en-original lang=en>The <span>task source</span> for the tasks mentioned above is the
1830     <span>DOM manipulation task source</span>.</span></p>
1831    
1832 wakaba 1.156 <hr>
1833    
1834     <pre class="idl no-ja-translation" data-ja-hash="75e1a0de2be298c9db36c73510aae01d"><span class=en-original lang=en>interface <dfn id=errorevent>ErrorEvent</dfn> : Event {
1835 wakaba 1.138 readonly attribute DOMString <a href=#dom-errorevent-message title=dom-ErrorEvent-message>message</a>;
1836     readonly attribute DOMString <a href=#dom-errorevent-filename title=dom-ErrorEvent-filename>filename</a>;
1837 wakaba 1.111 readonly attribute unsigned long <a href=#dom-errorevent-lineno title=dom-ErrorEvent-lineno>lineno</a>;
1838 wakaba 1.138 void <a href=#dom-errorevent-initerrorevent title=dom-ErrorEvent-initErrorEvent>initErrorEvent</a>(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in DOMString messageArg, in DOMString filenameArg, in unsigned long linenoArg);
1839     void <a href=#dom-errorevent-initerroreventns title=dom-ErrorEvent-initErrorEventNS>initErrorEventNS</a>(in DOMString namespaceURIArg, in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in DOMString messageArg, in DOMString filenameArg, in unsigned long linenoArg);
1840 wakaba 1.111 };</span></pre>
1841    
1842 wakaba 1.155 <p class="no-ja-translation" data-ja-hash="741eed0816bcef0dfb1fed290dc14c9c"><span class=en-original lang=en>The <dfn id=dom-errorevent-initerrorevent title=dom-ErrorEvent-initErrorEvent><code>initErrorEvent()</code></dfn>
1843     and <dfn id=dom-errorevent-initerroreventns title=dom-ErrorEvent-initErrorEventNS><code>initErrorEventNS()</code></dfn>
1844 wakaba 1.111 methods must initialize the event in a manner analogous to the
1845 wakaba 1.155 similarly-named methods in the DOM Events interfaces. <a href=#refsDOMEVENTS>[DOMEVENTS]</a></span></p>
1846 wakaba 1.111
1847     <p class="no-ja-translation" data-ja-hash="c3d08d500554faa699d875e3015209b9"><span class=en-original lang=en>The <dfn id=dom-errorevent-message title=dom-ErrorEvent-message><code>message</code></dfn>
1848     attribute represents the error message.</span></p>
1849    
1850 wakaba 1.120 <p class="no-ja-translation" data-ja-hash="27affe597e932e64fc4db85fad27e91b"><span class=en-original lang=en>The <dfn id=dom-errorevent-filename title=dom-ErrorEvent-filename><code>filename</code></dfn>
1851 wakaba 1.111 attribute represents the <span>absolute URL</span> of the script in
1852 wakaba 1.120 which the error originally occurred.</span></p>
1853 wakaba 1.111
1854 wakaba 1.120 <p class="no-ja-translation" data-ja-hash="4322851b5483408bad81570533bf6251"><span class=en-original lang=en>The <dfn id=dom-errorevent-lineno title=dom-ErrorEvent-lineno><code>lineno</code></dfn>
1855     attribute represents the line number where the error occurred in the
1856 wakaba 1.111 script.</span></p>
1857    
1858    
1859    
1860 wakaba 1.139 <h3 id=creating-workers class="has-ja-translation" data-ja-hash="f0a4732d38d01e3d103b68468f9fe234"><span class=en-original lang=en><span class=secno>4.8 </span>Creating workers</span><span class=ja-translation lang=ja><span class=secno>4.8 </span>労働者の作成</span></h3>
1861 wakaba 1.111
1862 wakaba 1.139 <h4 id=the-abstractworker-abstract-interface class="has-ja-translation" data-ja-hash="fe5227371e801f4ac588d0d07472a900" data-ja-real-hash="fea226dea005bb8238586cd20b34aa2f"><span class=en-original lang=en><span class=secno>4.8.1 </span>The <code><a href=#abstractworker>AbstractWorker</a></code> abstract interface</span><span class=ja-translation lang=ja><span class=secno>4.8.1 </span><code><a href=#abstractworker>AbstractWorker</a></code> 抽象界面</span></h4>
1863 wakaba 1.111
1864 wakaba 1.137 <pre class="idl no-ja-translation" data-ja-hash="84c84199da6cc07390dbf49ed3f9a34c"><span class=en-original lang=en>interface <dfn id=abstractworker>AbstractWorker</dfn> {
1865     attribute <span>Function</span> <a href=#handler-abstractworker-onerror title=handler-AbstractWorker-onerror>onerror</a>;
1866     <!-- v2-onclose attribute <span>Function</span> <span title="handler-AbstractWorker-onclose">onclose</span>; -->
1867 wakaba 1.111 };</span></pre>
1868    
1869     <p class="no-ja-translation" data-ja-hash="b6a7afc5ececf4988bace69746cd2a40"><span class=en-original lang=en>Objects implementing the <code><a href=#abstractworker>AbstractWorker</a></code> interface
1870     must also implement the <code>EventTarget</code> interface.</span></p>
1871    
1872     <p class="no-ja-translation" data-ja-hash="94f7748c361254422af5d1ae954849ee"><span class=en-original lang=en>The following are the <span>event handler attributes</span> (and their corresponding <span title="event handler event type">event handler event types</span>)
1873     that must be supported, as DOM attributes, by objects implementing
1874     the <code><a href=#abstractworker>AbstractWorker</a></code> interface:</span></p>
1875    
1876 wakaba 1.156 <table>
1877     <thead>
1878     <tr><th class="no-ja-translation" data-ja-hash="c85726f0c6ba202006ec1f912e68aa76"><span class=en-original lang=en><span title="event handler attributes">event handler attribute</span> </span><th class="no-ja-translation" data-ja-hash="3fc98eebba71602c62d8b2fd74645dc9"><span class=en-original lang=en><span>Event handler event type</span>
1879     </span><tbody>
1880     <tr><td class="no-ja-translation" data-ja-hash="797655c7ba76af81be91c1f52bf92e5d"><span class=en-original lang=en><dfn id=handler-abstractworker-onerror title=handler-AbstractWorker-onerror><code>onerror</code></dfn> </span><td class="no-ja-translation" data-ja-hash="bf1b78c16e7c3a3de662d83f487bffff"><span class=en-original lang=en> <code title=event-error>error</code>
1881 wakaba 1.111 <!-- v2-onclose --></span><!--<tr><td class="no-ja-translation" data-ja-hash="5bacdeaff60366f7971634c5de89cc1a"><span class=en-original lang=en><dfn title="handler-AbstractWorker-onclose"><code>onclose</code></dfn> </span><td class="no-ja-translation" data-ja-hash="e899358e829911a25c083ed9bc6519e6"><span class=en-original lang=en> <code title="event-close">close</code> -->
1882 wakaba 1.156 </span></table>
1883    
1884    
1885    
1886     <h4 id=dedicated-workers-and-the-worker-interface class="no-ja-translation" data-ja-hash="4d0010617afd55731512f81d11e29921"><span class=en-original lang=en><span class=secno>4.8.2 </span>Dedicated workers and the <code><a href=#worker>Worker</a></code> interface</span></h4>
1887 wakaba 1.111
1888 wakaba 1.154 <pre class="idl no-ja-translation" data-ja-hash="d3ff732dd43e4f43a4fe39374e4b65ae"><span class=en-original lang=en>[<a href=#dom-worker title=dom-Worker>Constructor</a>(in DOMString scriptURL)]
1889 wakaba 1.111 interface <dfn id=worker>Worker</dfn> : <a href=#abstractworker>AbstractWorker</a> {
1890     void <a href=#dom-worker-terminate title=dom-Worker-terminate>terminate</a>();
1891    
1892 wakaba 1.154 void <a href=#dom-worker-postmessage title=dom-Worker-postMessage>postMessage</a>(in any message, optional in <span>MessagePortArray</span> ports);<!--
1893 wakaba 1.111 <span>MessagePort</span> <span title="dom-Worker-startConversation">startConversation</span>(in any message);-->
1894 wakaba 1.137 attribute <span>Function</span> <a href=#handler-worker-onmessage title=handler-Worker-onmessage>onmessage</a>;
1895 wakaba 1.111 };</span></pre>
1896    
1897     <p class="no-ja-translation" data-ja-hash="c01e50cb895f4eaa527128e73934b76c"><span class=en-original lang=en>The <dfn id=dom-worker-terminate title=dom-Worker-terminate><code>terminate()</code></dfn> method,
1898     when invoked, must cause the "<a href=#terminate-a-worker>terminate a worker</a>"
1899     algorithm to be run on the worker with with the object is
1900     associated.</span></p>
1901    
1902     <p class="no-ja-translation" data-ja-hash="f306158a0574a5376130b398642a9bc3"><span class=en-original lang=en><code><a href=#worker>Worker</a></code> objects act as if they had an implicit
1903     <code>MessagePort</code> associated with them. This port is part of
1904     a channel that is set up when the worker is created, but it is not
1905     exposed. This object must never be garbage collected before the
1906     <code><a href=#worker>Worker</a></code> object.</span></p>
1907    
1908     <p class="no-ja-translation" data-ja-hash="3347b0248a16085b3e8a073aed81f1d8"><span class=en-original lang=en>All messages received by that port must immediately be retargeted
1909     at the <code><a href=#worker>Worker</a></code> object.</span></p>
1910    
1911     <p class="no-ja-translation" data-ja-hash="58e82dfd8fd30e4340d6d1f7f7a08239"><span class=en-original lang=en>The <dfn id=dom-worker-postmessage title=dom-Worker-postMessage><code>postMessage()</code></dfn><!--
1912     and <dfn
1913     title="dom-Worker-startConversation"><code>startConversation()</code></dfn>-->
1914     method<!--s (startConversation)--> on <code><a href=#worker>Worker</a></code> objects
1915     must act as if, when invoked, it<!--/they (startConversation)-->
1916     immediately invoked the method of the same name on the port, with
1917     the same arguments, and returned the same return value.</span></p>
1918    
1919     <p class="no-ja-translation" data-ja-hash="e9b0de1981a1ae0a443580d68868219a"><span class=en-original lang=en>The following are the <span>event handler attributes</span> (and their corresponding <span title="event handler event type">event handler event types</span>)
1920     that must be supported, as DOM attributes, by objects implementing
1921     the <code><a href=#worker>Worker</a></code> interface:</span></p>
1922    
1923 wakaba 1.156 <table>
1924     <thead>
1925     <tr><th class="no-ja-translation" data-ja-hash="c85726f0c6ba202006ec1f912e68aa76"><span class=en-original lang=en><span title="event handler attributes">event handler attribute</span> </span><th class="no-ja-translation" data-ja-hash="3fc98eebba71602c62d8b2fd74645dc9"><span class=en-original lang=en><span>Event handler event type</span>
1926     </span><tbody>
1927     <tr><td class="no-ja-translation" data-ja-hash="936f67c1111af9460db35858624e3ce9"><span class=en-original lang=en><dfn id=handler-worker-onmessage title=handler-Worker-onmessage><code>onmessage</code></dfn> </span><td class="no-ja-translation" data-ja-hash="fe07e2527bf13c457386ab4807af84a0"><span class=en-original lang=en> <code title=event-message>message</code>
1928     </span></table>
1929    
1930     <hr>
1931    
1932     <p class="no-ja-translation" data-ja-hash="071022f5c10c547e44e7e3a998659333"><span class=en-original lang=en>When the <dfn id=dom-worker title=dom-Worker><code>Worker(<var title="">scriptURL</var>)</code></dfn> constructor is invoked, the
1933 wakaba 1.111 user agent must run the following steps:</span></p>
1934    
1935 wakaba 1.156 <ol>
1936    
1937     <li><p class="no-ja-translation" data-ja-hash="2ca4870c8239974ba241fd037e090c44"><span class=en-original lang=en><span title="resolve a url">Resolve</span> the <var title="">scriptURL</var> argument relative to the <span>first
1938 wakaba 1.121 script</span>'s <span title="script's base URL">base URL</span>,
1939     when the method is invoked.</span></li>
1940 wakaba 1.111
1941     <li><p class="has-ja-translation" data-ja-hash="160444b5a61c1e71f39825a01936237f"><span class=en-original lang=en>If this fails, throw a <code>SYNTAX_ERR</code>
1942     exception.</span><span class=ja-translation lang=ja>これが失敗した場合、 <code>SYNTAX_ERR</code>
1943     例外を投げます。</span></li>
1944    
1945     <li><p class="no-ja-translation" data-ja-hash="8c1bc8b7160649d18a3c7780560d2b6d"><span class=en-original lang=en>If the <span>origin</span> of the resulting <span>absolute
1946     URL</span> is not the <span title="same origin">same</span> as the
1947     origin of the <span title=concept-script>script</span> that
1948     invoked the constructor, then throw a <span>security
1949     exception</span>.</span></li>
1950    
1951     <li><p class="no-ja-translation" data-ja-hash="b5bddf55144f8b1ff3c2a755b8ada3e0"><span class=en-original lang=en><span>Create a new <code><a href=#dedicatedworkerglobalscope>DedicatedWorkerGlobalScope</a></code>
1952     object</span>. Let <var title="">worker global scope</var> be this
1953     new object.</span></li>
1954    
1955     <li><p class="no-ja-translation" data-ja-hash="5f11902e2367f64698f9d31e03a9d235"><span class=en-original lang=en>Create a new <code><a href=#worker>Worker</a></code> object, associated with
1956     <var title="">worker global scope</var>. Let <var title="">worker</var> be this new object.</span></li>
1957    
1958     <li><p class="no-ja-translation" data-ja-hash="7b066bb31c499860c38db05cac15b6b9"><span class=en-original lang=en><span>Create a <code>MessagePort</code> object</span> owned
1959     by the <span title="script's global scope">global scope</span> of
1960     the <span title=concept-script>script</span> that invoked the
1961     constructor. Let this be the <var title="">outside
1962     port</var>.</span></li>
1963    
1964     <li><p class="has-ja-translation" data-ja-hash="91024eaaebdc23ea683ace1b3e316962"><span class=en-original lang=en>Associate the <var title="">outside port</var> with <var title="">worker</var>.</span><span class=ja-translation lang=ja><var title="">outside port</var> を <var
1965     title="">worker</var> に関連付けます。</span></li>
1966    
1967     <li><p class="no-ja-translation" data-ja-hash="2d1b035dbaad3feca57eb124d161b034"><span class=en-original lang=en><span>Create a <code>MessagePort</code> object</span> owned
1968     by <var title="">worker global scope</var>. Let <var title="">inside port</var> be this new object.</span></li>
1969    
1970     <li><p class="no-ja-translation" data-ja-hash="c7df111ebbfeab4bffdbe80d19fdb0ba"><span class=en-original lang=en>Associate <var title="">inside port</var> with <var title="">worker global scope</var>.</span></li>
1971    
1972     <li><p class="no-ja-translation" data-ja-hash="bf2642ced659847cb4402165d2ab3a8e"><span class=en-original lang=en><span>Entangle</span> <var title="">outside port</var> and
1973     <var title="">inside port</var>.</span></li>
1974    
1975     <li><p class="has-ja-translation" data-ja-hash="2c5bd80faeda34c67a2533f32a477c51"><span class=en-original lang=en>Return <var title="">worker</var>, and run the following
1976     steps asynchronously.</span><span class=ja-translation lang=ja><var title="">worker</var> を返し、以降の段階を非同期に走らせます。</span></li>
1977    
1978     <li><p class="no-ja-translation" data-ja-hash="486f13bccfc4521d81f95f8a83a34838"><span class=en-original lang=en>Enable <var title="">inside port</var>'s <span>port message
1979     queue</span>.</span></li>
1980    
1981     <li><p class="no-ja-translation" data-ja-hash="f226f14fb6f714ae0ebb2e1d19b80cb0"><span class=en-original lang=en>Enable <var title="">outside port</var>'s <span>port message
1982     queue</span>.</span></li>
1983    
1984     <li>
1985    
1986     <p class="no-ja-translation" data-ja-hash="55e6e7d35bf5d3d20aefe01d055f5e6b"><span class=en-original lang=en>Let <var title="">docs</var> be the <a href=#list-of-relevant-document-objects-to-add>list of relevant
1987     <code>Document</code> objects to add</a> given the <span title="script's global scope">global scope</span> of the <span title=concept-script>script</span> that invoked the
1988     constructor.</span></p>
1989    
1990     </li>
1991    
1992     <li>
1993    
1994     <p class="no-ja-translation" data-ja-hash="55e64a61fc96598db79195cddb4bb2f9"><span class=en-original lang=en><a href="#add-a-document-to-the-worker's-documents" title="add a document to the worker's documents">Add to
1995     <var title="">worker global scope</var>'s list of <span>the
1996     worker's <code>Document</code>s</span></a> the
1997     <code>Document</code> objects in <var title="">docs</var>.</span></p>
1998    
1999     </li>
2000    
2001     <li>
2002    
2003     <p class="no-ja-translation" data-ja-hash="7c3d95cd57d78baee3024bef7b2b71f6"><span class=en-original lang=en>If the <span title="script's global scope">global scope</span>
2004     of the <span title=concept-script>script</span> that invoked the
2005     constructor is a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object (i.e. we
2006     are creating a nested worker), add <var title="">worker global
2007     scope</var> to the list of <a href="#the-worker's-workers">the worker's workers</a> of the
2008     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object that is the <span title="script's global scope">global scope</span> of the <span title=concept-script>script</span> that invoked the
2009     constructor.</span></p>
2010    
2011     </li>
2012    
2013     <li>
2014    
2015     <p class="no-ja-translation" data-ja-hash="8d52f75615bdf14ecca1950ce2fe376b"><span class=en-original lang=en><a href=#run-a-worker>Run a worker</a> for the resulting <span>absolute
2016     URL</span>, with the <span>script browsing context</span> of the
2017     script that invoked the method as the <var title="">owner browsing
2018     context</var>, and with <var title="">worker global scope</var> as
2019     the global scope.</span></p>
2020    
2021     </li>
2022    
2023 wakaba 1.156 </ol>
2024    
2025     <p class="no-ja-translation" data-ja-hash="62d6758eaf2020c4112ab186636f4f33"><span class=en-original lang=en>This constructor must be visible when the <span>script's global
2026 wakaba 1.124 scope</span> is either a <code>Window</code> object or an object
2027     implementing the <code><a href=#workerutils>WorkerUtils</a></code> interface.</span></p>
2028    
2029    
2030 wakaba 1.139 <h4 id=shared-workers-and-the-sharedworker-interface class="no-ja-translation" data-ja-hash="3b77b75af8223662d0137a2dd84957ab"><span class=en-original lang=en><span class=secno>4.8.3 </span>Shared workers and the <code><a href=#sharedworker>SharedWorker</a></code> interface</span></h4>
2031 wakaba 1.111
2032     <pre class="idl no-ja-translation" data-ja-hash="f72ede7ba5104464a3b52f4315042c5d"><span class=en-original lang=en>[<a href=#dom-sharedworker title=dom-SharedWorker>Constructor</a>(in DOMString scriptURL, in DOMString name)]
2033     interface <dfn id=sharedworker>SharedWorker</dfn> : <a href=#abstractworker>AbstractWorker</a> {
2034     readonly attribute <span>MessagePort</span> <a href=#dom-sharedworker-port title=dom-SharedWorker-port>port</a>;
2035     };</span></pre>
2036    
2037     <p class="no-ja-translation" data-ja-hash="5cf4affd83f6594d8f8bc1a32f68ab35"><span class=en-original lang=en>The <dfn id=dom-sharedworker-port title=dom-SharedWorker-port><code>port</code></dfn>
2038     attribute must return the value it was assigned by the object's
2039     constructor. It represents the <code>MessagePort</code> for
2040     communicating with the shared worker.</span></p>
2041    
2042     <p class="no-ja-translation" data-ja-hash="a0ab2a2723152011df53c0fc544b493b"><span class=en-original lang=en>When the <dfn id=dom-sharedworker title=dom-SharedWorker><code>SharedWorker(<var title="">scriptURL</var>, <var title="">name</var>)</code></dfn>
2043     constructor is invoked, the user agent must run the following
2044     steps:</span></p>
2045    
2046 wakaba 1.156 <ol>
2047    
2048     <li><p class="has-ja-translation" data-ja-hash="3219e42f1040482201a693e248f580cb"><span class=en-original lang=en><span title="resolve a url">Resolve</span> the <var title="">scriptURL</var> argument.</span><span class=ja-translation lang=ja><var
2049 wakaba 1.111 title="">scriptURL</var> 引数を<span title="resolve a url">解決</span>します。</span></li>
2050    
2051     <li><p class="has-ja-translation" data-ja-hash="160444b5a61c1e71f39825a01936237f"><span class=en-original lang=en>If this fails, throw a <code>SYNTAX_ERR</code>
2052     exception.</span><span class=ja-translation lang=ja>これが失敗した場合、 <code>SYNTAX_ERR</code>
2053     例外を投げます。</span></li>
2054    
2055     <li><p class="no-ja-translation" data-ja-hash="b087dd24bd7b57655bef9f719db30b9a"><span class=en-original lang=en>If the <span>origin</span> of the resulting <span>absolute
2056     URL</span> is not the <span title="same origin">same</span> as the
2057     origin of the script that invoked the constructor, then throw a
2058     <span>security exception</span>.</span></li>
2059    
2060     <li>
2061    
2062     <p class="no-ja-translation" data-ja-hash="55e6e7d35bf5d3d20aefe01d055f5e6b"><span class=en-original lang=en>Let <var title="">docs</var> be the <a href=#list-of-relevant-document-objects-to-add>list of relevant
2063     <code>Document</code> objects to add</a> given the <span title="script's global scope">global scope</span> of the <span title=concept-script>script</span> that invoked the
2064     constructor.</span></p>
2065    
2066     </li>
2067    
2068     <li>
2069    
2070     <p class="has-ja-translation" data-ja-hash="683a2c0080e014b9eae98b884ccaf7e4"><span class=en-original lang=en>Execute the following substeps atomically:</span><span class=ja-translation lang=ja>次の部分段階群を原子的に実行します。</span></p>
2071    
2072 wakaba 1.156 <ol>
2073    
2074     <li><p class="no-ja-translation" data-ja-hash="b38ef0f6a7b346d45c984332a0b8776d"><span class=en-original lang=en>Create a new <code><a href=#sharedworker>SharedWorker</a></code> object, which will
2075 wakaba 1.111 shortly be associated with a <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code>
2076     object. Let this <code><a href=#sharedworker>SharedWorker</a></code> object be <var title="">worker</var>.</span></li>
2077    
2078     <li><p class="no-ja-translation" data-ja-hash="629bd7f10d8162f8dbf21128830192dc"><span class=en-original lang=en><span>Create a <code>MessagePort</code> object</span>
2079     owned by the <span title="script's global scope">global
2080     scope</span> of the script that invoked the method. Let this be
2081     the <var title="">outside port</var>.</span></li>
2082    
2083     <li><p class="no-ja-translation" data-ja-hash="2945bc791092fa6a9100ef8df34f4c10"><span class=en-original lang=en>Assign <var title="">outside port</var> to the <code title=dom-SharedWorker-port><a href=#dom-sharedworker-port>port</a></code> attribute of <var title="">worker</var>.</span></li>
2084    
2085     <li>
2086    
2087     <p class="no-ja-translation" data-ja-hash="a5402d09db1c68d0e688bfc726bfb83a"><span class=en-original lang=en>If there exists a <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object
2088     whose <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a>
2089     flag is false, whose <code title=dom-WorkerGlobalScope-name>name</code> attribute is
2090     exactly equal to the <var title="">name</var> argument, and
2091     whose <code title=dom-WorkerGlobalScope-location><a href=#dom-workerglobalscope-location>location</a></code> attribute
2092     represents an <span>absolute URL</span> that has the <span>same
2093     origin</span> as the resulting <span>absolute URL</span>, then
2094     run these substeps:</span></p>
2095    
2096 wakaba 1.156 <ol>
2097    
2098     <li><p class="no-ja-translation" data-ja-hash="f7fe188afbd752dfa48eb004c7dadd66"><span class=en-original lang=en>Let <var title="">worker global scope</var> be that
2099 wakaba 1.111 <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code> object.</span></li>
2100    
2101     <li><p class="no-ja-translation" data-ja-hash="313c7e6a97ecf9eceaccdf8015b78abe"><span class=en-original lang=en>If <var title="">worker global scope</var>'s <code title=dom-WorkerGlobalScope-location><a href=#dom-workerglobalscope-location>location</a></code>
2102     attribute represents an <span>absolute URL</span> that is not
2103     exactly equal to the resulting <span>absolute URL</span>, then
2104     throw a <code>URL_MISMATCH_ERR</code> exception and abort all
2105     these steps.</span></li>
2106    
2107     <li><p class="has-ja-translation" data-ja-hash="9c4f87efaa1e868cd6bf63dbffa749c0"><span class=en-original lang=en>Associate <var title="">worker</var> with <var title="">worker global scope</var>.</span><span class=ja-translation lang=ja><var title="">worker</var> を <var title="">worker
2108     global scope</var> に関連付けます。</span></li>
2109    
2110     <li><p class="no-ja-translation" data-ja-hash="bab9c8cea075e0f3614c731f09b49892"><span class=en-original lang=en><span>Create a <code>MessagePort</code> object</span>
2111     owned by <var title="">worker global scope</var>. Let this
2112     be the <var title="">inside port</var>.</span></li>
2113    
2114     <li><p class="no-ja-translation" data-ja-hash="bf2642ced659847cb4402165d2ab3a8e"><span class=en-original lang=en><span>Entangle</span> <var title="">outside port</var>
2115     and <var title="">inside port</var>.</span></li>
2116    
2117     <li><p class="has-ja-translation" data-ja-hash="ebb713e9e29aab450d79b533c42b67ae"><span class=en-original lang=en>Return <var title="">worker</var> and perform the next
2118     step asynchronously.</span><span class=ja-translation lang=ja><var title="">worker</var> を返し、
2119     次の段階を非同期に実行します。</span></li>
2120    
2121     <li><p class="no-ja-translation" data-ja-hash="54fc802e5e886ae34c575b12f00dfb03"><span class=en-original lang=en>Create an event that uses the <code>MessageEvent</code>
2122     interface, with the name <code title=event-connect>connect</code>, which does not bubble, is
2123     not cancelable, has no default action, has a <code title=dom-MessageEvent-data>data</code> attribute whose value
2124     is the empty string and has a <code title=dom-MessageEvent-ports>ports</code> attribute whose
2125     value is an array containing only the newly created port, and
2126     <span>queue a task</span> to dispatch the event at <var title="">worker global scope</var>.</span></li>
2127    
2128     <li>
2129    
2130     <p class="no-ja-translation" data-ja-hash="55e64a61fc96598db79195cddb4bb2f9"><span class=en-original lang=en><a href="#add-a-document-to-the-worker's-documents" title="add a document to the worker's documents">Add to
2131     <var title="">worker global scope</var>'s list of <span>the
2132     worker's <code>Document</code>s</span></a> the
2133     <code>Document</code> objects in <var title="">docs</var>.</span></p>
2134    
2135     </li>
2136    
2137     <li>
2138    
2139     <p class="no-ja-translation" data-ja-hash="71e9b593868deeebab7e077539f42964"><span class=en-original lang=en>If the <span title="script's global scope">global
2140     scope</span> of the <span title=concept-script>script</span>
2141     that invoked the constructor is a
2142     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object, add <var title="">worker global scope</var> to the list of <a href="#the-worker's-workers">the
2143     worker's workers</a> of the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>
2144     object that is the <span title="script's global scope">global
2145     scope</span> of the <span title=concept-script>script</span>
2146     that invoked the constructor.</span></p>
2147    
2148     </li>
2149    
2150     <li><p class="has-ja-translation" data-ja-hash="dd866391287c967d4799df78a7249911"><span class=en-original lang=en>Abort all these steps.</span><span class=ja-translation lang=ja>これらの段階をすべて停止します。</span></li>
2151    
2152 wakaba 1.156 </ol>
2153    
2154     </li>
2155 wakaba 1.111
2156     <li><p class="no-ja-translation" data-ja-hash="08b38f99ab8a1b8451edf6d12f8f60d9"><span class=en-original lang=en><span>Create a new <code><a href=#sharedworkerglobalscope>SharedWorkerGlobalScope</a></code>
2157     object</span>. Let <var title="">worker global scope</var> be
2158     this new object.</span></li>
2159    
2160     <li><p class="has-ja-translation" data-ja-hash="9c4f87efaa1e868cd6bf63dbffa749c0"><span class=en-original lang=en>Associate <var title="">worker</var> with <var title="">worker global scope</var>.</span><span class=ja-translation lang=ja><var title="">worker</var> を <var title="">worker
2161     global scope</var> に関連付けます。</span></li>
2162    
2163     <li><p class="no-ja-translation" data-ja-hash="5197138b23b238d1ca44cd6260532c5d"><span class=en-original lang=en>Set the <code title=dom-SharedWorkerGlobalScope-name><a href=#dom-sharedworkerglobalscope-name>name</a></code> attribute of
2164     <var title="">worker global scope</var> to <var title="">name</var>.</span></li>
2165    
2166     <li><p class="no-ja-translation" data-ja-hash="2d1b035dbaad3feca57eb124d161b034"><span class=en-original lang=en><span>Create a <code>MessagePort</code> object</span>
2167     owned by <var title="">worker global scope</var>. Let <var title="">inside port</var> be this new object.</span></li>
2168    
2169     <li><p class="no-ja-translation" data-ja-hash="bf2642ced659847cb4402165d2ab3a8e"><span class=en-original lang=en><span>Entangle</span> <var title="">outside port</var> and
2170     <var title="">inside port</var>.</span></li>
2171    
2172 wakaba 1.156 </ol>
2173    
2174     </li>
2175 wakaba 1.111
2176     <li><p class="no-ja-translation" data-ja-hash="8383fd384ab33b4860228f2c27483044"><span class=en-original lang=en>Return <var title="">worker</var> and perform the remaining
2177     steps asynchronously.</span></li>
2178    
2179     <li><p class="no-ja-translation" data-ja-hash="54fc802e5e886ae34c575b12f00dfb03"><span class=en-original lang=en>Create an event that uses the <code>MessageEvent</code>
2180     interface, with the name <code title=event-connect>connect</code>, which does not bubble, is not
2181     cancelable, has no default action, has a <code title=dom-MessageEvent-data>data</code> attribute whose value is
2182     the empty string and has a <code title=dom-MessageEvent-ports>ports</code> attribute whose value
2183     is an array containing only the newly created port, and <span>queue
2184     a task</span> to dispatch the event at <var title="">worker global
2185     scope</var>.</span></li>
2186    
2187     <li>
2188    
2189     <p class="no-ja-translation" data-ja-hash="55e64a61fc96598db79195cddb4bb2f9"><span class=en-original lang=en><a href="#add-a-document-to-the-worker's-documents" title="add a document to the worker's documents">Add to
2190     <var title="">worker global scope</var>'s list of <span>the
2191     worker's <code>Document</code>s</span></a> the
2192     <code>Document</code> objects in <var title="">docs</var>.</span></p>
2193    
2194     </li>
2195    
2196     <li>
2197    
2198     <p class="no-ja-translation" data-ja-hash="71e9b593868deeebab7e077539f42964"><span class=en-original lang=en>If the <span title="script's global scope">global scope</span>
2199     of the <span title=concept-script>script</span> that invoked the
2200     constructor is a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object, add <var title="">worker global scope</var> to the list of <a href="#the-worker's-workers">the
2201     worker's workers</a> of the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>
2202     object that is the <span title="script's global scope">global
2203     scope</span> of the <span title=concept-script>script</span>
2204     that invoked the constructor.</span></p>
2205    
2206     </li>
2207    
2208     <li>
2209    
2210     <p class="no-ja-translation" data-ja-hash="8d52f75615bdf14ecca1950ce2fe376b"><span class=en-original lang=en><a href=#run-a-worker>Run a worker</a> for the resulting <span>absolute
2211     URL</span>, with the <span>script browsing context</span> of the
2212     script that invoked the method as the <var title="">owner browsing
2213     context</var>, and with <var title="">worker global scope</var> as
2214     the global scope.</span></p>
2215    
2216     </li>
2217    
2218 wakaba 1.156 </ol>
2219    
2220     <p class="no-ja-translation" data-ja-hash="62d6758eaf2020c4112ab186636f4f33"><span class=en-original lang=en>This constructor must be visible when the <span>script's global
2221 wakaba 1.124 scope</span> is either a <code>Window</code> object or an object
2222     implementing the <code><a href=#workerutils>WorkerUtils</a></code> interface.</span></p>
2223 wakaba 1.133
2224     <p class="no-ja-translation" data-ja-hash="232ca3945fb57a3baa9cc0675ff99caa"><span class=en-original lang=en>The <span>task source</span> for the tasks mentioned above is the
2225     <span>DOM manipulation task source</span>.</span></p>
2226 wakaba 1.124
2227    
2228    
2229 wakaba 1.139 <h2 id=apis-available-to-workers class="has-ja-translation" data-ja-hash="4fce100e6a2eccbb2df8631a438feeb6"><span class=en-original lang=en><span class=secno>5 </span>APIs available to workers</span><span class=ja-translation lang=ja><span class=secno>5 </span>労働者が利用可能な API</span></h2>
2230 wakaba 1.111
2231 wakaba 1.154 <pre class="idl no-ja-translation" data-ja-hash="eb360baf4cea0845dd1f29248fa6057f"><span class=en-original lang=en>[Supplemental, NoInterfaceObject]
2232     interface <dfn id=workerutils>WorkerUtils</dfn> {
2233     void <a href=#dom-workerglobalscope-importscripts title=dom-WorkerGlobalScope-importScripts>importScripts</a>(in DOMString... urls);
2234 wakaba 1.111 readonly attribute <a href=#worker-navigator title=worker-Navigator>Navigator</a> <a href=#dom-worker-navigator title=dom-worker-navigator>navigator</a>;
2235 wakaba 1.154 };
2236     // implemented by <a href=#workerglobalscope>WorkerGlobalScope</a></span></pre>
2237 wakaba 1.111
2238     <p class="has-ja-translation" data-ja-hash="fc1e0d30e2c0869e54fb2487a7dd6836" data-ja-real-hash="a9f04ef5503be39e966b5cc5744a3d1c"><span class=en-original lang=en>Objects that implement the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>
2239     interface must also implement the <code><a href=#workerutils>WorkerUtils</a></code>
2240     interface.</span><span class=ja-translation lang=ja><code><a href=#workerglobalscope>WorkerGlobalScope</a></code> 界面を実装するオブジェクトは、 <code><a href=#workerutils>WorkerUtils</a></code> 界面も実装しなければ<em class=rfc2119 title="MUST">なりません</em>。</span></p>
2241    
2242     <p class="no-ja-translation" data-ja-hash="66c8457f878286e5a4ecb06e2d847359"><span class=en-original lang=en>Objects that implement the <code><a href=#workerutils>WorkerUtils</a></code> interface
2243     must also implement the <code>WindowTimers</code> interface. (This
2244     interface provides the <code title="">setTimeout()</code> method and
2245     its friends.)</span></p><!-- XXX ref -->
2246    
2247     <!-- XXX ApplicationCache -->
2248    
2249     <!-- XXX debugging: void log(in DOMString s); // log to console -->
2250    
2251 wakaba 1.156 <hr>
2252    
2253     <p class="has-ja-translation" data-ja-hash="59b28734296c1cd390d156b0e8e5fb94"><span class=en-original lang=en>The DOM APIs (<code>Node</code> objects, <code>Document</code>
2254 wakaba 1.111 objects, etc) are not available to workers in this version of this
2255     specification.</span><span class=ja-translation lang=ja>DOM API (<code>Node</code> オブジェクト、 <code>Document</code>
2256     オブジェクト、その他) は、この版のこの仕様書では労働者に利用可能ではありません。</span></p>
2257    
2258    
2259 wakaba 1.139 <h3 id=importing-scripts-and-libraries class="has-ja-translation" data-ja-hash="e7522d998689dc52be80feeff81470ca"><span class=en-original lang=en><span class=secno>5.1 </span>Importing scripts and libraries</span><span class=ja-translation lang=ja><span class=secno>5.1 </span>スクリプトとライブラリーの輸入</span></h3>
2260 wakaba 1.111
2261     <p class="no-ja-translation" data-ja-hash="66975403bb279c95f3527e7070d78341"><span class=en-original lang=en>When a script invokes the <dfn id=dom-workerglobalscope-importscripts title=dom-WorkerGlobalScope-importScripts><code>importScripts(<var title="">urls</var>)</code></dfn> method on a
2262     <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object, the user agent must run the
2263     following steps:</span></p>
2264    
2265 wakaba 1.156 <ol>
2266    
2267     <li><p class="has-ja-translation" data-ja-hash="143a8bb07f4501807d2bbf2d2d2b345a"><span class=en-original lang=en>If there are no arguments, return without doing
2268 wakaba 1.111 anything. Abort these steps.</span><span class=ja-translation lang=ja>引数がない場合、何も返さずに返ります。
2269     これらの段階を停止します。</span></li>
2270    
2271     <li><p class="has-ja-translation" data-ja-hash="b89818b453add85fbb5ec1e963e3072c"><span class=en-original lang=en><span title="resolve a url">Resolve</span> each
2272     argument.</span><span class=ja-translation lang=ja>各引数を<span title="resolve a url">解決</span>します。</span></li>
2273    
2274     <li><p class="has-ja-translation" data-ja-hash="54adea3a3a07dd8833ad87eb937142f1"><span class=en-original lang=en>If any fail, throw a <code>SYNTAX_ERR</code>
2275     exception.</span><span class=ja-translation lang=ja>いずれかが失敗した場合、 <code>SYNTAX_ERR</code> 例外を投げます。</span></li>
2276    
2277     <!--
2278     <li><p class="has-ja-translation" data-ja-hash="952d7bd44378695378ddf1084a1c5347"><span class=en-original lang=en>If any of the resulting <span title="absolute URL">absolute
2279     URLs</span> have an <span>origin</span> that is not the <span
2280     title="same origin">same</span> as the origin of the script that
2281     invoked the method, then throw a <span>security
2282     exception</span>.</span><span class=ja-translation lang=ja>結果として得られた<span title="absolute URL">絶対
2283     URL</span>
2284     のいずれかが、メソッドを呼び出したスクリプトの<span>origin</span>と<span
2285     title="same origin">同じ</span>ではない起源を持つ場合、
2286     <span>保安性例外</span>を投げます。</span></p></li>
2287     -->
2288    
2289     <li>
2290    
2291     <p class="has-ja-translation" data-ja-hash="9a0a1930525c4231da8248d6b7847c8d"><span class=en-original lang=en>Attempt to <span>fetch</span> each resource identified by the
2292     resulting <span title="absolute URLs">absolute URL</span>.</span><span class=ja-translation lang=ja>結果として得られた<span title="absolute URLs">絶対 URL</span>
2293     によって識別される資源をそれぞれ<span>取得</span>しようと試みます。</span></p>
2294    
2295     </li>
2296    
2297     <li>
2298    
2299     <p class="has-ja-translation" data-ja-hash="4fc5f1898eb20e4c8da603b91c1ae884"><span class=en-original lang=en>For each argument in turn, in the order given, starting with
2300     the first one, run these substeps:</span><span class=ja-translation lang=ja>各引数について、与えられた順に最初のものから、次の部分段階群を走らせます。</span></p>
2301    
2302 wakaba 1.156 <ol>
2303    
2304     <li>
2305 wakaba 1.111
2306     <p class="has-ja-translation" data-ja-hash="a5cd8fb5d75985afdc62f7ac228329d4"><span class=en-original lang=en>Wait for the fetching attempt for the corresponding resource
2307     to complete.</span><span class=ja-translation lang=ja>対応する資源を取得しようとする試みが完了するのを待ちます。</span></p>
2308    
2309     <p class="no-ja-translation" data-ja-hash="c821b5a32a4316df06e95e2117d4d21a"><span class=en-original lang=en>If the fetching attempt failed, throw a
2310     <code>NETWORK_ERR</code> exception and abort all these
2311     steps.</span></p>
2312    
2313     <p class="no-ja-translation" data-ja-hash="a2c139226de4390d75b561512be824a7"><span class=en-original lang=en>If the attempt succeeds, then <a href=#decode-a-script-resource title="decode a script
2314     resource">decode the script resource</a> to obtain its <var title="">source</var>.</span></p>
2315    
2316     <p class="no-ja-translation" data-ja-hash="c880bce97c5a1aadccd8989fc4ec8551"><span class=en-original lang=en>Let <var title="">language</var> be JavaScript.</span></p>
2317    
2318     <p class="note has-ja-translation" data-ja-hash="9d495d7b0fa2439cfa3470c4af977171"><span class=en-original lang=en>As with the worker's script, the script here is
2319     always assumed to be JavaScript, regardless of the MIME
2320     type.</span><span class=ja-translation lang=ja>労働者のスクリプトと同じく、ここでのスクリプトも、 MIME 型に関わらず常に
2321     JavaScript であるとみなします。</span></p> <!-- XXX -->
2322    
2323     </li>
2324    
2325     <li>
2326    
2327     <p class="no-ja-translation" data-ja-hash="82bb5f7207d0f40963418cf33df6325b"><span class=en-original lang=en><span>Create a script</span>, using <var title="">source</var> as the script source and <var title="">language</var> as the scripting language, using the
2328     same global object, browsing context, character encoding, base
2329     URL, and script group as the <span title=concept-script>script</span> that was created by the
2330     worker's <a href=#run-a-worker>run a worker</a> algorithm.</span></p>
2331    
2332     <p class="no-ja-translation" data-ja-hash="160451bccc2829032bdfb4597231e9c2"><span class=en-original lang=en>Let the newly created <span title=concept-script>script</span> run until it either
2333     returns, fails to parse, fails to catch an exception, or gets
2334     prematurely aborted by the "<a href=#kill-a-worker>kill a worker</a>" or
2335     "<a href=#terminate-a-worker>terminate a worker</a>" algorithms defined above.</span></p>
2336    
2337     <p class="no-ja-translation" data-ja-hash="41014f4a697396a3e02475a4d61a7472"><span class=en-original lang=en>If it failed to parse, then throw a
2338     <code>SyntaxError</code><!-- XXX ref? --> exception and abort
2339     all these steps.</span></p>
2340    
2341     <p class="no-ja-translation" data-ja-hash="32f753089621a99745d3a6dde7c5aa8b"><span class=en-original lang=en>If an exception was raised or if the script was prematurely
2342     aborted, then abort all these steps, letting the exception or
2343     aborting continue to be processed by the script that called the
2344     <code title=dom-WorkerGlobalScope-importScripts><a href=#dom-workerglobalscope-importscripts>importScripts()</a></code>
2345     method.</span></p>
2346    
2347     <p class="no-ja-translation" data-ja-hash="f41de43eedf5733455078779b5f50c14"><span class=en-original lang=en>If the "<a href=#kill-a-worker>kill a worker</a>" or "<a href=#terminate-a-worker>terminate a
2348     worker</a>" algorithms abort the script then abort all these
2349     steps.</span></p>
2350    
2351     </li>
2352    
2353 wakaba 1.156 </ol>
2354 wakaba 1.111
2355 wakaba 1.156 </li>
2356    
2357     </ol>
2358    
2359    
2360     <h3 id=the-navigator-object class="no-ja-translation" data-ja-hash="6a11027ebc14ad36700f251d60a84912"><span class=en-original lang=en><span class=secno>5.2 </span>The <code title=worker-Navigator><a href=#worker-navigator>Navigator</a></code> object</span></h3>
2361 wakaba 1.111
2362     <p class="no-ja-translation" data-ja-hash="b0a33e2b5cacd5c4c5725f370211c7f4"><span class=en-original lang=en>The <dfn id=dom-worker-navigator title=dom-worker-navigator><code>navigator</code></dfn> attribute
2363     of the <code><a href=#workerutils>WorkerUtils</a></code> interface must return an instance of
2364     the <code title=worker-Navigator><a href=#worker-navigator>Navigator</a></code> interface, which
2365     represents the identity and state of the user agent (the
2366     client):</span></p>
2367    
2368 wakaba 1.154 <pre class="idl no-ja-translation" data-ja-hash="6d834a5d9279a0ac570d99b54c771186"><span class=en-original lang=en>interface <dfn id=worker-navigator title=worker-Navigator>Navigator</dfn> {};
2369     <a href=#worker-navigator title=worker-Navigator>Navigator</a> implements <span>NavigatorID</span>;
2370     <a href=#worker-navigator title=worker-Navigator>Navigator</a> implements <span>NavigatorOnLine</span>;</span></pre>
2371    
2372     <p class="no-ja-translation" data-ja-hash="f83ff867184de4dcece4621dc2c07096"><span class=en-original lang=en>Objects implementing the <code title=worker-Navigator><a href=#worker-navigator>Navigator</a></code> interface also implement
2373     the <code>NavigatorID</code> and <code>NavigatorOnLine</code>
2374     interfaces. <a href=#refsHTML5>[HTML5]</a></span></p>
2375 wakaba 1.111
2376 wakaba 1.113 <p class="note no-ja-translation" data-ja-hash="67986732437eb5b67c3e1bd21f1325a8"><span class=en-original lang=en>The <code title=worker-Navigator><a href=#worker-navigator>Navigator</a></code>
2377 wakaba 1.111 interface defined in this specification is different than the one
2378 wakaba 1.113 defined in the HTML specification.</span></p>
2379 wakaba 1.111
2380    
2381    
2382 wakaba 1.139 <h3 id=apis-defined-in-other-specifications class="has-ja-translation" data-ja-hash="d6d6885373ce92bfa8857f5a375a9c8f"><span class=en-original lang=en><span class=secno>5.3 </span>APIs defined in other specifications</span><span class=ja-translation lang=ja><span class=secno>5.3 </span>他の仕様書で定義されている API</span></h3>
2383 wakaba 1.111
2384 wakaba 1.137 <p class="no-ja-translation" data-ja-hash="1280f8909e789b1739534938ee2d8974"><span class=en-original lang=en>The <code title=dom-opendatabase>openDatabase()</code> and
2385 wakaba 1.111 <code title=dom-opendatabase-sync>openDatabaseSync()</code>
2386 wakaba 1.137 methods are defined in the Web Database specification. <a href=#refsWEBDATABASE>[WEBDATABASE]</a></span></p>
2387 wakaba 1.111
2388    
2389    
2390 wakaba 1.139 <h3 id=interface-objects-and-constructors class="has-ja-translation" data-ja-hash="78e75b89c304218ef77a66cd9efdf398"><span class=en-original lang=en><span class=secno>5.4 </span>Interface objects and constructors</span><span class=ja-translation lang=ja><span class=secno>5.4 </span>界面オブジェクトと構築器</span></h3>
2391 wakaba 1.111
2392     <p class="no-ja-translation" data-ja-hash="891d0a43200fedd7ae183f012070bb93"><span class=en-original lang=en>There must be no interface objects and constructors available in
2393     the global scope of scripts whose <span>script execution
2394     context</span> is a <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object except for
2395     the following:</span></p>
2396    
2397 wakaba 1.156 <ul>
2398    
2399     <li><p class="has-ja-translation" data-ja-hash="fefceafe7239d8df54847618da8d3ddd"><span class=en-original lang=en><code>XMLHttpRequest</code> and all interface objects and
2400 wakaba 1.111 constructors defined by the XMLHttpRequest specifications, except
2401     that the <span>document response entity body</span> must always be
2402     null. <a href=#refsXHR>[XHR]</a></span><span class=ja-translation lang=ja>XMLHttpRequest 仕様書で定義されている
2403     <code>XMLHttpRequest</code> とすべての界面オブジェクトと構築器、
2404     ただし<span>文書応答実体本体</span>は常に null でなければ<em class=rfc2119 title="MUST">なりません</em>。 <a
2405     href=#refsXHR>[XHR]</a></span></li>
2406    
2407     <li><p class="no-ja-translation" data-ja-hash="dd3bea5f0bf238db87ad9fb59c7be62a"><span class=en-original lang=en>The <code>WebSocket</code> interface object and
2408     constructor. <a href=#refsWEBSOCKET>[WEBSOCKET]</a></span></li>
2409    
2410     <li><p class="no-ja-translation" data-ja-hash="bbeb4f3911ac8aedf89935a07d70106c"><span class=en-original lang=en>The <code>EventSource</code> interface object and
2411     constructor. <a href=#refsEVENTSOURCE>[EVENTSOURCE]</a></span></li>
2412    
2413     <li><p class="no-ja-translation" data-ja-hash="939ce12ed8f8d8ce1888e6c380db792c"><span class=en-original lang=en>The <code>MessageChannel</code> interface object and
2414     constructor. <a href=#refsHTML5>[HTML5]</a></span></li>
2415    
2416     <li><p class="no-ja-translation" data-ja-hash="0ca0874e3173f58421ed4537975fdd7f"><span class=en-original lang=en>The <code title=dom-Worker><a href=#dom-worker>Worker()</a></code> and <code title=dom-SharedWorker><a href=#dom-sharedworker>SharedWorker(<var title="">url</var>)</a></code> constructors.</span></li>
2417    
2418 wakaba 1.156 </ul>
2419    
2420    
2421     <h3 id=worker-locations class="has-ja-translation" data-ja-hash="ae4aa0f882fcbd2ee8252e59113ec205"><span class=en-original lang=en><span class=secno>5.5 </span>Worker locations</span><span class=ja-translation lang=ja><span class=secno>5.5 </span>労働者の所在</span></h3>
2422 wakaba 1.111
2423     <pre class="idl no-ja-translation" data-ja-hash="8d12e26ffacf32cd9d10364c0255ab53"><span class=en-original lang=en>interface <dfn id=workerlocation>WorkerLocation</dfn> {
2424     readonly attribute DOMString <a href=#dom-workerlocation-href title=dom-WorkerLocation-href>href</a>;
2425     readonly attribute DOMString <a href=#dom-workerlocation-protocol title=dom-WorkerLocation-protocol>protocol</a>;
2426     readonly attribute DOMString <a href=#dom-workerlocation-host title=dom-WorkerLocation-host>host</a>;
2427     readonly attribute DOMString <a href=#dom-workerlocation-hostname title=dom-WorkerLocation-hostname>hostname</a>;
2428     readonly attribute DOMString <a href=#dom-workerlocation-port title=dom-WorkerLocation-port>port</a>;
2429     readonly attribute DOMString <a href=#dom-workerlocation-pathname title=dom-WorkerLocation-pathname>pathname</a>;
2430     readonly attribute DOMString <a href=#dom-workerlocation-search title=dom-WorkerLocation-search>search</a>;
2431     readonly attribute DOMString <a href=#dom-workerlocation-hash title=dom-WorkerLocation-hash>hash</a>;
2432     };</span></pre>
2433    
2434     <p class="no-ja-translation" data-ja-hash="0875217b900933e0434228878aa70bb1"><span class=en-original lang=en>A <code><a href=#workerlocation>WorkerLocation</a></code> object represents an <span>absolute
2435     URL</span> set at its creation.</span></p>
2436    
2437     <p class="no-ja-translation" data-ja-hash="12d68ceea5131e0a3f4acc5b2060ee25"><span class=en-original lang=en>The <dfn id=dom-workerlocation-href title=dom-WorkerLocation-href><code>href</code></dfn>
2438     attribute must return the <span>absolute URL</span> that the object
2439     represents.</span></p>
2440    
2441     <p class="no-ja-translation" data-ja-hash="f1f2216168ef764adc270dd0ce7cab68"><span class=en-original lang=en>The <code><a href=#workerlocation>WorkerLocation</a></code> interface also has the complement
2442     of <span>URL decomposition attributes</span>, <dfn id=dom-workerlocation-protocol title=dom-WorkerLocation-protocol><code>protocol</code></dfn>,
2443     <dfn id=dom-workerlocation-host title=dom-WorkerLocation-host><code>host</code></dfn>, <dfn id=dom-workerlocation-port title=dom-WorkerLocation-port><code>port</code></dfn>, <dfn id=dom-workerlocation-hostname title=dom-WorkerLocation-hostname><code>hostname</code></dfn>,
2444     <dfn id=dom-workerlocation-pathname title=dom-WorkerLocation-pathname><code>pathname</code></dfn>,
2445     <dfn id=dom-workerlocation-search title=dom-WorkerLocation-search><code>search</code></dfn>,
2446     and <dfn id=dom-workerlocation-hash title=dom-WorkerLocation-hash><code>hash</code></dfn>. These must
2447     follow the rules given for URL decomposition attributes, with the
2448     <span title=concept-uda-input>input</span> being the
2449     <span>absolute URL</span> that the object represents (same as the
2450     <code title=dom-WorkerLocation-href><a href=#dom-workerlocation-href>href</a></code> attribute), and
2451     the <span title=concept-uda-setter>common setter action</span>
2452     being a no-op, since the attributes are defined to be readonly. <a href=#refsHTML5>[HTML5]</a></span></p>
2453    
2454    
2455     <h2 class="no-num has-ja-translation" data-ja-hash="d95867deadfe690e40f42068d6b59df8" id=references><span class=en-original lang=en>References</span><span class=ja-translation lang=ja>参照</span></h2>
2456    
2457     <p class="big-issue no-ja-translation" data-ja-hash="683a8b064076b13e2c36958afe8b9897"><span class=en-original lang=en>This section will be written in a future
2458     draft.<!--XXX--></span></p>
2459    
2460    
2461     <h2 class="no-num has-ja-translation" data-ja-hash="0407c27180c9b019e644e8ad4c6a9324" id=acknowledgements><span class=en-original lang=en>Acknowledgements</span><span class=ja-translation lang=ja>謝辞</span></h2> <!-- ACKS -->
2462    
2463 wakaba 1.156 <p class="has-ja-translation" data-ja-hash="a17a0feb6f58a31040d51121e80bc233" data-ja-real-hash="1796f8370fb41e95c9601e01bd2760d2"><span class=en-original lang=en>Thanks to
2464 wakaba 1.111
2465     Aaron Boodman,
2466 wakaba 1.156 Алексей Проскуряков (Alexey Proskuryakov),
2467 wakaba 1.111 Anne van Kesteren,
2468     Ben Turner,
2469     Dmitry Titov,
2470     Drew Wilson,
2471     Jeremy Orlow,
2472     Jonas Sicking,
2473     Justin James,
2474     Kevin Hakanson,
2475     Maciej Stachowiak,
2476     Michael Nordman,
2477     Mike Smith,
2478    
2479     and
2480    
2481     Philip Taylor
2482    
2483 wakaba 1.156 for their useful and substantial comments.</span><span class=ja-translation lang=ja>Aaron Boodman, Алексей Проскуряков (Alexey Proskuryakov), Anne van Kesteren, Ben Turner, Dmitry Titov, Drew Wilson, Jeremy Orlow, Jonas Sicking, Justin James, Kevin Hakanson, Maciej Stachowiak, Michael Nordman, Mike Smith, Philip Taylor の有用かつ重要なコメントに感謝します。</span></p>
2484 wakaba 1.111
2485     <p class="has-ja-translation" data-ja-hash="7c6875278ecf56df193c33c553856fac"><span class=en-original lang=en>Huge thanks to the whole Gears team, who pioneered this
2486     technology and whose experience has been a huge influence on this
2487     specification.</span><span class=ja-translation lang=ja>Gears チームの方々にも非常に感謝します。
2488     Gears チームの方々はこの技術を開拓し、その経験はこの仕様書にも多大な影響を与えています。
2489     </span></p>
2490    
2491    
2492 wakaba 1.156

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24