Skip to content

Commit d65ed67

Browse files
One ServiceWorker object per service worker per realm (#1428)
1 parent 94e6a67 commit d65ed67

File tree

2 files changed

+80
-48
lines changed

2 files changed

+80
-48
lines changed

docs/index.bs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
337337

338338
A {{ServiceWorker}} object has an associated {{ServiceWorkerState}} object which is itself associated with [=/service worker=]'s <a>state</a>.
339339

340+
<section>
341+
<h4 id="service-worker-creation">Getting {{ServiceWorker}} instances</h4>
342+
343+
An [=environment settings object=] has a <dfn for="environment settings object">service worker object map</dfn>, a [=/map=] where the [=map/keys=] are [=/service workers=] and the [=map/values=] are {{ServiceWorker}} objects.
344+
345+
<section algorithm="service-worker-creation-algorithm">
346+
To <dfn lt="get the service worker object|getting the service worker object">get the service worker object</dfn> representing |serviceWorker| (a [=/service worker=]) in |environment| (an [=environment settings object=]), run these steps:
347+
348+
1. Let |objectMap| be |environment|'s [=environment settings object/service worker object map=].
349+
1. If |objectMap|[|serviceWorker|] does not [=map/exist=], then set |objectMap|[|serviceWorker|] to a new {{ServiceWorker}} in |environment|'s [=environment settings object/Realm=], and associate it with |serviceWorker|.
350+
1. Return |objectMap|[|serviceWorker|].
351+
</section>
352+
</section>
353+
340354
<section>
341355
<h4 id="service-worker-url">{{ServiceWorker/scriptURL}}</h4>
342356

@@ -378,13 +392,14 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
378392
1. Let |serviceWorker| be the [=/service worker=] represented by the <a>context object</a>.
379393
1. If the result of running the [=Should Skip Event=] algorithm with "message" and |serviceWorker|, is true, then return.
380394
1. Invoke <a>Run Service Worker</a> algorithm with |serviceWorker| as the argument.
381-
1. Let |incumbentSettings| be the <a>incumbent settings object</a>, and |incumbentGlobal| its [=environment settings object/global object=].
395+
1. Let |incumbentSettings| be the [=incumbent settings object=].
396+
1. Let |incumbentGlobal| be |incumbentSettings|'s [=environment settings object/global object=].
382397
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |options|.transfer). Rethrow any exceptions.
383398
1. [=Queue a task=] on the [=DOM manipulation task source=] to run the following steps:
384399
1. Let |source| be determined by switching on the type of |incumbentGlobal|:
385400
<dl class="switch">
386401
<dt>{{ServiceWorkerGlobalScope}}</dt>
387-
<dd>a new {{ServiceWorker}} object that represents |incumbentGlobal|'s [=ServiceWorkerGlobalScope/service worker=].</dd>
402+
<dd>The result of [=getting the service worker object=] that represents |incumbentGlobal|'s [=ServiceWorkerGlobalScope/service worker=] in the [=relevant settings object=] of |serviceWorker|'s [=service worker/global object=].</dd>
388403

389404
<dt>{{Window}}</dt>
390405
<dd>a new {{WindowClient}} object that represents |incumbentGlobal|'s [=relevant settings object=].</dd>
@@ -461,23 +476,23 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
461476

462477
<dfn attribute for="ServiceWorkerRegistration"><code>installing</code></dfn> attribute *must* return the value to which it was last set.
463478

464-
Note: The {{ServiceWorker}} objects returned from this attribute getter that represent the same [=/service worker=] are the same objects.
479+
Note: Within a [=environment settings object/Realm=], there is only one {{ServiceWorker}} object per associated [=/service worker=].
465480
</section>
466481

467482
<section algorithm="navigator-service-worker-waiting">
468483
<h4 id="navigator-service-worker-waiting">{{ServiceWorkerRegistration/waiting}}</h4>
469484

470485
<dfn attribute for="ServiceWorkerRegistration"><code>waiting</code></dfn> attribute *must* return the value to which it was last set.
471486

472-
Note: The {{ServiceWorker}} objects returned from this attribute getter that represent the same [=/service worker=] are the same objects.
487+
Note: Within a [=environment settings object/Realm=], there is only one {{ServiceWorker}} object per associated [=/service worker=].
473488
</section>
474489

475490
<section algorithm="navigator-service-worker-active">
476491
<h4 id="navigator-service-worker-active">{{ServiceWorkerRegistration/active}}</h4>
477492

478493
<dfn attribute for="ServiceWorkerRegistration"><code>active</code></dfn> attribute *must* return the value to which it was last set.
479494

