Skip to content

Commit 7f2b6e1

Browse files
authored
Improve "update via cache" and "worker type" in register algorithms. (#1411)
This makes the following changes: * updateViaCache is a live property. This is mostly covered by the WPT registration-updateviacache.https.html. A test that the updateViaCache change is only committed if the register() call resolves is added in web-platform-tests/wpt#17131. * Changing worker type bypasses the byte-for-byte update check. This is covered by WPT update-registration-with-type.https.html. * Adds Worker type and updateViaCache to the job equivalence check. A test for this is added in web-platform-tests/wpt#17131. Addresses #1189, #1408, #1359, and #1358.
1 parent 8077176 commit 7f2b6e1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

docs/index.bs

+12-8
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
637637

638638
Note: The {{ServiceWorkerContainer/register(scriptURL, options)}} method creates or updates a [=/service worker registration=] for the given [=service worker registration/scope url=]. If successful, a [=/service worker registration=] ties the provided |scriptURL| to a [=service worker registration/scope url=], which is subsequently used for <a lt="handle fetch">navigation matching</a>.
639639

640-
<dfn method for="ServiceWorkerContainer"><code>register(|scriptURL|, |options|)</code></dfn> method *must* run these steps:
640+
The <dfn method for="ServiceWorkerContainer"><code>register(|scriptURL|, |options|)</code></dfn> method *must* run these steps:
641641

642642
1. Let |p| be a <a>promise</a>.
643643
1. Let |client| be the <a>context object</a>'s [=ServiceWorkerContainer/service worker client=].
@@ -2249,7 +2249,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
22492249

22502250
Two <a>jobs</a> are <dfn id="dfn-job-equivalent">equivalent</dfn> when their <a>job type</a> is the same and:
22512251

2252-
* For *register* and *update* <a>jobs</a>, both their [=job/scope url=] and the [=job/script url=] are the same.
2252+
* For *register* and *update* <a>jobs</a>, their [=job/scope url=], [=job/script url=], [=job/worker type=], and [=job/update via cache mode=] are the same.
22532253
* For *unregister* <a>jobs</a>, their [=job/scope url=] is the same.
22542254

22552255
A <dfn id="dfn-job-queue">job queue</dfn> is a thread safe [=queue=] used to synchronize the set of concurrent [=jobs=]. The [=job queue=] contains [=jobs=] as its [=queue/items=]. A [=job queue=] is initially empty.
@@ -2437,7 +2437,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24372437
1. If |registration| is not null, then:
24382438
1. If |registration|'s <a>uninstalling flag</a> is set, unset it.
24392439
1. Let |newestWorker| be the result of running the <a>Get Newest Worker</a> algorithm passing |registration| as the argument.
2440-
1. If |newestWorker| is not null, |job|'s [=job/script url=] [=url/equals=] |newestWorker|'s [=service worker/script url=], and |job|'s [=job/update via cache mode=]'s value equals |registration|'s [=service worker registration/update via cache mode=], then:
2440+
1. If |newestWorker| is not null, |job|'s [=job/script url=] [=url/equals=] |newestWorker|'s [=service worker/script url=], |job|'s [=job/worker type=] equals |newestWorker|'s [=service worker/type=], and |job|'s [=job/update via cache mode=]'s value equals |registration|'s [=service worker registration/update via cache mode=], then:
24412441
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
24422442
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
24432443
1. Else:
@@ -2465,7 +2465,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24652465
1. Let |referrerPolicy| be the empty string.
24662466
1. Let |hasUpdatedResources| be false.
24672467
1. Let |updatedResourceMap| be an [=ordered map=] where the [=map/keys=] are [=/URLs=] and the [=map/values=] are [=/responses=].
2468-
1. Switching on |job|'s <a>worker type</a>, run these substeps with the following options:
2468+
1. Switching on |job|'s [=worker type=], run these substeps with the following options:
24692469
<!-- TODO: reorganize algorithm so that the worker environment is created before fetching happens -->
24702470
: "<code>classic</code>"
24712471
:: <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.
@@ -2515,14 +2515,16 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25152515
1. Let |url| be |request|'s [=request/url=].
25162516
1. Set |updatedResourceMap|[|url|] to |response|.
25172517
1. If |response|'s [=response/cache state=] is not "`local`", set |registration|'s [=last update check time=] to the current time.
2518-
1. Let |map| be |newestWorker|'s [=script resource map=] if |newestWorker| is not null, and null otherwise.
2519-
1. If |map| is null or |map|[|url|]'s [=response/body=] is not byte-for-byte identical with |response|'s [=response/body=], set |hasUpdatedResources| to true.
2520-
1. Else if |newestWorker|'s [=classic scripts imported flag=] is set, then:
2518+
1. Set |hasUpdatedResources| to true if any of the following are true:
2519+
* |newestWorker| is null.
2520+
* |newestWorker|'s [=service worker/script url=] is not |url| or |newestWorker|'s [=service worker/type=] is not |job|'s [=worker type=].
2521+
* |newestWorker|'s [=script resource map=][|url|]'s [=response/body=] is not byte-for-byte identical with |response|'s [=response/body=].
2522+
1. If |hasUpdatedResources| is false and |newestWorker|'s [=classic scripts imported flag=] is set, then:
25212523

25222524
Note: The following checks to see if an imported script has been updated, since the main script has not changed.
25232525

25242526
1. [=map/For each=] |importUrl| → |storedResponse| of |newestWorker|'s [=script resource map=]:
2525-
1. If |importUrl| is |request|'s [=request/url=], then continue.
2527+
1. If |importUrl| is |url|, then continue.
25262528
1. Let |importRequest| be a new [=/request=] whose [=request/url=] is |importUrl|, [=request/client=] is |job|'s [=job/client=], [=request/destination=] is "`script`", [=request/parser metadata=] is "`not parser-inserted`", [=request/synchronous flag=] is set, and whose [=request/use-URL-credentials flag=] is set.
25272529
1. Set |importRequest|'s [=request/cache mode=] to "`no-cache`" if any of the following are true:
25282530
* |registration|'s [=service worker registration/update via cache mode=] is "`none`".
@@ -2552,6 +2554,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25522554

25532555
Else, continue the rest of these steps after the algorithm's asynchronous completion, with |script| being the asynchronous completion value.
25542556
1. If |hasUpdatedResources| is false, then:
2557+
1. Set |registration|'s [=service worker registration/update via cache mode=] to |job|'s [=job/update via cache mode=].
25552558
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
25562559
1. Invoke [=Finish Job=] with |job| and abort these steps.
25572560
1. Let |worker| be a new [=/service worker=].
@@ -2601,6 +2604,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26012604

26022605
1. Let |installFailed| be false.
26032606
1. Let |newestWorker| be the result of running <a>Get Newest Worker</a> algorithm passing |registration| as its argument.
2607+
1. Set |registration|'s [=service worker registration/update via cache mode=] to |job|'s [=job/update via cache mode=].
26042608
1. Run the <a>Update Registration State</a> algorithm passing |registration|, "<code>installing</code>" and |worker| as the arguments.
26052609
1. Run the <a>Update Worker State</a> algorithm passing |registration|'s <a>installing worker</a> and *installing* as the arguments.
26062610
1. Assert: |job|'s [=job/job promise=] is not null.

0 commit comments

Comments
 (0)