Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update usages of module fetching html algorithms #1658

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
<section>
<h4 id="importscripts">{{WorkerGlobalScope/importScripts(urls)}}</h4>

When the <dfn method for="ServiceWorkerGlobalScope" id="importscripts-method"><code>importScripts(|urls|)</code></dfn> method is called on a {{ServiceWorkerGlobalScope}} object, the user agent *must* <a>import scripts into worker global scope</a>, given this {{ServiceWorkerGlobalScope}} object and |urls|, and with the following steps to [=fetching scripts/perform the fetch=] given the [=/request=] |request|:
When the <dfn method for="ServiceWorkerGlobalScope" id="importscripts-method"><code>importScripts(|urls|)</code></dfn> method is called on a {{ServiceWorkerGlobalScope}} object, the user agent *must* <a>import scripts into worker global scope</a>, given this {{ServiceWorkerGlobalScope}} object and |urls|, and with the following [=fetching scripts/synchronous perform the fetch hook=] given the [=/request=] |request|:

1. Let |serviceWorker| be |request|'s [=request/client=]'s [=environment settings object/global object=]'s [=ServiceWorkerGlobalScope/service worker=].
1. Let |map| be |serviceWorker|'s [=script resource map=].
Expand Down Expand Up @@ -2646,15 +2646,15 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
1. Switching on |job|'s [=worker type=], run these substeps with the following options:
<!-- TODO: reorganize algorithm so that the worker environment is created before fetching happens -->
: "<code>classic</code>"
:: <a>Fetch a classic worker script</a> given |job|’s <a lt="URL serializer">serialized</a> [=job/script url=], |job|’s [=job/client=], "<code>serviceworker</code>", and the to-be-created <a>environment settings object</a> for this service worker.
:: <a>Fetch a classic worker script</a> given |job|’s <a lt="URL serializer">serialized</a> [=job/script url=], |job|’s [=job/client=], "<code>serviceworker</code>", the to-be-created <a>environment settings object</a> for this service worker, and |onComplete| and |performFetch| as defined below.
: "<code>module</code>"
:: <a>Fetch a module worker script graph</a> given |job|’s <a lt="URL serializer">serialized</a> [=job/script url=], |job|’s [=job/client=], "<code>serviceworker</code>", "<code>omit</code>", and the to-be-created <a>environment settings object</a> for this service worker.
:: <a>Fetch a module worker script graph</a> given |job|’s <a lt="URL serializer">serialized</a> [=job/script url=], |job|’s [=job/client=], "<code>serviceworker</code>", "<code>omit</code>", and the to-be-created <a>environment settings object</a> for this service worker, and |onComplete| and |performFetch| as defined below.

Issue: Using the to-be-created [=environment settings object=] rather than a concrete [=environment settings object=]. This is used due to the unique processing model of service workers compared to the processing model of other [=web workers=]. The script fetching algorithms of HTML standard originally designed for other [=web workers=] require an [=environment settings object=] of the execution environment, but service workers fetch a script separately in the [=Update=] algorithm before the script later runs multiple times through the [=Run Service Worker=] algorithm.

Issue: The [=fetch a classic worker script=] algorithm and the [=fetch a module worker script graph=] algorithm in HTML take |job|’s [=job/client=] as an argument. |job|’s [=job/client=] is null when passed from the [=Soft Update=] algorithm.

To [=fetching scripts/perform the fetch=] given |request|, run the following steps:
In both cases, let |performFetch| be the following [=fetching scripts/asynchronous perform the fetch hook=] given |request|, |isTopLevel| and |processCustomFetchResponse|:

