You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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. Let |updatedResourceMap| be an [=ordered map=] where the [=map/keys=] are [=/URLs=] and the [=map/values=] are [=/responses=].
2376
2376
1. Switching on |job|'s <a>worker type</a>, run these substeps with the following options:
2377
2377
<!-- 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.
2382
2382
2383
2383
To [=fetching scripts/perform the fetch=] given |request|, run the following steps:
1. If |serviceWorker| is already running, abort these steps.
2611
2612
1. Let |script| be |serviceWorker|'s [=service worker/script resource=].
2612
2613
1. Assert: |script| is not null.
2613
-
1. If |serviceWorker| is already running, abort these steps.
2614
2614
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.
2615
2615
1. Call the JavaScript [=InitializeHostDefinedRealm|InitializeHostDefinedRealm()=] abstract operation with the following customizations:
2616
2616
* For the global object, create a new {{ServiceWorkerGlobalScope}} object. Let |workerGlobalScope| be the created object.
1. Set |workerGlobalScope|'s [=ServiceWorkerGlobalScope/force bypass cache for importscripts flag=] if the *force bypass cache for importscripts flag* is set.
2646
2646
1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|.
2647
2647
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=].
2648
2650
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|.
2649
2651
2650
2652
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.
1. Let |updatedResourceMap| be an [=ordered map=] where the [=map/keys=] are [=/URLs=] and the [=map/values=] are [=/responses=].
2249
2249
1. Switching on |job|'s <a>worker type</a>, run these substeps with the following options:
2250
2250
<!-- 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.
2255
2255
2256
2256
To [=fetching scripts/perform the fetch=] given |request|, run the following steps:
1. If |serviceWorker| is already running, abort these steps.
2484
2485
1. Let |script| be |serviceWorker|'s [=service worker/script resource=].
2485
2486
1. Assert: |script| is not null.
2486
-
1. If |serviceWorker| is already running, abort these steps.
2487
2487
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.
2488
2488
1. Call the JavaScript [=InitializeHostDefinedRealm|InitializeHostDefinedRealm()=] abstract operation with the following customizations:
2489
2489
* For the global object, create a new {{ServiceWorkerGlobalScope}} object. Let |workerGlobalScope| be the created object.
1. Set |workerGlobalScope|'s [=ServiceWorkerGlobalScope/force bypass cache for importscripts flag=] if the *force bypass cache for importscripts flag* is set.
2519
2519
1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|.
2520
2520
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=].
2521
2523
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|.
2522
2524
2523
2525
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