Skip to content

Commit b6ac20c

Browse files
Allow the addRoutes() to be called during installing (#1744)
This is for addressing #1743. `InstallEvent.addRoutes()` is allowed to be called during installing, and the event wait until a promise returned by addRoutes() resolves. Additional change: - Update of the persistent data has been changed to follow how Chromium works. - fetch-event existence check has been moved inside the loop. It changed the rule verification order. - introduced parallel queue to clarify rules added by `addRoutes()` will be added in this order even if `addRoutes()` can be called in parallel.
1 parent 0c42aff commit b6ac20c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

docs/index.bs

+23-6
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
214214

215215
A [=/service worker=] is said to be <dfn>running</dfn> if its [=event loop=] is running.
216216

217+
A [=/service worker=] has an associated <dfn>[[service worker queue]]</dfn> (a [=parallel queue=]).
218+
217219
<section>
218220
<h4 id="service-worker-lifetime">Lifetime</h4>
219221

@@ -1607,16 +1609,31 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
16071609

16081610
The <dfn method for="InstallEvent"><code>addRoutes(|rules|)</code></dfn> method steps are:
16091611

1610-
1. Let |serviceWorker| be the [=current global object=]'s associated [=ServiceWorkerGlobalScope/service worker=].
1611-
1. Let |routerRules| be a copy of |serviceWorker|'s [=list of router rules=].
16121612
1. If |rules| is a {{RouterRule}} dictionary, set |rules| to &#x00AB; |rules| &#x00BB;.
1613+
1. Let |serviceWorker| be the [=current global object=]'s associated [=ServiceWorkerGlobalScope/service worker=].
16131614
1. For each |rule| of |rules|:
16141615
1. If running the [=Verify Router Condition=] algorithm with |rule|["{{RouterRule/condition}}"] and |serviceWorker| returns false, return [=a promise rejected with=] a {{TypeError}}.
1615-
1. Append |rule| to |routerRules|.
1616-
1. If |routerRules| [=list/contains=] a {{RouterRule}} whose {{RouterRule/source}} is either of "{{RouterSourceEnum/fetch-event}}" or "{{RouterSourceEnum/race-network-and-fetch-handler}}", and |serviceWorker|'s [=set of event types to handle=] does not [=set/contain=] {{ServiceWorkerGlobalScope/fetch!!event}}, return [=a promise rejected with=] a {{TypeError}}.
1617-
1. Set |serviceWorker|'s [=service worker/list of router rules=] to |routerRules|.
1618-
1. Return [=a promise resolved with=] undefined.
1616+
1. If |rule|["{{RouterRule/source}}"] is either of "{{RouterSourceEnum/fetch-event}}" or "{{RouterSourceEnum/race-network-and-fetch-handler}}", and |serviceWorker|'s [=set of event types to handle=] does not [=set/contain=] {{ServiceWorkerGlobalScope/fetch!!event}}, return [=a promise rejected with=] a {{TypeError}}.
1617+
1. Let |lifetimePromise| be a new [=promise=].
1618+
1. [=ExtendableEvent/Add lifetime promise=] |lifetimePromise| to [=this=].
1619+
1620+
Note: {{InstallEvent/addRoutes(rules)|event.addRoutes(rules)}} extends the lifetime of the event by default as if {{ExtendableEvent/waitUntil()|event.waitUntil(promise)}} is called.
1621+
1622+
1. Let |promise| be a new [=promise=].
1623+
1. Upon [=upon fulfillment|fulfillment=] or [=upon rejection|rejection=] of |promise|, resolve |lifetimePromise| with undefined.
16191624

1625+
Note: this step is for making |lifetimePromise| always fullfilled to avoid the install event failure.
1626+
1627+
1. [=queue/Enqueue=] the following steps to [=[[service worker queue]]=]:
1628+
1. Let |allRules| be a copy of |serviceWorker|'s [=list of router rules=].
1629+
1. For each |rule| of |rules|:
1630+
1. Append |rule| to |allRules|.
1631+
1632+
1. Set |serviceWorker|'s [=service worker/list of router rules=] to |allRules|.
1633+
1. Let |serviceWorkerEventLoop| be the [=current global object=]'s [=event loop=].
1634+
1. [=Queue a task=] to run the following steps on |serviceWorkerEventLoop| using the [=DOM manipulation task source=]:
1635+
1. Resolve |promise| with undefined.
1636+
1. Return |promise|.
16201637
</section>
16211638
</section>
16221639

0 commit comments

Comments
 (0)