Skip to content

Commit d8e8e1c

Browse files
committed
Configure script's settings and realm for service workers
Service workers have a different script execution model from other workers. Update algorithm fetches a service worker script, and Run Service Worker algorithm runs the script when installing it and whenever functional events and message events need to be dispatched. This change: - Passes null as the value of script settings object/module map settings object argument to fetch a classic worker script/fetch a module worker script graph algorithm, respectively, called in Update algorithm, instead of the placeholder argument "the to-be-created environment settings object". - Sets the script's settings to the environment settings object created in Run Service Worker algorithm and the script's record.[[Realm]] to that settings object's Realm. Fixes #1013.
1 parent 0efd007 commit d8e8e1c

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

docs/index.bs

+7-5
Original file line numberDiff line numberDiff line change
@@ -2375,10 +2375,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
23752375
1. Let |updatedResourceMap| be an [=ordered map=] where the [=map/keys=] are [=/URLs=] and the [=map/values=] are [=/responses=].
23762376
1. Switching on |job|'s <a>worker type</a>, run these substeps with the following options:
23772377
<!-- TODO: reorganize algorithm so that the worker environment is created before fetching happens -->
2378-
: "<code>classic</code>"
2379-
:: <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.
2380-
: "<code>module</code>"
2381-
:: <a>Fetch a module worker script graph</a> given |job|’s <a lt="URL serializer">serialized</a> [=job/script url=], |job|’s [=job/client=], "<code>serviceworker</code>", "<code>omit</code>", and the to-be-created <a>environment settings object</a> for this service worker.
2378+
: "`classic`"
2379+
:: [=Fetch a classic worker script=] given |job|’s [=URL serializer|serialized=] [=job/script url=], |job|’s [=job/client=], "`serviceworker`", and null.
2380+
: "`module`"
2381+
:: [=Fetch a module worker script graph=] given |job|’s [=URL serializer|serialized=] [=job/script url=], |job|’s [=job/client=], "`serviceworker`", "`omit`", and null.
23822382

23832383
To [=fetching scripts/perform the fetch=] given |request|, run the following steps:
23842384

@@ -2608,9 +2608,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26082608
: Output
26092609
:: None
26102610

2611+
1. If |serviceWorker| is already running, abort these steps.
26112612
1. Let |script| be |serviceWorker|'s [=service worker/script resource=].
26122613
1. Assert: |script| is not null.
2613-
1. If |serviceWorker| is already running, abort these steps.
26142614
1. Create a separate parallel execution environment (i.e. a separate thread or process or equivalent construct), and run the rest of these steps in that context.
26152615
1. Call the JavaScript [=InitializeHostDefinedRealm|InitializeHostDefinedRealm()=] abstract operation with the following customizations:
26162616
* For the global object, create a new {{ServiceWorkerGlobalScope}} object. Let |workerGlobalScope| be the created object.
@@ -2645,6 +2645,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26452645
1. Set |workerGlobalScope|'s [=ServiceWorkerGlobalScope/force bypass cache for importscripts flag=] if the *force bypass cache for importscripts flag* is set.
26462646
1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|.
26472647
1. If |serviceWorker| is an <a>active worker</a>, and there are any <a>tasks</a> queued in |serviceWorker|'s <a>containing service worker registration</a>'s [=service worker registration/task queues=], <a lt="queue a task">queue</a> them to |serviceWorker|'s <a>event loop</a>'s [=/task queues=] in the same order using their original <a>task sources</a>.
2648+
1. Set |script|'s [=script/settings object=] to |settingsObject|.
2649+
1. Set |script|'s [=script/record=].\[[Realm]] to |settingsObject|'s [=environment settings object/Realm=].
26482650
1. If |script| is a <a>classic script</a>, then <a lt="run a classic script">run the classic script</a> |script|. Otherwise, it is a <a>module script</a>; <a lt="run a module script">run the module script</a> |script|.
26492651

26502652
Note: In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the <a>terminate service worker</a> algorithm.

docs/v1/index.bs

+7-5
Original file line numberDiff line numberDiff line change
@@ -2248,10 +2248,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
22482248
1. Let |updatedResourceMap| be an [=ordered map=] where the [=map/keys=] are [=/URLs=] and the [=map/values=] are [=/responses=].
22492249
1. Switching on |job|'s <a>worker type</a>, run these substeps with the following options:
22502250
<!-- TODO: reorganize algorithm so that the worker environment is created before fetching happens -->
2251-
: "<code>classic</code>"
2252-
:: <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.
2253-
: "<code>module</code>"
2254-
:: <a>Fetch a module worker script graph</a> given |job|’s <a lt="URL serializer">serialized</a> [=job/script url=], |job|’s [=job/client=], "<code>serviceworker</code>", "<code>omit</code>", and the to-be-created <a>environment settings object</a> for this service worker.
2251+
: "`classic`"
2252+
:: [=Fetch a classic worker script=] given |job|’s [=URL serializer|serialized=] [=job/script url=], |job|’s [=job/client=], "`serviceworker`", and null.
2253+
: "`module`"
2254+
:: [=Fetch a module worker script graph=] given |job|’s [=URL serializer|serialized=] [=job/script url=], |job|’s [=job/client=], "`serviceworker`", "`omit`", and null.
22552255

22562256
To [=fetching scripts/perform the fetch=] given |request|, run the following steps:
22572257

@@ -2481,9 +2481,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24812481
: Output
24822482
:: None
24832483

2484+
1. If |serviceWorker| is already running, abort these steps.
24842485
1. Let |script| be |serviceWorker|'s [=service worker/script resource=].
24852486
1. Assert: |script| is not null.
2486-
1. If |serviceWorker| is already running, abort these steps.
24872487
1. Create a separate parallel execution environment (i.e. a separate thread or process or equivalent construct), and run the rest of these steps in that context.
24882488
1. Call the JavaScript [=InitializeHostDefinedRealm|InitializeHostDefinedRealm()=] abstract operation with the following customizations:
24892489
* For the global object, create a new {{ServiceWorkerGlobalScope}} object. Let |workerGlobalScope| be the created object.
@@ -2518,6 +2518,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25182518
1. Set |workerGlobalScope|'s [=ServiceWorkerGlobalScope/force bypass cache for importscripts flag=] if the *force bypass cache for importscripts flag* is set.
25192519
1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|.
25202520
1. If |serviceWorker| is an <a>active worker</a>, and there are any <a>tasks</a> queued in |serviceWorker|'s <a>containing service worker registration</a>'s [=service worker registration/task queues=], <a lt="queue a task">queue</a> them to |serviceWorker|'s <a>event loop</a>'s [=/task queues=] in the same order using their original <a>task sources</a>.
2521+
1. Set |script|'s [=script/settings object=] to |settingsObject|.
2522+
1. Set |script|'s [=script/record=].\[[Realm]] to |settingsObject|'s [=environment settings object/Realm=].
25212523
1. If |script| is a <a>classic script</a>, then <a lt="run a classic script">run the classic script</a> |script|. Otherwise, it is a <a>module script</a>; <a lt="run a module script">run the module script</a> |script|.
25222524

25232525
Note: In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the <a>terminate service worker</a> algorithm.

0 commit comments

Comments
 (0)