Skip to content

Commit 7c07a47

Browse files
How to create registration objects (#1445)
* How to create registration objects * Fixes following feedback * v1
1 parent 5580c1d commit 7c07a47

File tree

2 files changed

+72
-24
lines changed

2 files changed

+72
-24
lines changed

docs/index.bs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,30 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
477477
};
478478
</pre>
479479

480-
A {{ServiceWorkerRegistration}} object represents a [=/service worker registration=]. Each {{ServiceWorkerRegistration}} object is associated with a <dfn for="ServiceWorkerRegistration">service worker registration</dfn> (a [=/service worker registration=]). Multiple separate objects implementing the {{ServiceWorkerRegistration}} interface across documents and workers can all be associated with the same [=/service worker registration=] simultaneously.
480+
A {{ServiceWorkerRegistration}} has a <dfn for="ServiceWorkerRegistration">service worker registration</dfn> (a [=/service worker registration=]).
481+
482+
<section>
483+
<h4 id="service-worker-registration-creation">Getting {{ServiceWorkerRegistration}} instances</h4>
484+
485+
An [=environment settings object=] has a <dfn for="environment settings object">service worker registration object map</dfn>, a [=/map=] where the [=map/keys=] are [=/service worker registrations=] and the [=map/values=] are {{ServiceWorkerRegistration}} objects.
486+
487+
<section algorithm="service-worker-registration-creation-algorithm">
488+
To <dfn lt="get the service worker registration object|getting the service worker registration object">get the service worker registration object</dfn> representing |registration| (a [=/service worker registration=]) in |environment| (an [=environment settings object=]), run these steps:
489+
490+
1. Let |objectMap| be |environment|'s [=environment settings object/service worker registration object map=].
491+
1. If |objectMap|[|registration|] does not [=map/exist=], then:
492+
1. Let |registrationObject| be a new {{ServiceWorkerRegistration}} in |environment|'s [=environment settings object/Realm=].
493+
1. Set |registrationObject|'s [=ServiceWorkerRegistration/service worker registration=] to |registration|.
494+
1. Set |registrationObject|'s {{ServiceWorkerRegistration/installing}} attribute to null.
495+
1. Set |registrationObject|'s {{ServiceWorkerRegistration/waiting}} attribute to null.
496+
1. Set |registrationObject|'s {{ServiceWorkerRegistration/active}} attribute to null.
497+
1. If |registration|'s [=service worker registration/installing worker=] is not null, then set |registrationObject|'s {{ServiceWorkerRegistration/installing}} attribute to the result of [=getting the service worker object=] that represents |registration|'s [=service worker registration/installing worker=] in |environment|.
498+
1. If |registration|'s [=service worker registration/waiting worker=] is not null, then set |registrationObject|'s {{ServiceWorkerRegistration/waiting}} attribute to the result of [=getting the service worker object=] that represents |registration|'s [=service worker registration/waiting worker=] in |environment|.
499+
1. If |registration|'s [=service worker registration/active worker=] is not null, then set |registrationObject|'s {{ServiceWorkerRegistration/active}} attribute to the result of [=getting the service worker object=] that represents |registration|'s [=service worker registration/active worker=] in |environment|.
500+
1. Set |objectMap|[|registration|] to |registrationObject|.
501+
1. Return |objectMap|[|registration|].
502+
</section>
503+
</section>
481504

482505
<section algorithm="navigator-service-worker-installing">
483506
<h4 id="navigator-service-worker-installing">{{ServiceWorkerRegistration/installing}}</h4>
@@ -653,7 +676,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
653676
1. Let |readyPromise| be the [=context object=]'s [=ServiceWorkerContainer/ready promise=].
654677
1. If |readyPromise| is pending, run the following substeps [=in parallel=]:
655678
1. Let |registration| be the result of running [=Match Service Worker Registration=] with the [=context object=]'s [=ServiceWorkerContainer/service worker client=]'s [=creation URL=].
656-
1. If |registration| is not null, and |registration|'s [=active worker=] is not null, [=queue a task=] on |readyPromise|'s [=relevant settings object=]'s [=responsible event loop=], using the [=DOM manipulation task source=], to resolve |readyPromise| with the {{ServiceWorkerRegistration}} object that represents |registration| in |readyPromise|'s [=relevant Realm=].
679+
1. If |registration| is not null, and |registration|'s [=active worker=] is not null, [=queue a task=] on |readyPromise|'s [=relevant settings object=]'s [=responsible event loop=], using the [=DOM manipulation task source=], to resolve |readyPromise| with the result of [=getting the service worker registration object=] that represents |registration| in |readyPromise|'s [=relevant settings object=].
657680
1. Return |readyPromise|.
658681