480-
Note: The {{ServiceWorker}} objects returned from this attribute getter that represent the same [=/service worker=] are the same objects.
495+
Note: Within a [=environment settings object/Realm=], there is only one {{ServiceWorker}} object per associated [=/service worker=].
481496
</section>
482497

483498
<section algorithm="service-worker-registration-navigationpreload">
@@ -616,9 +631,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
616631
<dfn attribute for="ServiceWorkerContainer"><code>controller</code></dfn> attribute *must* run these steps:
617632

618633
1. Let |client| be the <a>context object</a>'s [=ServiceWorkerContainer/service worker client=].
619-
1. Return the {{ServiceWorker}} object that represents |client|'s <a>active service worker</a>.
634+
1. If |client|'s [=active service worker=] is null, then return null.
635+
1. Return the result of [=getting the service worker object=] that represents |client|'s [=active service worker=] in the [=context object=]'s [=relevant settings object=].
620636

621-
Note: {{ServiceWorkerContainer/controller|navigator.serviceWorker.controller}} returns <code>null</code> if the request is a force refresh (shift+refresh). The {{ServiceWorker}} objects returned from this attribute getter that represent the same [=/service worker=] are the same objects.
637+
Note: {{ServiceWorkerContainer/controller|navigator.serviceWorker.controller}} returns <code>null</code> if the request is a force refresh (shift+refresh).
622638
</section>
623639

624640
<section algorithm="navigator-service-worker-ready">
@@ -910,8 +926,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
910926
attribute EventHandler onactivate;
911927
attribute EventHandler onfetch;
912928

913-
// event
914-
attribute EventHandler onmessage; // event.source of the message events is Client object
929+
attribute EventHandler onmessage;
915930
attribute EventHandler onmessageerror;
916931
};
917932
</pre>
@@ -923,7 +938,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
923938
<section>
924939
<h4 id="service-worker-global-scope-clients">{{ServiceWorkerGlobalScope/clients}}</h4>
925940

926-
<dfn attribute for="ServiceWorkerGlobalScope"><code>clients</code></dfn> attribute *must* return the {{Clients}} object that is associated with the <a>context object</a>.
941+
The <dfn attribute for="ServiceWorkerGlobalScope"><code>clients</code></dfn> attribute *must* return the {{Clients}} object that is associated with the <a>context object</a>.
927942
</section>
928943

929944
<section>
@@ -1074,17 +1089,18 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
10741089

10751090
The <dfn method for="Client"><code>postMessage(|message|, |options|)</code></dfn> method *must* run these steps:
10761091

