/
307.txt
131 lines (102 loc) · 8.04 KB
/
307.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
[23] [[ワーカー]]の[[大域オブジェクト]]の [DFN[[CODE(DOMm)@en[[[importScripts]]]]]]
[[メソッド]]は、指定した [[URL]] の[[スクリプト]]を実行するよう指示するものです。
* 仕様書
[REFS[
- [2] '''[CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2015-05-06 10:42:35 +09:00]] 版) <https://html.spec.whatwg.org/#dom-workerglobalscope-importscripts>'''
- [10] [CITE@en[Service Workers Nightly]] ([TIME[2017-02-16 20:10:49 +09:00]]) <https://w3c.github.io/ServiceWorker/#dfn-imported-scripts-updated-flag>
- [28] [CITE@en[Service Workers]] ([TIME[2015-09-03 15:00:35 +09:00]] 版) <https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-global-scope-importscripts-allowed-flag>
- [22] [CITE@en[Service Workers]] ([TIME[2015-09-03 15:00:35 +09:00]] 版) <https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#importscripts>
]REFS]
* 処理
[3] [CODE(DOMi)@en[[[WorkerGlobalScope]]]] [[インターフェイス]]の
[DFN[[CODE(DOMm)@en[[[importScripts]]]]]] [[メソッド]]は、
次のようにしなければ[MUST[なりません]] [SRC[>>2]]。
[FIG(steps)[
= [4] [VAR[URL群]]を、任意の個数の [CODE(DOMi)@en[USVString]] が[[引数]]として指定されたと解釈した結果に設定します。
= [72] [[現在設定群オブジェクト]]の[F[大域オブジェクト]]が [CODE(DOMi)@en[ServiceWorkerGlobalScope]] で、
[[現在設定群オブジェクト]]の[F[大域オブジェクト]]の [F[importscripts allowed flag]] が[[偽]]なら、
== [73] [CODE(DOMe)@en[InvalidStateError]] [[例外]]を[[投げ]]、ここで停止します
[SRC[>>22]]。
= [66] [VAR[URL群]]と[[現在設定群オブジェクト]]について、[[ワーカー大域適用範囲にスクリプトを輸入]]します。
[VAR[[[fetchの実行]]]]は、[[文脈オブジェクト]]に依存して決まる処理とします。
[[例外]]が[[投げ]]られれば、[[再び投げ]]ます。
]FIG]
[11] [[サービスワーカー]]は、 [DFN[[F[imported scripts updated flag]]]]
を持ちます。初期値は[[未設定]]です。 [SRC[>>10]]
[27] [CODE(DOMi)@en[[[ServiceWorkerGlobalScope]]]] [[オブジェクト]]は、
[DFN[[F[importscripts allowed flag]]]] を持ちます。初期状態では[[偽]]です [SRC[>>28]]。
[67] [DFN[[RUBYB[ワーカー大域適用範囲にスクリプトを輸入]@en[import scripts into worker global scope]]]]するには、
[VAR[URL群]]と[VAR[設定群オブジェクト]]と[VAR[[[fetchの実行]]]]について次のようにします。
[FIG(steps)[
= [57] [[文脈オブジェクト]]の[F[[[型]]]]が [CODE[[[module]]]] なら、
== [58] [CODE(DOMe)@en[[[TypeError]]]] [[例外]]を[[投げ]]、停止します。
=
@@ [24] [[状態を検証]]します。
= [5] [VAR[URL群]]が空なら、
== [68] ここで停止します。
= [6] [VAR[URL群]]の各[VAR[項目]]について、
== [69] [VAR[項目]]を、[VAR[項目]]を[VAR[設定群オブジェクト]]に対して[[構文解析][URLの構文解析]]した結果に設定します。
== [70] [VAR[項目]]が[[失敗]]なら、
=== [7] [CODE(DOMe)@en[[[SyntaxError]]]] [[例外]]を[[投げ]]、ここで停止します。
= [9] [VAR[URL群]]の各[VAR[項目]]について、
== [71] [VAR[スクリプト]]を、[[古典ワーカーで輸入されたスクリプトをfetch]]した結果に設定します。
[VAR[URL]]、[VAR[設定群オブジェクト]]、[VAR[fetchの実行]]を引き渡します。
[[例外]]が[[投げ]]られれば、[[再び投げ]]ます。
== [15] [VAR[結果]]を、[VAR[スクリプト]]について、
[VAR[エラーを再度投げる]]フラグを設定して[[古典スクリプトを実行]]した結果に設定します。
== [13] [VAR[結果]]が何も返されなければ、ここで停止します。
==- [[例外]]が投げられているか、[[走っているスクリプトの実行中断]]がなされています。
]FIG]
;; [19] 本[[メソッド]]は [[fetch]] の結果を[[同期的]]に待っています。ただし
[[fetch]] の開始は同時なので、[[スクリプト]]実行中に[[ネットワーク]]から取得されることを期待できます。
後の[[スクリプト]]は、前の[[スクリプト]]が実行完了していることを前提にできます。
[HISTORY[
[26] 以前は[DFN[[RUBYB[状態の検証]@en[validate the state]]]]、
[DFN[[RUBYB[fetch結果の取得]@en[get a fetch result]]]]、
[DFN[[RUBYB[fetch結果の後処理]@en[postprocess the fetch result]]]]という引数が規定されていましたが、
廃止されました。後2者は[[fetchの処理]]に統合されました。
]HISTORY]
* 歴史
[1] [CITE[importScripts() no longer checking for cross-origin loads]] ([[Ian Hickson <ian@...>]] 著, [TIME[2008-11-26 23:40:05 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/16885>
[21] [CITE@en[Refactor importScripts(urls) · whatwg/html@509578d]] ([TIME[2015-09-03 21:07:19 +09:00]] 版) <https://github.com/whatwg/html/commit/509578d97bd12374e50a409bd4f1ec63cd36a543>
[54] [CITE@en[Give importScripts() a base URL · whatwg/html@fc4168b]]
([TIME[2015-09-16 11:41:13 +09:00]] 版)
<https://github.com/whatwg/html/commit/fc4168b1ccde276fbf936bbc592353f585d83d5c>
[55] [CITE@en[Integrate Fetch into HTML · whatwg/html@7c5555a]]
([TIME[2015-09-18 20:00:20 +09:00]] 版)
<https://github.com/whatwg/html/commit/7c5555a16f2920c02244c10756bb2f1a11e87a22>
[59] [CITE@en[Throw NetworkError for cross-origin importScripts() exceptions · whatwg/html@1e865ed]] ([TIME[2015-10-28 00:00:43 +09:00]] 版) <https://github.com/whatwg/html/commit/1e865ed22daf02d331966765b948bcece800678f>
[60] [CITE@en[Rewrite script execution on top of ES · whatwg/html@4891d18]]
([TIME[2015-12-23 01:36:20 +09:00]] 版)
<https://github.com/whatwg/html/commit/4891d18aaf2df1d40aa61f467a5a10cfc19dd85d>
[61] [CITE@en[Fix importScripts() script execution · whatwg/html@704907d]]
([TIME[2015-12-23 23:19:26 +09:00]] 版)
<https://github.com/whatwg/html/commit/704907dc195e77759fb7b48e51932094d150b7fc>
[16] [CITE@en[Add <script type="module"> and module resolution/fetching/evaluation · whatwg/html@cd1a9fb]] ([TIME[2016-01-29 23:05:37 +09:00]] 版) <https://github.com/whatwg/html/commit/cd1a9fb1e83f7d0bc30be8b34ecdaf444a0b19a4>
[18] [CITE@en[URLs are parsed and produce records · whatwg/html@30bc255]]
([TIME[2016-02-14 23:06:46 +09:00]] 版)
<https://github.com/whatwg/html/commit/30bc2557105ad62881ec9670f253febbc9761b44>
[56] [CITE@en[Add module workers · whatwg/html@e3a5bb7]]
([TIME[2016-02-15 23:02:51 +09:00]] 版)
<https://github.com/whatwg/html/commit/e3a5bb757f64374c37d8c4528c01298463ef0b2a>
[63] [CITE@en[Fix #715: clarify how aborting a running script works · whatwg/html@6a48bfb]]
([TIME[2016-02-24 17:12:24 +09:00]] 版)
<https://github.com/whatwg/html/commit/6a48bfbf1066034eab4786d62ba4017593c48430>
[14] [CITE@en[Make script fetching more correct with regard to request destinations · whatwg/html@6dc9c9e]]
([TIME[2016-02-29 18:12:54 +09:00]] 版)
<https://github.com/whatwg/html/commit/6dc9c9e1efcc3122294fb015e4a4eea66456a611>
[64] [CITE@en[Use USVString for all URLs]]
( ([[domenic]]著, [TIME[2016-05-20 22:02:29 +09:00]]))
<https://github.com/whatwg/html/commit/018b983b77b2cd908f6d00100e7e0abe893dd2c3>
[65] [CITE@en[Improve all the script-fetching algorithms]]
([[domenic]]著, [TIME[2016-07-08 01:25:53 +09:00]])
<https://github.com/whatwg/html/commit/b4f40e72fcca8a13eefa8a2dd06258378e76fcb7>
[8] [CITE@en[Editorial: use "current settings object" for importScripts]]
([[domenic]]著, [TIME[2016-10-25 05:12:50 +09:00]])
<https://github.com/whatwg/html/commit/a2df643560f246fa9ff2c62825d1636504e73a96>
[12] [CITE@en[Enforce strict MIME type checks for worker-imported scripts]]
([[mikewest]]著, [TIME[2018-12-19 07:18:59 +09:00]])
<https://github.com/whatwg/html/commit/d1c3679934f52450666750464effb97e14f555e0>
[17] [CITE@en[Nosniffing for Worker Scripts · Issue #3255 · whatwg/html]]
([TIME[2019-05-31 18:27:12 +09:00]])
<https://github.com/whatwg/html/issues/3255>