Skip to content

Commit 037e4ff

Browse files
Making it easier to handle the state of extendable events (#1348)
* Making it easier to handle the state of extendable events * Updating v1
1 parent 307bb01 commit 037e4ff

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

docs/index.bs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,14 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12931293
};
12941294
</pre>
12951295

1296-
An {{ExtendableEvent}} object has an associated <dfn for="ExtendableEvent">extend lifetime promises</dfn> (an array of <a>promises</a>). It is initially an empty array.
1296+
An {{ExtendableEvent}} object has an associated <dfn export for="ExtendableEvent">extend lifetime promises</dfn> (an array of <a>promises</a>). It is initially an empty array.
12971297

12981298
An {{ExtendableEvent}} object has an associated <dfn for="ExtendableEvent">pending promises count</dfn> (the number of pending promises in the [=ExtendableEvent/extend lifetime promises=]). It is initially set to zero.
12991299

1300+
An {{ExtendableEvent}} object has an associated <dfn export for="ExtendableEvent">timed out flag</dfn>. It is initially unset, and is set after an optional user agent imposed delay if the [=ExtendableEvent/pending promises count=] is greater than zero.
1301+
1302+
An {{ExtendableEvent}} object is said to be <dfn export for="ExtendableEvent">active</dfn> when its [=ExtendableEvent/timed out flag=] is unset and either its [=ExtendableEvent/pending promises count=] is greater than zero or its [=dispatch flag=] is set.
1303+
13001304
[=/Service workers=] have two <a>lifecycle events</a>, {{install!!event}} and {{activate!!event}}. [=/Service workers=] use the {{ExtendableEvent}} interface for {{activate!!event}} event and {{install!!event}} event.
13011305

13021306
<a href="#extensibility">Service worker extensions</a> that <a href="#extension-to-service-worker-global-scope">define event handlers</a> *may* also use or extend the {{ExtendableEvent}} interface.
@@ -1310,7 +1314,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
13101314