1077-
1. Let |sourceSettings| be the [=context object=]'s [=relevant settings object=].
1092+
1. Let |contextObject| be the [=context object=].
1093+
1. Let |sourceSettings| be the |contextObject|'s [=relevant settings object=].
10781094
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |options|.transfer). Rethrow any exceptions.
10791095
1. Run the following steps [=in parallel=]:
10801096
1. Let |targetClient| be null.
10811097
1. For each [=/service worker client=] |client|:
1082-
1. If |client| is the [=context object=]'s [=Client/service worker client=], set |targetClient| to |client|, and [=break=].
1098+
1. If |client| is the |contextObject|'s [=Client/service worker client=], set |targetClient| to |client|, and [=break=].
10831099
1. If |targetClient| is null, return.
10841100
1. Let |destination| be the {{ServiceWorkerContainer}} object whose associated [=ServiceWorkerContainer/service worker client=] is |targetClient|.
10851101
1. Add a [=task=] that runs the following steps to |destination|'s [=ServiceWorkerContainer/client message queue=]:
10861102
1. Let |origin| be the [=Unicode serialization of an origin|Unicode serialization=] of |sourceSettings|'s [=environment settings object/origin=].
1087-
1. Let |source| be a {{ServiceWorker}} object, which represents the [=ServiceWorkerGlobalScope/service worker=] associated with |sourceSettings|'s [=environment settings object/global object=].
1103+
1. Let |source| be the result of [=getting the service worker object=] that represents |contextObject|'s [=relevant global object=]'s [=ServiceWorkerGlobalScope/service worker=] in |targetClient|.
10881104
1. Let |deserializeRecord| be <a abstract-op>StructuredDeserializeWithTransfer</a>(|serializeWithTransferResult|, |destination|'s [=relevant Realm=]).
10891105

10901106
If this throws an exception, catch it, [=fire an event=] named {{messageerror!!event}} at |destination|, using {{MessageEvent}}, with the {{MessageEvent/origin}} attribute initialized to |origin| and the {{MessageEvent/source}} attribute initialized to |source|, and then abort these steps.
@@ -2614,7 +2630,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26142630
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
26152631
1. Let |settingsObjects| be all [=environment settings objects=] whose [=environment settings object/origin=] is |registration|'s [=service worker registration/scope url=]'s origin.
26162632
1. For each |settingsObject| of |settingsObjects|, [=queue a task=] on |settingsObject|'s [=responsible event loop=] in the [=DOM manipulation task source=] to run the following steps:
2617-
1. Let |registrationObjects| be every {{ServiceWorkerRegistration}} object in |settingsObject|'s [=environment settings object/realm execution context=], whose [=ServiceWorkerRegistration/service worker registration=] is |registration|.
2633+
1. Let |registrationObjects| be every {{ServiceWorkerRegistration}} object in |settingsObject|'s [=environment settings object/realm=], whose [=ServiceWorkerRegistration/service worker registration=] is |registration|.
26182634
1. For each |registrationObject| of |registrationObjects|, [=fire an event=] on |registrationObject| named `updatefound`.
26192635
1. Let |installingWorker| be |registration|'s <a>installing worker</a>.
26202636
1. If the result of running the [=Should Skip Event=] algorithm with |installingWorker| and "install" is false, then:
@@ -3088,26 +3104,26 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
30883104

30893105
: Input
30903106
:: |registration|, a [=/service worker registration=]
3091-
:: |target|, a string (one of "<code>installing</code>", "<code>waiting</code>", and "<code>active</code>")
3107+
:: |target|, a string (one of "`installing`", "`waiting`", and "`active`")
30923108
:: |source|, a [=/service worker=] or null
30933109
: Output
30943110
:: None
30953111

30963112
1. Let |registrationObjects| be an array containing all the {{ServiceWorkerRegistration}} objects associated with |registration|.
3097-
1. If |target| is "<code>installing</code>", then:
3098-
1. Set |registration|'s <a>installing worker</a> to |source|.
3113+
1. If |target| is "`installing`", then:
3114+
1. Set |registration|'s [=installing worker=] to |source|.
30993115
1. For each |registrationObject| in |registrationObjects|:
3100-
1. <a>Queue a task</a> to set the {{ServiceWorkerRegistration/installing}} attribute of |registrationObject| to the {{ServiceWorker}} object that represents |registration|’s <a>installing worker</a>, or null if |registration|’s <a>installing worker</a> is null.
3101-
1. Else if |target| is "<code>waiting</code>", then:
3102-
1. Set |registration|'s <a>waiting worker</a> to |source|.
3116+
1. [=Queue a task=] to set the {{ServiceWorkerRegistration/installing}} attribute of |registrationObject| to null if |registration|’s [=installing worker=] is null, or the result of [=getting the service worker object=] that represents |registration|’s [=installing worker=] in |registrationObject|'s [=relevant settings object=].
3117+
1. Else if |target| is "`waiting`", then:
3118+
1. Set |registration|'s [=waiting worker=] to |source|.
31033119
1. For each |registrationObject| in |registrationObjects|:
3104-
1. <a>Queue a task</a> to set the {{ServiceWorkerRegistration/waiting}} attribute of |registrationObject| to the {{ServiceWorker}} object that represents |registration|’s <a>waiting worker</a>, or null if |registration|’s <a>waiting worker</a> is null.
3105-
1. Else if |target| is "<code>active</code>", then:
3120+
1. [=Queue a task=] to set the {{ServiceWorkerRegistration/waiting}} attribute of |registrationObject| to null if |registration|’s [=waiting worker=] is null, or the result of [=getting the service worker object=] that represents |registration|’s [=waiting worker=] in |registrationObject|'s [=relevant settings object=].
3121+
1. Else if |target| is "`active`", then:
31063122
1. Set |registration|'s [=service worker registration/active worker=] to |source|.
31073123
1. For each |registrationObject| in |registrationObjects|:
3108-
1. <a>Queue a task</a> to set the {{ServiceWorkerRegistration/active}} attribute of |registrationObject| to the {{ServiceWorker}} object that represents |registration|’s [=service worker registration/active worker=], or null if |registration|’s [=service worker registration/active worker=] is null.
3124+
1. [=Queue a task=] to set the {{ServiceWorkerRegistration/active}} attribute of |registrationObject| to null if |registration|’s [=active worker=] is null, or the result of [=getting the service worker object=] that represents |registration|’s [=active worker=] in |registrationObject|'s [=relevant settings object=].
31093125

3110-
The <a>task</a> *must* use |registrationObject|'s <a>relevant settings object</a>'s <a>responsible event loop</a> and the <a>DOM manipulation task source</a>.
3126+
The [=task=] *must* use |registrationObject|'s [=relevant settings object=]'s [=responsible event loop=] and the [=DOM manipulation task source=].
31113127
</section>
31123128

31133129
<section algorithm>

0 commit comments

Comments
 (0)