状態を検証

ワーカー importScripts メソッド (DOM)

[23] ワーカー大域オブジェクトimportScripts メソッドは、指定した URLスクリプトを実行するよう指示するものです。

仕様書

処理

[3] WorkerGlobalScope インターフェイスimportScripts メソッドは、 次のようにしなければなりません >>2

  1. [4] URL群を、任意の個数の USVString引数として指定されたと解釈した結果に設定します。
  2. [72] 現在設定群オブジェクト大域オブジェクトServiceWorkerGlobalScope で、 現在設定群オブジェクト大域オブジェクトimportscripts allowed flagなら、
    1. [73] InvalidStateError 例外投げ、ここで停止します >>22
  3. [66] URL群現在設定群オブジェクトについて、ワーカー大域適用範囲にスクリプトを輸入します。 fetchの実行は、文脈オブジェクトに依存して決まる処理とします。 例外投げられれば、再び投げます。

[11] サービスワーカーは、 imported scripts updated flag を持ちます。初期値は未設定です。 >>10

[27] ServiceWorkerGlobalScope オブジェクトは、 importscripts allowed flag を持ちます。初期状態ではです >>28

[67] ワーカー大域適用範囲にスクリプトを輸入 (import scripts into worker global scope) するには、 URL群設定群オブジェクトfetchの実行について次のようにします。

  1. [57] 文脈オブジェクトmodule なら、
    1. [58] TypeError 例外投げ、停止します。
  2. [24] 状態を検証します。
  3. [5] URL群が空なら、
    1. [68] ここで停止します。
  4. [6] URL群の各項目について、
    1. [69] 項目を、項目設定群オブジェクトに対して構文解析した結果に設定します。
    2. [70] 項目失敗なら、
      1. [7] SyntaxError 例外投げ、ここで停止します。
  5. [9] URL群の各項目について、
    1. [71] スクリプトを、古典ワーカーで輸入されたスクリプトをfetchした結果に設定します。 URL設定群オブジェクトfetchの実行を引き渡します。 例外投げられれば、再び投げます。
    2. [15] 結果を、スクリプトについて、 エラーを再度投げるフラグを設定して古典スクリプトを実行した結果に設定します。
    3. [13] 結果が何も返されなければ、ここで停止します。
[19]メソッドfetch の結果を同期的に待っています。ただし fetch の開始は同時なので、スクリプト実行中にネットワークから取得されることを期待できます。 後のスクリプトは、前のスクリプトが実行完了していることを前提にできます。

[26] 以前は状態の検証 (validate the state) fetch結果の取得 (get a fetch result) fetch結果の後処理 (postprocess the fetch result) という引数が規定されていましたが、 廃止されました。後2者はfetchの処理に統合されました。

歴史

[1] importScripts() no longer checking for cross-origin loads (Ian Hickson <ian@...> 著, 版) http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/16885

[21] Refactor importScripts(urls) · whatwg/html@509578d ( 版) https://github.com/whatwg/html/commit/509578d97bd12374e50a409bd4f1ec63cd36a543

[54] Give importScripts() a base URL · whatwg/html@fc4168b ( 版) https://github.com/whatwg/html/commit/fc4168b1ccde276fbf936bbc592353f585d83d5c

[55] Integrate Fetch into HTML · whatwg/html@7c5555a ( 版) https://github.com/whatwg/html/commit/7c5555a16f2920c02244c10756bb2f1a11e87a22

[59] Throw NetworkError for cross-origin importScripts() exceptions · whatwg/html@1e865ed ( 版) https://github.com/whatwg/html/commit/1e865ed22daf02d331966765b948bcece800678f

[60] Rewrite script execution on top of ES · whatwg/html@4891d18 ( 版) https://github.com/whatwg/html/commit/4891d18aaf2df1d40aa61f467a5a10cfc19dd85d

[61] Fix importScripts() script execution · whatwg/html@704907d ( 版) https://github.com/whatwg/html/commit/704907dc195e77759fb7b48e51932094d150b7fc

[16] Add <script type="module"> and module resolution/fetching/evaluation · whatwg/html@cd1a9fb ( 版) https://github.com/whatwg/html/commit/cd1a9fb1e83f7d0bc30be8b34ecdaf444a0b19a4

[18] URLs are parsed and produce records · whatwg/html@30bc255 ( 版) https://github.com/whatwg/html/commit/30bc2557105ad62881ec9670f253febbc9761b44

[56] Add module workers · whatwg/html@e3a5bb7 ( 版) https://github.com/whatwg/html/commit/e3a5bb757f64374c37d8c4528c01298463ef0b2a

[63] Fix #715: clarify how aborting a running script works · whatwg/html@6a48bfb ( 版) https://github.com/whatwg/html/commit/6a48bfbf1066034eab4786d62ba4017593c48430

[14] Make script fetching more correct with regard to request destinations · whatwg/html@6dc9c9e ( 版) https://github.com/whatwg/html/commit/6dc9c9e1efcc3122294fb015e4a4eea66456a611

[64] Use USVString for all URLs ( (domenic著, )) https://github.com/whatwg/html/commit/018b983b77b2cd908f6d00100e7e0abe893dd2c3

[65] Improve all the script-fetching algorithms (domenic著, ) https://github.com/whatwg/html/commit/b4f40e72fcca8a13eefa8a2dd06258378e76fcb7

[8] Editorial: use "current settings object" for importScripts (domenic著, ) https://github.com/whatwg/html/commit/a2df643560f246fa9ff2c62825d1636504e73a96

[12] Enforce strict MIME type checks for worker-imported scripts (mikewest著, ) https://github.com/whatwg/html/commit/d1c3679934f52450666750464effb97e14f555e0

[17] Nosniffing for Worker Scripts · Issue #3255 · whatwg/html () https://github.com/whatwg/html/issues/3255

[20] Minor improvements around importScripts. (#1380) (mattto著, ) https://github.com/w3c/ServiceWorker/commit/c0aa49426169003379227b80dd84ade7c2819584

[25] Minor improvements around importScripts. by mattto · Pull Request #1380 · w3c/ServiceWorker () https://github.com/w3c/ServiceWorker/pull/1380