13111315
1. If the {{Event/isTrusted}} attribute is false, [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
13121316

1313-
1. If the [=ExtendableEvent/pending promises count=] is zero and the [=dispatch flag=] is unset, [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
1317+
1. If not [=ExtendableEvent/active=], [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
13141318

13151319
Note: If no lifetime extension promise has been added in the task that called the event handlers, calling {{ExtendableEvent/waitUntil()}} in subsequent asynchronous tasks will throw.
13161320

@@ -1325,7 +1329,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
13251329
1. If |registration|'s [=uninstalling flag=] is set, invoke [=Try Clear Registration=] with |registration|.
13261330
1. If |registration| is not null, invoke [=Try Activate=] with |registration|.
13271331

1328-
The user agent *should not* <a lt="terminate service worker">terminate</a> the [=/service worker=] associated with |event|'s <a>relevant settings object</a>'s [=environment settings object/global object=] when |event|'s [=dispatch flag=] is set or |event|'s [=ExtendableEvent/pending promises count=] is not zero. However, the user agent *may* impose a time limit to this lifetime extension.
1332+
The user agent *should not* [=terminate service worker|terminate=] a [=/service worker=] if [=Service Worker Has No Pending Events=] returns false for that [=/service worker=].
13291333
</section>
13301334

13311335
[=/Service workers=] and <a href="#extensibility">extensions</a> that <a href="#extension-to-service-worker-global-scope">define event handlers</a> *may* define their own behaviors, allowing the [=ExtendableEvent/extend lifetime promises=] to suggest operation length, and the rejected state of any of the <a>promise</a> in [=ExtendableEvent/extend lifetime promises=] to suggest operation failure.
@@ -2536,8 +2540,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25362540
1. Initialize |e|’s {{Event/type}} attribute to {{install!!event}}.
25372541
1. <a>Dispatch</a> |e| at |installingWorker|'s [=service worker/global object=].
25382542
1. *WaitForAsynchronousExtensions*: Run the following substeps <a>in parallel</a>:
2539-
1. <span id="install-settle-step">Wait until |e|'s [=ExtendableEvent/pending promises count=] is zero.</span>
2540-
1. If the result of <a>waiting for all</a> of |e|'s <a>extend lifetime promises</a> rejected, set |installFailed| to true.
2543+
1. <span id="install-settle-step">Wait until |e| is not [=ExtendableEvent/active=].</span>
2544+
1. If |e|'s [=ExtendableEvent/timed out flag=] is set, or the result of [=waiting for all=] of |e|'s [=extend lifetime promises=] rejected, set |installFailed| to true.
25412545

25422546
If |task| is discarded or the script has been aborted by the <a lt="Terminate Service Worker">termination</a> of |installingWorker|, set |installFailed| to true.
25432547

@@ -2598,7 +2602,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25982602
1. Let |e| be the result of <a>creating an event</a> with {{ExtendableEvent}}.
25992603
1. Initialize |e|’s {{Event/type}} attribute to {{activate!!event}}.
26002604
1. <a>Dispatch</a> |e| at |activeWorker|'s [=service worker/global object=].
2601-
1. <span id="activate-settle-step">*WaitForAsynchronousExtensions*: Wait, [=in parallel=], until |e|'s [=ExtendableEvent/pending promises count=] is zero.</span>
2605+
1. <span id="activate-settle-step">*WaitForAsynchronousExtensions*: Wait, [=in parallel=], until |e| is not [=ExtendableEvent/active=].</span>
26022606
1. Wait for |task| to have executed or been discarded, or the script to have been aborted by the <a lt="terminate service worker">termination</a> of |activeWorker|.
26032607
1. Wait for the step labeled *WaitForAsynchronousExtensions* to complete.
26042608
1. Run the <a>Update Worker State</a> algorithm passing |registration|'s <a>active worker</a> and *activated* as the arguments.
@@ -2908,8 +2912,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
29082912

29092913
1. Assert: |event|'s [=dispatch flag=] is unset.
29102914
1. For each |item| of |worker|'s [=set of extended events=]:
2911-
1. If |item|'s [=pending promises count=] is zero, [=set/remove=] |item| from |worker|'s [=set of extended events=].
2912-
1. If |event|'s [=pending promises count=] is not zero, [=set/append=] |event| to |worker|'s [=set of extended events=].
2915+
1. If |item| is not [=ExtendableEvent/active=], [=set/remove=] |item| from |worker|'s [=set of extended events=].
2916+
1. If |event| is [=ExtendableEvent/active=], [=set/append=] |event| to |worker|'s [=set of extended events=].
29132917
</section>
29142918

29152919
<section algorithm>
@@ -3142,11 +3146,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31423146
: Output
31433147
:: True or false, a boolean
31443148

3145-
1. Let |sum| be zero.
3146-
1. For each |item| of |worker|'s [=set of extended events=]:
3147-
1. Add |item|'s [=pending promises count=] to |sum|.
3148-
1. If |sum| is zero, return true.
3149-
1. Else, return false.
3149+
1. For each |event| of |worker|'s [=set of extended events=]:
3150+
1. If |event| is [=ExtendableEvent/active=], return false.
3151+
1. Return true.
31503152
</section>
31513153

31523154
<section algorithm>

docs/v1/index.bs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,10 +1231,14 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12311231
};
12321232
</pre>
12331233

1234-
An {{ExtendableEvent}} object has an associated <dfn for="ExtendableEvent">extend lifetime promises</dfn> (an array of <a>promises</a>). It is initially an empty array.
1234+
An {{ExtendableEvent}} object has an associated <dfn export for="ExtendableEvent">extend lifetime promises</dfn> (an array of <a>promises</a>). It is initially an empty array.
12351235

12361236
An {{ExtendableEvent}} object has an associated <dfn for="ExtendableEvent">pending promises count</dfn> (the number of pending promises in the [=ExtendableEvent/extend lifetime promises=]). It is initially set to zero.
12371237

1238+
An {{ExtendableEvent}} object has an associated <dfn export for="ExtendableEvent">timed out flag</dfn>. It is initially unset, and is set after an optional user agent imposed delay if the [=ExtendableEvent/pending promises count=] is greater than zero.
1239+
1240+
An {{ExtendableEvent}} object is said to be <dfn export for="ExtendableEvent">active</dfn> when its [=ExtendableEvent/timed out flag=] is unset and either its [=ExtendableEvent/pending promises count=] is greater than zero or its [=dispatch flag=] is set.
1241+
12381242
[=/Service workers=] have two <a>lifecycle events</a>, {{install!!event}} and {{activate!!event}}. [=/Service workers=] use the {{ExtendableEvent}} interface for {{activate!!event}} event and {{install!!event}} event.
12391243

12401244
<a href="#extensibility">Service worker extensions</a> that <a href="#extension-to-service-worker-global-scope">define event handlers</a> *may* also use or extend the {{ExtendableEvent}} interface.
@@ -1248,7 +1252,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12481252

12491253
1. If the {{Event/isTrusted}} attribute is false, [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
12501254

1251-
1. If the [=ExtendableEvent/pending promises count=] is zero and the [=dispatch flag=] is unset, [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
1255+
1. If not [=ExtendableEvent/active=], [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
12521256

12531257
Note: If no lifetime extension promise has been added in the task that called the event handlers, calling {{ExtendableEvent/waitUntil()}} in subsequent asynchronous tasks will throw.
12541258

@@ -1263,7 +1267,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12631267
1. If |registration|'s [=uninstalling flag=] is set, invoke [=Try Clear Registration=] with |registration|.
12641268
1. If |registration| is not null, invoke [=Try Activate=] with |registration|.
12651269

1266-
The user agent *should not* <a lt="terminate service worker">terminate</a> the [=/service worker=] associated with |event|'s <a>relevant settings object</a>'s [=environment settings object/global object=] when |event|'s [=dispatch flag=] is set or |event|'s [=ExtendableEvent/pending promises count=] is not zero. However, the user agent *may* impose a time limit to this lifetime extension.
1270+
The user agent *should not* [=terminate service worker|terminate=] a [=/service worker=] if [=Service Worker Has No Pending Events=] returns false for that [=/service worker=].
12671271
</section>
12681272

12691273
[=/Service workers=] and <a href="#extensibility">extensions</a> that <a href="#extension-to-service-worker-global-scope">define event handlers</a> *may* define their own behaviors, allowing the [=ExtendableEvent/extend lifetime promises=] to suggest operation length, and the rejected state of any of the <a>promise</a> in [=ExtendableEvent/extend lifetime promises=] to suggest operation failure.
@@ -2408,8 +2412,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24082412
1. Initialize |e|’s {{Event/type}} attribute to {{install!!event}}.
24092413
1. <a>Dispatch</a> |e| at |installingWorker|'s [=service worker/global object=].
24102414
1. *WaitForAsynchronousExtensions*: Run the following substeps <a>in parallel</a>:
2411-
1. <span id="install-settle-step">Wait until |e|'s [=ExtendableEvent/pending promises count=] is zero.</span>
2412-
1. If the result of <a>waiting for all</a> of |e|'s <a>extend lifetime promises</a> rejected, set |installFailed| to true.
2415+
1. <span id="install-settle-step">Wait until |e| is not [=ExtendableEvent/active=].</span>
2416+
1. If |e|'s [=ExtendableEvent/timed out flag=] is set, or the result of [=waiting for all=] of |e|'s [=extend lifetime promises=] rejected, set |installFailed| to true.
24132417

24142418
If |task| is discarded or the script has been aborted by the <a lt="Terminate Service Worker">termination</a> of |installingWorker|, set |installFailed| to true.
24152419

@@ -2470,7 +2474,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24702474
1. Let |e| be the result of <a>creating an event</a> with {{ExtendableEvent}}.
24712475
1. Initialize |e|’s {{Event/type}} attribute to {{activate!!event}}.
24722476
1. <a>Dispatch</a> |e| at |activeWorker|'s [=service worker/global object=].
2473-
1. <span id="activate-settle-step">*WaitForAsynchronousExtensions*: Wait, [=in parallel=], until |e|'s [=ExtendableEvent/pending promises count=] is zero.</span>
2477+
1. <span id="activate-settle-step">*WaitForAsynchronousExtensions*: Wait, [=in parallel=], until |e| is not [=ExtendableEvent/active=].</span>
24742478
1. Wait for |task| to have executed or been discarded, or the script to have been aborted by the <a lt="terminate service worker">termination</a> of |activeWorker|.
24752479
1. Wait for the step labeled *WaitForAsynchronousExtensions* to complete.
24762480
1. Run the <a>Update Worker State</a> algorithm passing |registration|'s <a>active worker</a> and *activated* as the arguments.
@@ -2754,8 +2758,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
27542758

27552759
1. Assert: |event|'s [=dispatch flag=] is unset.
27562760
1. For each |item| of |worker|'s [=set of extended events=]:
2757-
1. If |item|'s [=pending promises count=] is zero, [=set/remove=] |item| from |worker|'s [=set of extended events=].
2758-
1. If |event|'s [=pending promises count=] is not zero, [=set/append=] |event| to |worker|'s [=set of extended events=].
2761+
1. If |item| is not [=ExtendableEvent/active=], [=set/remove=] |item| from |worker|'s [=set of extended events=].
2762+
1. If |event| is [=ExtendableEvent/active=], [=set/append=] |event| to |worker|'s [=set of extended events=].
27592763
</section>
27602764

27612765
<section algorithm>
@@ -2988,11 +2992,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
29882992
: Output
29892993
:: True or false, a boolean
29902994

2991-
1. Let |sum| be zero.
2992-
1. For each |item| of |worker|'s [=set of extended events=]:
2993-
1. Add |item|'s [=pending promises count=] to |sum|.
2994-
1. If |sum| is zero, return true.
2995-
1. Else, return false.
2995+
1. For each |event| of |worker|'s [=set of extended events=]:
2996+
1. If |event| is [=ExtendableEvent/active=], return false.
2997+
1. Return true.
29962998
</section>
29972999

29983000
<section algorithm>

0 commit comments

Comments
 (0)