回答編集履歴
7
まとめを修正した。
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
まとめると、
|
41
|
+
仕様にあること、無いことをまとめると、以下の通りです。
|
42
42
|
|
43
43
|
|
44
44
|
|
6
まとめを追記した。
test
CHANGED
@@ -38,9 +38,33 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
+
まとめると、
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
**ECMAScript 6**
|
46
|
+
|
47
|
+
・[[Job]]を要素とするキューを持っており、キュー内の[[Job]]を順次実行していく。
|
48
|
+
|
49
|
+
・キューの割り込み処理は発生しうるが、[[Job]] の実行中は割り込みされない。
|
50
|
+
|
51
|
+
**ECMAScript 5.1**
|
52
|
+
|
53
|
+
・実行コンテキストのスタックがあり、スタックのトップにある実行コンテキストを使って処理が実行される。
|
54
|
+
|
55
|
+
・キューや割り込みについては記述が無い。
|
56
|
+
|
57
|
+
・スタックを新しく作るような記述が無いことから、シングルスレッドと推定できる。
|
58
|
+
|
59
|
+
**WHATWG仕様**
|
60
|
+
|
61
|
+
・イベント実行中は一つの [[Job]] と考えられ、イベント実行中は割り込み処理されない(setTimeout も同様)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
41
|
-
そもそも、HTML5にはWeb Workerがあるので、
|
67
|
+
そもそも、HTML5にはWeb Workerがあるので、シングルスレッドというのは正確ではないと思います。
|
42
|
-
|
43
|
-
シングルスレッドというのは正確ではないと思います。
|
44
68
|
|
45
69
|
ただ、Web Workerからはwindowオブジェクトは参照できない様なので
|
46
70
|
|
@@ -48,6 +72,8 @@
|
|
48
72
|
|
49
73
|
|
50
74
|
|
75
|
+
### ECMAScript 6仕様から分かること
|
76
|
+
|
51
77
|
ECMAScript 6の仕様には、シングルスレッドでの動作しか書かれていません。
|
52
78
|
|
53
79
|
以下の箇所が該当すると思います。
|
@@ -68,15 +94,15 @@
|
|
68
94
|
|
69
95
|
> 8. In an implementation dependent manner, obtain the ECMAScript source texts (see clause 10) for zero or more ECMAScript scripts and/or ECMAScript modules.
|
70
96
|
|
71
|
-
>
|
97
|
+
> For each such sourceText do,
|
72
|
-
|
98
|
+
|
73
|
-
>
|
99
|
+
> a. If sourceText is the source code of a script, then
|
74
|
-
|
100
|
+
|
75
|
-
>
|
101
|
+
> i. Perform EnqueueJob("ScriptJobs", ScriptEvaluationJob, « sourceText »).
|
76
|
-
|
102
|
+
|
77
|
-
>
|
103
|
+
> b. Else sourceText is the source code of a module,
|
78
|
-
|
104
|
+
|
79
|
-
>
|
105
|
+
> i. Perform EnqueueJob("ScriptJobs", TopLevelModuleEvaluationJob, « sourceText »).
|
80
106
|
|
81
107
|
のように、JobをEnqueueすることで処理を開始しており、その後の処理も
|
82
108
|
|
@@ -84,9 +110,9 @@
|
|
84
110
|
|
85
111
|
|
86
112
|
|
87
|
-
|
113
|
+
###WHATWGの仕様から分かること
|
88
|
-
|
114
|
+
|
89
|
-
以下のようにイベントループの説明があります。
|
115
|
+
WHATWGの仕様を見ても、以下のようにイベントループの説明があります。
|
90
116
|
|
91
117
|
[8.1.4 Event loops](https://html.spec.whatwg.org/multipage/webappapis.html#event-loops)
|
92
118
|
|
@@ -102,7 +128,7 @@
|
|
102
128
|
|
103
129
|
イベントループの[処理モデル](https://html.spec.whatwg.org/multipage/webappapis.html#processing-model-8)を見ても、
|
104
130
|
|
105
|
-
>
|
131
|
+
> An event loop must continually run through the following steps for as long as it exists:
|
106
132
|
|
107
133
|
の後に順番に処理するステップが書かれているだけで、マルチスレッドで処理するとは書かれていません。
|
108
134
|
|
@@ -205,3 +231,5 @@
|
|
205
231
|
あたりが元のようで、ES6より前には仕様化されていなかったように見えます。
|
206
232
|
|
207
233
|
|
234
|
+
|
235
|
+
|
5
ECMAScript 6より前に、Jobのキューが仕様に無いことを追記した。
test
CHANGED
@@ -66,9 +66,9 @@
|
|
66
66
|
|
67
67
|
[8.5 ECMAScript Initialization()](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-initialization)
|
68
68
|
|
69
|
-
> 8. In an implementation dependent manner, obtain the ECMAScript source texts (see clause 10)
|
69
|
+
> 8. In an implementation dependent manner, obtain the ECMAScript source texts (see clause 10) for zero or more ECMAScript scripts and/or ECMAScript modules.
|
70
|
-
|
70
|
+
|
71
|
-
>
|
71
|
+
> For each such sourceText do,
|
72
72
|
|
73
73
|
> a. If sourceText is the source code of a script, then
|
74
74
|
|
@@ -146,6 +146,10 @@
|
|
146
146
|
|
147
147
|
はっきりとした記述が無い様に思います。
|
148
148
|
|
149
|
+
Jobのキューについても記述がありません。
|
150
|
+
|
151
|
+
|
152
|
+
|
149
153
|
仕様に書かれているのは、
|
150
154
|
|
151
155
|
「実行コンテキストのスタックがあり、スタックのトップにある
|
4
日本語訳部分を見易く整形した。
test
CHANGED
@@ -172,19 +172,11 @@
|
|
172
172
|
|
173
173
|
> When control is transferred to ECMAScript executable code, control is entering an execution context. Active execution contexts logically form a stack. The top execution context on this logical stack is the running execution context. A new execution context is created whenever control is transferred from the executable code associated with the currently running execution context to executable code that is not associated with that execution context. The newly created execution context is pushed onto the stack and becomes the running execution context.
|
174
174
|
|
175
|
-
|
176
|
-
|
177
|
-
アクティブな実行コンテキストは論理的にスタックを構成する。
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
実行中の実行コンテキストに関連付いた実行コードから
|
182
|
-
|
183
|
-
関連付いていない実行コンテキストに制御が移るときはいつも、
|
184
|
-
|
185
|
-
新しい実行コンテキストが生成される。
|
186
|
-
|
187
|
-
新しい実行コンテキストは、スタックのトップにプッシュされ、実行中の実行コンテキストになる。
|
175
|
+
```
|
176
|
+
|
177
|
+
ECMAScriptの実行可能コードに制御が移ると、実行コンテキストに入る。アクティブな実行コンテキストは論理的にスタックを構成する。スタックのトップの実行コンテキストは、実行中の実行コンテキストである。実行中の実行コンテキストに関連付いた実行コードから関連付いていない実行コンテキストに制御が移るときはいつも、新しい実行コンテキストが生成される。新しい実行コンテキストは、スタックのトップにプッシュされ、実行中の実行コンテキストになる。
|
178
|
+
|
179
|
+
```
|
188
180
|
|
189
181
|
(executeもrunも「実行」と訳したので、「実行中の実行コンテキスト」となり、
|
190
182
|
|
3
改行位置などを修正した。
test
CHANGED
@@ -54,12 +54,8 @@
|
|
54
54
|
|
55
55
|
[8.4 Jobs and Job Queues](http://www.ecma-international.org/ecma-262/6.0/#sec-jobs-and-job-queues)
|
56
56
|
|
57
|
-
|
58
|
-
|
59
57
|
> Once execution of a Job is initiated, the Job always executes to completion. No other Job may be initiated until the currently running Job completes. However, the currently running Job or external events may cause the enqueuing of additional PendingJobs that may be initiated sometime after completion of the currently running Job.
|
60
58
|
|
61
|
-
|
62
|
-
|
63
59
|
Jobの実行中には、他のJobは実行されないこと、Jobの十個中にPendingJobsという別の
|
64
60
|
|
65
61
|
Jobをキューに追加することはあることが書かれています。
|
@@ -92,21 +88,13 @@
|
|
92
88
|
|
93
89
|
以下のようにイベントループの説明があります。
|
94
90
|
|
95
|
-
[8.1.4 Event loops](
|
91
|
+
[8.1.4 Event loops](https://html.spec.whatwg.org/multipage/webappapis.html#event-loops)
|
96
|
-
|
92
|
+
|
97
|
-
taskのキューがあって、それをイベントループが処理していくというような
|
93
|
+
taskのキューがあって、それをイベントループが処理していくというような記述です。
|
98
|
-
|
99
|
-
記述です。
|
100
|
-
|
101
|
-
|
102
94
|
|
103
95
|
> There must be at least one browsing context event loop per user agent, and at most one per unit of related similar-origin browsing contexts.
|
104
96
|
|
105
|
-
|
106
|
-
|
107
|
-
ブラウジングコンテキストに対して、多くても1つしかイベントループがないと
|
97
|
+
ブラウジングコンテキストに対して、多くても1つしかイベントループがないと読めます。
|
108
|
-
|
109
|
-
読めます。
|
110
98
|
|
111
99
|
|
112
100
|
|
@@ -124,11 +112,9 @@
|
|
124
112
|
|
125
113
|
> Each event loop has a currently running task.
|
126
114
|
|
127
|
-
|
128
|
-
|
129
|
-
とあり、「event loop has a currently running task 」なので、同時に実行するtaskは
|
115
|
+
とあり、「event loop has a currently running task 」なので、同時に実行するtaskは
|
130
|
-
|
116
|
+
|
131
|
-
考えられます。
|
117
|
+
イベントループ1つにつき1つと考えられます。
|
132
118
|
|
133
119
|
|
134
120
|
|
@@ -150,9 +136,7 @@
|
|
150
136
|
|
151
137
|
> 14. Queue the task task.
|
152
138
|
|
153
|
-
とあり、これがイベントループのキューを使っていることを
|
139
|
+
とあり、これがイベントループのキューを使っていることを意味していると思います。
|
154
|
-
|
155
|
-
意味していると思います。
|
156
140
|
|
157
141
|
|
158
142
|
|
2
ECMAScript 6より前について追記した。
test
CHANGED
@@ -132,7 +132,7 @@
|
|
132
132
|
|
133
133
|
|
134
134
|
|
135
|
-
気にされているsetTimeoutについても、
|
135
|
+
気にされている**setTimeoutについて**も、
|
136
136
|
|
137
137
|
taskの例として挙がっている
|
138
138
|
|
@@ -153,3 +153,75 @@
|
|
153
153
|
とあり、これがイベントループのキューを使っていることを
|
154
154
|
|
155
155
|
意味していると思います。
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
### ECMAScript 6より前について
|
160
|
+
|
161
|
+
ECMAScript 5.1の仕様には、**シングルスレッドで処理する**ことについて、
|
162
|
+
|
163
|
+
はっきりとした記述が無い様に思います。
|
164
|
+
|
165
|
+
仕様に書かれているのは、
|
166
|
+
|
167
|
+
「実行コンテキストのスタックがあり、スタックのトップにある
|
168
|
+
|
169
|
+
実行コンテキストを使って処理が実行される。」
|
170
|
+
|
171
|
+
「新しく作られた実行コンテキストは、スタックにプッシュされる。」
|
172
|
+
|
173
|
+
ことです。
|
174
|
+
|
175
|
+
別のスレッドを作るのであれば、スタックを新しく作る必要があると思いますが、
|
176
|
+
|
177
|
+
スタックを新しく作る、と言う記述は仕様中に見当たらないため、
|
178
|
+
|
179
|
+
スレッドは作られない、つまりシングルスレッドと解釈できるかな、というところです。
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
以下、参照した仕様と、私なりの日本語訳です。
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
[10.3 Execution Contexts](http://www.ecma-international.org/ecma-262/5.1/#sec-10.3)
|
188
|
+
|
189
|
+
> When control is transferred to ECMAScript executable code, control is entering an execution context. Active execution contexts logically form a stack. The top execution context on this logical stack is the running execution context. A new execution context is created whenever control is transferred from the executable code associated with the currently running execution context to executable code that is not associated with that execution context. The newly created execution context is pushed onto the stack and becomes the running execution context.
|
190
|
+
|
191
|
+
ECMAScriptの実行可能コードに制御が移ると、実行コンテキストに入る。
|
192
|
+
|
193
|
+
アクティブな実行コンテキストは論理的にスタックを構成する。
|
194
|
+
|
195
|
+
スタックのトップの実行コンテキストは、実行中の実行コンテキストである。
|
196
|
+
|
197
|
+
実行中の実行コンテキストに関連付いた実行コードから
|
198
|
+
|
199
|
+
関連付いていない実行コンテキストに制御が移るときはいつも、
|
200
|
+
|
201
|
+
新しい実行コンテキストが生成される。
|
202
|
+
|
203
|
+
新しい実行コンテキストは、スタックのトップにプッシュされ、実行中の実行コンテキストになる。
|
204
|
+
|
205
|
+
(executeもrunも「実行」と訳したので、「実行中の実行コンテキスト」となり、
|
206
|
+
|
207
|
+
日本語として少しおかしくなってしまいました)
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
ECMAScript 3以前については、調べていませんが、
|
212
|
+
|
213
|
+
同様の記述があるのではないかと思います。
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
**setTimeoutなどの非同期呼び出し**については、
|
218
|
+
|
219
|
+
[strawman:oldes6 (ES Wiki)](http://wiki.ecmascript.org/doku.php?id=strawman:oldes6)
|
220
|
+
|
221
|
+
の
|
222
|
+
|
223
|
+
> Concurrency, Asynchrony, and Distributed Programming
|
224
|
+
|
225
|
+
あたりが元のようで、ES6より前には仕様化されていなかったように見えます。
|
226
|
+
|
227
|
+
|
1
ECMAScript 6を見たことを明記した。
test
CHANGED
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
-
ECMAScriptの仕様には、シングルスレッドでの動作しか書かれていません。
|
51
|
+
ECMAScript 6の仕様には、シングルスレッドでの動作しか書かれていません。
|
52
52
|
|
53
53
|
以下の箇所が該当すると思います。
|
54
54
|
|