1. Append \`<code>Service-Worker</code>\`/\`<code>script</code>\` to |request|'s [=request/header list=].

Expand All @@ -2668,19 +2668,19 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
Note: Even if the cache mode is not set to "<code>no-cache</code>", the user agent obeys Cache-Control header's max-age value in the network layer to determine if it should bypass the browser cache.

1. Set |request|'s [=service-workers mode=] to "`none`".
1. If the [=fetching scripts/is top-level=] flag is unset, then return the result of [=/fetching=] |request|.
1. If |isTopLevel| is false, [=fetch=] |request| with processCustomFetchResponse as [=fetch/processResponseConsumeBody=], and abort these steps.
1. Set |request|'s [=request/redirect mode=] to "<code>error</code>".
1. [=/Fetch=] |request|, and asynchronously wait to run the remaining steps as part of fetch's <a>process response</a> for the [=/response=] |response|.
1. [=Extract a MIME type=] from the |response|'s [=response/header list=]. If this MIME type (ignoring parameters) is not a [=JavaScript MIME type=], then:
1. Invoke [=Reject Job Promise=] with |job| and "{{SecurityError}}" {{DOMException}}.
1. Asynchronously complete these steps with a [=network error=].
1. Invoke |processCustomFetchResponse| with a [=network error=] and abort these steps.
1. Let |serviceWorkerAllowed| be the result of [=extracting header list values=] given \`<code>Service-Worker-Allowed</code>\` and |response|'s [=response/header list=].

Note: See the definition of the [=Service-Worker-Allowed=] header in Appendix B: Extended HTTP headers.

1. Set |policyContainer| to the result of <a>creating a policy container from a fetch response</a> given |response|.
1. If |serviceWorkerAllowed| is failure, then:
1. Asynchronously complete these steps with a <a>network error</a>.
1. Invoke |processCustomFetchResponse| with a [=network error=] and abort these steps.
1. Let |scopeURL| be |registration|'s [=service worker registration/scope url=].
1. Let |maxScopeString| be null.
1. If |serviceWorkerAllowed| is null, then:
Expand Down Expand Up @@ -2726,32 +2726,32 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
1. If |fetchedResponse|'s [=response/body=] is not byte-for-byte identical with |storedResponse|'s [=unsafe response=]'s [=response/body=], set |hasUpdatedResources| to true.

Note: The control does not break the loop in this step to continue with all the imported scripts to populate the cache.
1. Asynchronously complete these steps with |response|.
1. Invoke |processCustomFetchResponse| with |response|.

When the algorithm asynchronously completes, continue the rest of these steps, with |script| being the asynchronous completion value.
In both cases, let |onComplete| given |script| be the following algorithm:

1. If |script| is null or [=Is Async Module=] with |script|'s [=script/record=], |script|'s [=script/base URL=], and « » is true, then:
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
1. If |script| is null or [=Is Async Module=] with |script|'s [=script/record=], |script|'s [=script/base URL=], and « » is true, then:
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.

Note: This will do nothing if [=Reject Job Promise=] was previously invoked with "{{SecurityError}}" {{DOMException}}.

1. If |newestWorker| is null, then [=map/remove=] [=registration map=][(|registration|'s [=service worker registration/storage key=], [=URL serializer|serialized=] |scopeURL|)].
1. Invoke [=Finish Job=] with |job| and abort these steps.
1. If |hasUpdatedResources| is false, then:
1. Set |registration|'s [=service worker registration/update via cache mode=] to |job|'s [=job/update via cache mode=].
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
1. Invoke [=Finish Job=] with |job| and abort these steps.
1. Let |worker| be a new [=/service worker=].
1. Set |worker|'s [=service worker/script url=] to |job|'s [=job/script url=], |worker|'s [=script resource=] to |script|, |worker|'s [=service worker/type=] to |job|'s [=worker type=], and |worker|'s [=script resource map=] to |updatedResourceMap|.
1. Append |url| to |worker|'s [=set of used scripts=].
1. Set |worker|'s <a>script resource</a>'s [=script resource/policy container=] to |policyContainer|.
1. Let |forceBypassCache| be true if |job|'s [=job/force bypass cache flag=] is set, and false otherwise.
1. Let |runResult| be the result of running the [=Run Service Worker=] algorithm with |worker| and |forceBypassCache|.
1. If |runResult| is *failure* or an [=abrupt completion=], then:
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
1. If |newestWorker| is null, then [=map/remove=] [=registration map=][(|registration|'s [=service worker registration/storage key=], [=URL serializer|serialized=] |scopeURL|)].
1. Invoke [=Finish Job=] with |job|.
1. Else, invoke [=Install=] algorithm with |job|, |worker|, and |registration| as its arguments.
Note: This will do nothing if [=Reject Job Promise=] was previously invoked with "{{SecurityError}}" {{DOMException}}.

1. If |newestWorker| is null, then [=map/remove=] [=registration map=][(|registration|'s [=service worker registration/storage key=], [=URL serializer|serialized=] |scopeURL|)].
1. Invoke [=Finish Job=] with |job| and abort these steps.
1. If |hasUpdatedResources| is false, then:
1. Set |registration|'s [=service worker registration/update via cache mode=] to |job|'s [=job/update via cache mode=].
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
1. Invoke [=Finish Job=] with |job| and abort these steps.
1. Let |worker| be a new [=/service worker=].
1. Set |worker|'s [=service worker/script url=] to |job|'s [=job/script url=], |worker|'s [=script resource=] to |script|, |worker|'s [=service worker/type=] to |job|'s [=worker type=], and |worker|'s [=script resource map=] to |updatedResourceMap|.
1. Append |url| to |worker|'s [=set of used scripts=].
1. Set |worker|'s <a>script resource</a>'s [=script resource/policy container=] to |policyContainer|.
1. Let |forceBypassCache| be true if |job|'s [=job/force bypass cache flag=] is set, and false otherwise.
1. Let |runResult| be the result of running the [=Run Service Worker=] algorithm with |worker| and |forceBypassCache|.
1. If |runResult| is *failure* or an [=abrupt completion=], then:
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
1. If |newestWorker| is null, then [=map/remove=] [=registration map=][(|registration|'s [=service worker registration/storage key=], [=URL serializer|serialized=] |scopeURL|)].
1. Invoke [=Finish Job=] with |job|.
1. Else, invoke [=Install=] algorithm with |job|, |worker|, and |registration| as its arguments.
</section>

<section algorithm>
Expand Down