From d8e8e1c40876158df91ad8e5a79de0cd5443f2cc Mon Sep 17 00:00:00 2001 From: Jungkee Song Date: Wed, 28 Mar 2018 17:36:41 +0900 Subject: [PATCH] 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. --- docs/index.bs | 12 +++++++----- docs/v1/index.bs | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/index.bs b/docs/index.bs index 58d63502..8e17d3a2 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -2375,10 +2375,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. Let |updatedResourceMap| be an [=ordered map=] where the [=map/keys=] are [=/URLs=] and the [=map/values=] are [=/responses=]. 1. Switching on |job|'s worker type, run these substeps with the following options: - : "classic" - :: Fetch a classic worker script given |job|’s serialized [=job/script url=], |job|’s [=job/client=], "serviceworker", and the to-be-created environment settings object for this service worker. - : "module" - :: Fetch a module worker script graph given |job|’s serialized [=job/script url=], |job|’s [=job/client=], "serviceworker", "omit", and the to-be-created environment settings object for this service worker. + : "`classic`" + :: [=Fetch a classic worker script=] given |job|’s [=URL serializer|serialized=] [=job/script url=], |job|’s [=job/client=], "`serviceworker`", and null. + : "`module`" + :: [=Fetch a module worker script graph=] given |job|’s [=URL serializer|serialized=] [=job/script url=], |job|’s [=job/client=], "`serviceworker`", "`omit`", and null. To [=fetching scripts/perform the fetch=] given |request|, run the following steps: @@ -2608,9 +2608,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe : Output :: None + 1. If |serviceWorker| is already running, abort these steps. 1. Let |script| be |serviceWorker|'s [=service worker/script resource=]. 1. Assert: |script| is not null. - 1. If |serviceWorker| is already running, abort these steps. 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. 1. Call the JavaScript [=InitializeHostDefinedRealm|InitializeHostDefinedRealm()=] abstract operation with the following customizations: * 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 1. Set |workerGlobalScope|'s [=ServiceWorkerGlobalScope/force bypass cache for importscripts flag=] if the *force bypass cache for importscripts flag* is set. 1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|. 1. If |serviceWorker| is an active worker, and there are any tasks queued in |serviceWorker|'s containing service worker registration's [=service worker registration/task queues=], queue them to |serviceWorker|'s event loop's [=/task queues=] in the same order using their original task sources. + 1. Set |script|'s [=script/settings object=] to |settingsObject|. + 1. Set |script|'s [=script/record=].\[[Realm]] to |settingsObject|'s [=environment settings object/Realm=]. 1. If |script| is a classic script, then run the classic script |script|. Otherwise, it is a module script; run the module script |script|. Note: In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the terminate service worker algorithm. diff --git a/docs/v1/index.bs b/docs/v1/index.bs index 8c51ab33..a49b7e85 100644 --- a/docs/v1/index.bs +++ b/docs/v1/index.bs @@ -2248,10 +2248,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. Let |updatedResourceMap| be an [=ordered map=] where the [=map/keys=] are [=/URLs=] and the [=map/values=] are [=/responses=]. 1. Switching on |job|'s worker type, run these substeps with the following options: - : "classic" - :: Fetch a classic worker script given |job|’s serialized [=job/script url=], |job|’s [=job/client=], "serviceworker", and the to-be-created environment settings object for this service worker. - : "module" - :: Fetch a module worker script graph given |job|’s serialized [=job/script url=], |job|’s [=job/client=], "serviceworker", "omit", and the to-be-created environment settings object for this service worker. + : "`classic`" + :: [=Fetch a classic worker script=] given |job|’s [=URL serializer|serialized=] [=job/script url=], |job|’s [=job/client=], "`serviceworker`", and null. + : "`module`" + :: [=Fetch a module worker script graph=] given |job|’s [=URL serializer|serialized=] [=job/script url=], |job|’s [=job/client=], "`serviceworker`", "`omit`", and null. To [=fetching scripts/perform the fetch=] given |request|, run the following steps: @@ -2481,9 +2481,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe : Output :: None + 1. If |serviceWorker| is already running, abort these steps. 1. Let |script| be |serviceWorker|'s [=service worker/script resource=]. 1. Assert: |script| is not null. - 1. If |serviceWorker| is already running, abort these steps. 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. 1. Call the JavaScript [=InitializeHostDefinedRealm|InitializeHostDefinedRealm()=] abstract operation with the following customizations: * 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 1. Set |workerGlobalScope|'s [=ServiceWorkerGlobalScope/force bypass cache for importscripts flag=] if the *force bypass cache for importscripts flag* is set. 1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|. 1. If |serviceWorker| is an active worker, and there are any tasks queued in |serviceWorker|'s containing service worker registration's [=service worker registration/task queues=], queue them to |serviceWorker|'s event loop's [=/task queues=] in the same order using their original task sources. + 1. Set |script|'s [=script/settings object=] to |settingsObject|. + 1. Set |script|'s [=script/record=].\[[Realm]] to |settingsObject|'s [=environment settings object/Realm=]. 1. If |script| is a classic script, then run the classic script |script|. Otherwise, it is a module script; run the module script |script|. Note: In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the terminate service worker algorithm.