659682
Note: The returned [=ServiceWorkerContainer/ready promise=] will never reject. If it does not resolve in this algorithm, it will eventually resolve when a matching [=/service worker registration=] is registered and its [=active worker=] is set. (See the relevant [Activate algorithm step](#activate-resolve-ready-step).)
@@ -688,10 +711,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
688711
1. Let |promise| be a new <a>promise</a>.
689712
1. Run the following substeps <a>in parallel</a>:
690713
1. Let |registration| be the result of running <a>Match Service Worker Registration</a> algorithm with |clientURL| as its argument.
691-
1. If |registration| is not null, then:
692-
1. Resolve |promise| with the {{ServiceWorkerRegistration}} object which represents |registration|.
693-
1. Else:
694-
1. Resolve |promise| with undefined.
714+
1. If |registration| is null, resolve |promise| with undefined and abort these steps.
715+
1. Resolve |promise| with the result of [=getting the service worker registration object=] that represents |registration| in |promise|'s [=relevant settings object=].
695716
1. Return |promise|.
696717
</section>
697718

@@ -708,7 +729,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
708729
1. If the [=url/origin=] of the result of [=URL parser|parsing=] |scope| is the [=same origin|same=] as |client|'s [=environment settings object/origin=], then [=append=] |registration| to |registrations|.
709730
1. [=Queue a task=] on |promise|'s [=relevant settings object=]'s [=responsible event loop=], using the [=DOM manipulation task source=], to run the following steps:
710731
1. Let |registrationObjects| be a new [=list=].
711-
1. [=list/For each=] |registration| of |registrations|, [=append=] the {{ServiceWorkerRegistration}} object associated with |registration| to |registrationObjects|.
732+
1. [=list/For each=] |registration| of |registrations|:
733+
1. Let |registrationObj| be the result of [=getting the service worker registration object=] that represents |registration| in |promise|'s [=relevant settings object=].
734+
1. [=list/Append=] |registrationObj| to |registrationObjects|.
712735
1. Resolve |promise| with [=create a frozen array|a new frozen array of=] |registrationObjects| in |promise|'s [=relevant Realm=].
713736
1. Return |promise|.
714737
</section>
@@ -953,7 +976,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
953976
<section>
954977
<h4 id="service-worker-global-scope-registration">{{ServiceWorkerGlobalScope/registration}}</h4>
955978

956-
The <dfn attribute for="ServiceWorkerGlobalScope"><code>registration</code></dfn> attribute *must* return the {{ServiceWorkerRegistration}} object that represents the [=ServiceWorkerGlobalScope/service worker=]'s <a>containing service worker registration</a>.
979+
The <dfn attribute for="ServiceWorkerGlobalScope"><code>registration</code></dfn> attribute *must* return the result of [=getting the service worker registration object=] representing the [=context object=]'s [=ServiceWorkerGlobalScope/service worker=]'s [=containing service worker registration=] in [=context object=]'s [=relevant settings object=].
957980
</section>
958981

959982
<section>
@@ -2380,15 +2403,16 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
23802403
: Output
23812404
:: none
23822405

2383-
1. Let |convertedValue| be null.
23842406
1. If |job|'s [=job/client=] is not null, [=queue a task=], on |job|'s [=job/client=]'s [=responsible event loop=] using the [=DOM manipulation task source=], to run the following substeps:
2385-
1. If |job|'s [=job/job type=] is either *register* or *update*, set |convertedValue| to the {{ServiceWorkerRegistration}} object that represents |value|, in |job|'s [=job/client=]'s [=environment settings object/Realm=].
2407+
1. Let |convertedValue| be null.
2408+
1. If |job|'s [=job/job type=] is either *register* or *update*, set |convertedValue| to the result of [=getting the service worker registration object=] that represents |value| in |job|'s [=job/client=].
23862409
1. Else, set |convertedValue| to |value|, in |job|'s [=job/client=]'s [=environment settings object/Realm=].
23872410
1. Resolve |job|'s [=job/job promise=] with |convertedValue|.
23882411
1. For each |equivalentJob| in |job|'s <a>list of equivalent jobs</a>:
23892412
1. If |equivalentJob|'s [=job/client=] is null, continue to the next iteration of the loop.
23902413
1. [=Queue a task=], on |equivalentJob|'s [=job/client=]'s [=responsible event loop=] using the [=DOM manipulation task source=], to run the following substeps:
2391-
1. If |equivalentJob|'s [=job/job type=] is either *register* or *update*, set |convertedValue| to the {{ServiceWorkerRegistration}} object that represents |value|, in |equivalentJob|'s [=job/client=]'s [=environment settings object/Realm=].
2414+
1. Let |convertedValue| be null.
2415+
1. If |equivalentJob|'s [=job/job type=] is either *register* or *update*, set |convertedValue| to the result of [=getting the service worker registration object=] that represents |value| in |equivalentJob|'s [=job/client=].
23922416
1. Else, set |convertedValue| to |value|, in |equivalentJob|'s [=job/client=]'s [=environment settings object/Realm=].
23932417
1. Resolve |equivalentJob|'s [=job/job promise=] with |convertedValue|.
23942418
</section>
@@ -2709,7 +2733,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
27092733
1. Let |matchedClients| be a [=list=] of [=/service worker clients=] whose <a>creation URL</a> <a lt="Match Service Worker Registration">matches</a> |registration|'s [=service worker registration/scope url=].
27102734
1. [=list/For each=] |client| of |matchedClients|, [=queue a task=] on |client|'s [=responsible event loop=], using the [=DOM manipulation task source=], to run the following substeps:
27112735
1. Let |readyPromise| be |client|'s [=environment settings object/global object=]'s {{ServiceWorkerContainer}} object's [=ServiceWorkerContainer/ready promise=].
2712-
1. <span id="activate-resolve-ready-step">If |readyPromise| is pending, resolve |readyPromise| with the {{ServiceWorkerRegistration}} object that represents |registration| in |readyPromise|'s [=relevant Realm=]</span>.
2736+
1. <span id="activate-resolve-ready-step">If |readyPromise| is pending, resolve |readyPromise| with the the result of [=getting the service worker registration object=] that represents |registration| in |readyPromise|'s [=relevant settings object=]</span>.
27132737
1. [=list/For each=] |client| of |matchedClients|:
27142738
1. If |client| is a <a>window client</a>, unassociate |client|'s <a>responsible document</a> from its <a>application cache</a>, if it has one.
27152739
1. Else if |client| is a <a>shared worker client</a>, unassociate |client|'s [=environment settings object/global object=] from its <a>application cache</a>, if it has one.

0 commit comments

Comments
 (0)