From 9111303ebc163b046d3f1ae6267a747ddfde2b64 Mon Sep 17 00:00:00 2001 From: Jungkee Song Date: Wed, 17 Feb 2016 20:06:49 +0900 Subject: [PATCH] Add worker modules Define service worker's type to support both classic mode and module mode. Integrate fetch a classic worker script/fetch a module script tree in html with set up the request/validate the response hooks customized for service worker. Update Run Service Worker to run the script depending on the script's type. Changes in HTML: https://github.com/whatwg/html/pull/746 --- spec/service_worker/index.bs | 207 ++++++++++++--------- spec/service_worker/index.html | 309 ++++++++++++++++++------------- spec/service_worker_1/index.html | 93 ++++++---- 3 files changed, 366 insertions(+), 243 deletions(-) diff --git a/spec/service_worker/index.bs b/spec/service_worker/index.bs index 305c1d43..291da208 100644 --- a/spec/service_worker/index.bs +++ b/spec/service_worker/index.bs @@ -187,19 +187,35 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/ urlPrefix: interaction.html text: has focus steps urlPrefix: webappapis.html + text: classic script text: creation url text: dom manipulation task source + text: fetch a classic worker script + text: fetch a module script tree text: fire a simple event + text: https state + text: module script + text: realm execution context text: report the error + text: run a classic script + text: run a module script + text: script text: task queue; for: event loop urlPrefix: workers.html text: get a fetch result + text: https state text: import scripts into worker global scope + text: kill a worker text: postprocess the fetch result text: runtime script errors handling; url: runtime-script-errors-2 text: shared workers + text: terminate a worker text: validate the state text: web worker; url: workers + for: workerglobalscope; urlPrefix: #concept-workerglobalscope- + text: https state + text: type + text: url type: event urlPrefix: indices.html text: DOMContentLoaded; for: Document; url: event-domcontentloaded @@ -278,10 +294,11 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

A service worker is a type of web worker. A service worker executes in the registering service worker client's origin.

A service worker has an associated state, which is one of parsed, installing, installed, activating, activated, and redundant. It is initially parsed.

A service worker has an associated script url (a URL).

+

A service worker has an associated type which is either "classic" or "module". Unless stated otherwise, it is "classic".

A service worker has an associated containing service worker registration (a service worker registration), which contains itself.

A service worker has an associated id (an opaque string), which uniquely identifies itself during the lifetime of its containing service worker registration.

A service worker is dispatched a set of lifecycle events, install and activate, and functional events including fetch.

-

A service worker has an associated script resource, which represents its own script resource. It is initially set to null. A script resource has an associated has ever been evaluated flag. It is initially unset.

+

A service worker has an associated script resource (a script), which represents its own script resource. It is initially set to null. A script resource has an associated has ever been evaluated flag. It is initially unset. A script resource has an associated HTTPS state which is "none", "deprecated", or "modern". Unless stated otherwise, it is "none".

A service worker has an associated script resource map which is a List of the Record {\[[key]], \[[value]]} where \[[key]] is a URL and \[[value]] is a script resource.

A service worker has an associated skip waiting flag. Unless stated otherwise it is unset.

A service worker has an associated imported scripts updated flag. It is initially unset.

@@ -717,6 +734,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
       dictionary RegistrationOptions {
         USVString scope;
+        WorkerType type = "classic";
       };
     
@@ -803,7 +821,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
  • If scopeURL is failure, reject p with a TypeError and abort these steps.
  • If scopeURL's scheme is not one of "http" and "https", reject p with a TypeError and abort these steps.
  • If any of the strings in scopeURL's path contains either ASCII case-insensitive "%2f" or ASCII case-insensitive "%5c", reject p with a TypeError and abort these steps.
  • -
  • Let job be the result of running Create Job with register, scopeURL, scriptURL, p, and client.
  • +
  • Let job be the result of running Create Job with register, scopeURL, scriptURL, options.type, p, and client.
  • Run the following substep in parallel:
    1. Invoke Schedule Job with job.
    2. @@ -2760,6 +2778,8 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

      A job has a script url (a URL).

      +

      A job has a worker type ("classic" or "module").

      +

      A job has a client (a service worker client). It is initially null.

      A job has a promise (a promise). It is initially null.

      @@ -2785,6 +2805,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
      jobType, a job type
      scopeURL, a URL
      scriptURL, a URL
      +
      workerExecutionType, "classic" or "module"
      promise, a promise
      client, a service worker client
      Output
      @@ -2795,6 +2816,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
    3. Set job's job type to jobType.
    4. Set job's scope url to scopeURL.
    5. Set job's script url to scriptURL.
    6. +
    7. Set job's worker type to workerExecutionType.
    8. Set job's promise to promise.
    9. Set job's client to client.
    10. Return job.
    11. @@ -3008,74 +3030,83 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
    12. Let newestWorker be the result of running Get Newest Worker algorithm passing registration as the argument.
    13. If job's job type is update, and newestWorker's script url is not job's script url, invoke Finish Job with job.
    14. -
    15. Let r be the associated request of the result of invoking the initial value of {{Request}} as constructor with job's serialized script url. If this throws an exception, then: -
        -
      1. Invoke Reject Job Promise with job and the exception.
      2. -
      3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
      4. -
      5. Invoke Finish Job with job and abort these steps.
      6. -
      -
    16. -
    17. Set r's initiator to "" and destination to "serviceworker".
    18. -
    19. Set r's client to job's client.
    20. -
    21. Append `Service-Worker`/`script` to r's header list. -

      See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.

      -
    22. -
    23. Set r's skip service worker flag, r's synchronous flag, and r's redirect mode to "manual".
    24. -
    25. If newestWorker is not null and registration's last update check time is not null, then: -
        -
      1. If the time difference in seconds calculated by the current time minus registration's last update check time is greater than 86400, or force bypass cache flag is set, set r's cache mode to "reload".
      2. -
      -

      Even if the cache mode is not set to "reload", the user agent obeys Cache-Control header's max-age value in the network layer to determine if it should bypass the browser cache.

      -
    26. -
    27. Let response be the result of running fetch using r.
    28. -
    29. If response is a network error or response's status is not in the range 200 to 299, then: -
        -
      1. Invoke Reject Job Promise with job and a TypeError.
      2. -
      3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
      4. -
      5. Invoke Finish Job with job and abort these steps.
      6. -
      -
    30. -
    31. Extract a MIME type from the response's header list. If this MIME type (ignoring parameters) is not one of text/javascript, application/x-javascript, and application/javascript, then: -
        -
      1. Invoke Reject Job Promise with job and a "{{SecurityError}}" exception.
      2. -
      3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
      4. -
      5. Invoke Finish Job with job and abort these steps.
      6. -
      -
    32. -
    33. Let serviceWorkerAllowed be the result of parsing `Service-Worker-Allowed` in response's header list. -

      See the definition of the Service-Worker-Allowed header in Appendix B: Extended HTTP headers.

      -
    34. -
    35. If serviceWorkerAllowed is failure, then: -
        -
      1. Invoke Reject Job Promise with job and a TypeError.
      2. -
      3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
      4. -
      5. Invoke Finish Job with job and abort these steps.
      6. -
      -
    36. -
    37. Let scopeURL be registration's scope url.
    38. -
    39. Let maxScopeString be null.
    40. -
    41. If serviceWorkerAllowed is null, then: +
    42. Switching on job's worker type, run these substeps with the following options: +
      +
      "classic"
      +

      Fetch a classic worker script given job’s serialized script url, job’s client, and "serviceworker".

      +
      "module"
      +

      Fetch a module script tree given job’s serialized script url, "omit", "serviceworker", and job’s client.

      +
      +

      To set up the request given request, run the following steps:

        -
      1. Set maxScopeString to "/" concatenated with the strings, except the last string that denotes the script's file name, in job's script url's path (including empty strings), separated from each other by "/".
      2. +
      3. Append `Service-Worker`/`script` to request's header list. +

        See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.

        +
      4. +
      5. Set request's skip service worker flag and request's redirect mode to "error".
      6. +
      7. If newestWorker is not null and registration's last update check time is not null, then: +
          +
        1. If the time difference in seconds calculated by the current time minus registration's last update check time is greater than 86400, or force bypass cache flag is set, set request's cache mode to "reload".
        2. +
        +

        Even if the cache mode is not set to "reload", the user agent obeys Cache-Control header's max-age value in the network layer to determine if it should bypass the browser cache.

        +
      -
    43. -
    44. Else: +

      To validate the response given response, run the following steps:

        -
      1. Let maxScope be the result of parsing serviceWorkerAllowed with job's script url.
      2. -
      3. Set maxScopeString to "/" concatenated with the strings in maxScope's path (including empty strings), separated from each other by "/".
      4. -
      -
    45. -
    46. Let scopeString be "/" concatenated with the strings in scopeURL's path (including empty strings), separated from each other by "/".
    47. -
    48. If scopeString starts with maxScopeString, do nothing.
    49. -
    50. Else: -
        -
      1. Invoke Reject Job Promise with job and a "{{SecurityError}}" exception.
      2. -
      3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
      4. -
      5. Invoke Finish Job with job and abort these steps.
      6. +
      7. If response's type is "error" or response's status is not an ok status, then: +
          +
        1. Invoke Reject Job Promise with job and a TypeError.
        2. +
        3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
        4. +
        5. Invoke Finish Job with job.
        6. +
        7. Return false and abort these steps.
        8. +
        +
      8. +
      9. Extract a MIME type from the response's header list. If this MIME type (ignoring parameters) is not one of text/javascript, application/x-javascript, and application/javascript, then: +
          +
        1. Invoke Reject Job Promise with job and a "{{SecurityError}}" exception.
        2. +
        3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
        4. +
        5. Invoke Finish Job with job.
        6. +
        7. Return false and abort these steps.
        8. +
        +
      10. +
      11. Let serviceWorkerAllowed be the result of parsing `Service-Worker-Allowed` in response's header list. +

        See the definition of the Service-Worker-Allowed header in Appendix B: Extended HTTP headers.

        +
      12. +
      13. If serviceWorkerAllowed is failure, then: +
          +
        1. Invoke Reject Job Promise with job and a TypeError.
        2. +
        3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
        4. +
        5. Invoke Finish Job with job.
        6. +
        7. Return false and abort these steps.
        8. +
        +
      14. +
      15. Let scopeURL be registration's scope url.
      16. +
      17. Let maxScopeString be null.
      18. +
      19. If serviceWorkerAllowed is null, then: +
          +
        1. Set maxScopeString to "/" concatenated with the strings, except the last string that denotes the script's file name, in job's script url's path (including empty strings), separated from each other by "/".
        2. +
        +
      20. +
      21. Else: +
          +
        1. Let maxScope be the result of parsing serviceWorkerAllowed with job's script url.
        2. +
        3. Set maxScopeString to "/" concatenated with the strings in maxScope's path (including empty strings), separated from each other by "/".
        4. +
        +
      22. +
      23. Let scopeString be "/" concatenated with the strings in scopeURL's path (including empty strings), separated from each other by "/".
      24. +
      25. If scopeString starts with maxScopeString, do nothing.
      26. +
      27. Else: +
          +
        1. Invoke Reject Job Promise with job and a "{{SecurityError}}" exception.
        2. +
        3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
        4. +
        5. Invoke Finish Job with job.
        6. +
        7. Return false and abort these steps.
        8. +
        +
      28. +
      29. If response's cache state is not "local", set registration's last update check time to the current time.
      30. +
      31. Return true.
    51. -
    52. If response's cache state is not "local", set registration's last update check time to the current time.
    53. -
    54. If newestWorker is not null, newestWorker's script url equals job's script url with the exclude fragments flag set, and response is a byte-for-byte match with the script resource of newestWorker, then: +
    55. If newestWorker is not null, newestWorker's script url equals job's script url with the exclude fragments flag set, and script is a byte-for-byte match with newestWorker's script resource, then:
      1. Invoke Resolve Job Promise with job and the {{ServiceWorkerRegistration}} object, setting its service worker client to job's client, which represents registration.
      2. Invoke Finish Job with job and abort these steps.
      3. @@ -3085,7 +3116,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
        1. Let worker be a new service worker.
        2. Generate a unique opaque string and set worker's id to the value.
        3. -
        4. Set worker's script url to job's script url, worker's script resource to the script resource retrieved from the fetched response.
        5. +
        6. Set worker's script url to job's script url, worker's script resource to script, and worker's type to job's worker type.
        7. Invoke Run Service Worker algorithm with worker as the argument.
        8. If an uncaught runtime script error occurs during the above step, then:
            @@ -3285,45 +3316,55 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
            None
              -
            1. Assert: serviceWorker has the script resource successfully fetched against its script url.
            2. +
            3. Let script be serviceWorker's script resource.
            4. +
            5. Assert: script is not null.
            6. If serviceWorker is already running, abort these steps.
            7. -
            8. Let workerGlobalScope be a new {{ServiceWorkerGlobalScope}} object.
            9. +
            10. 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.
            11. +
            12. Call the JavaScript InitializeHostDefinedRealm() abstract operation with the following customizations: +
                +
              • For the global object, create a new {{ServiceWorkerGlobalScope}} object. Let workerGlobalScope be the created object.
              • +
              • Let realmExecutionContext be the created JavaScript execution context.
              • +
              +
            13. Let workerEventLoop be a newly created event loop.
            14. -
            15. If serviceWorker is an active worker, and there are any tasks queued in serviceWorker's containing service worker registration's task queues, queue them to serviceWorker's event loop's task queues in the same order using their original task sources.
            16. +
            17. Let workerGlobalScope be realmExecutionContext's global object.
            18. Let settingsObject be a new environment settings object whose algorithms are defined as follows:
              -
              The script execution environments
              -
              When the environment settings object is created, for each language supported by the user agent, create an appropriate execution environment as defined by the relevant specification.
              -
              When a script execution environment is needed, return the appropriate one from those created when the environment settings object was created.
              +
              The realm execution context
              +
              Return realmExecutionContext.
              The global object
              Return workerGlobalScope.
              The responsible event loop
              Return workerEventLoop.
              The referrer source
              Return serviceWorker's script url.
              +

              Remove this definition after sorting out the referencing sites.

              The API URL character encoding
              Return UTF-8.
              The API base URL
              Return serviceWorker's script url.
              The origin and effective script origin
              Return its registering service worker client's origin.
              +
              The creation URL
              +
              Return workerGlobalScope's url.
              +
              The HTTPS state
              +
              Return workerGlobalScope's HTTPS state.
            19. -
            20. 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.
            21. -
            22. Let source be the result of running the UTF-8 decode algorithm on serviceWorker's script resource scriptResource.
            23. -
            24. Let language be JavaScript.
            25. -
            26. In the newly created execution environment, create a JavaScript global environment whose global object is workerGlobalScope. (The JavaScript global environment whose global object is a {{ServiceWorkerGlobalScope}} object is defined as the service worker environment, which is a type of worker environments.)
            27. -
            28. Let script be a new script.
            29. -
            30. Obtain the appropriate script execution environment for the scripting language language from settingsObject.
            31. -
            32. Parse/compile/initialize source using that script execution environment, as appropriate for language, and thus obtain a code entry-point. If the script was not compiled successfully, let the code entry-point be a no-op script, and act as if a corresponding uncaught script error had occurred.
            33. -
            34. Let script's settings object be settingsObject.
            35. -
            36. Jump to the script's code entry-point, and let that run until it either returns, fails to catch an exception, or gets aborted by the kill a worker or Terminate Service Worker algorithms.
            37. -
            38. If scriptResource's has ever been evaluated flag is unset, then: +
            39. Set workerGlobalScope's url to serviceWorker's script url.
            40. +
            41. Set workerGlobalScope's HTTPS state to serviceWorker's script resource's HTTPS state.
            42. +
            43. Set workerGlobalScope's type to serviceWorker's type.
            44. +
            45. Create a new {{WorkerLocation}} object and associate it with workerGlobalScope.
            46. +
            47. If serviceWorker is an active worker, and there are any tasks queued in serviceWorker's containing service worker registration's task queues, queue them to serviceWorker's event loop's task queues in the same order using their original task sources.
            48. +
            49. If script is a classic script, then run the classic script script. Otherwise, it is a module script; run the module script script. +

              In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the kill a worker or terminate a worker algorithms.

              +
            50. +
            51. If script's has ever been evaluated flag is unset, then:
              1. Set workerGlobalScope's associated service worker's set of event types to handle to the set of event types created from settingsObject's global object's associated list of event listeners' event types.

                If the global object's associated list of event listeners does not have any event listener added at this moment, the service worker's set of event types to handle is set to an empty set. The user agents are encouraged to show a warning that the event listeners must be added on the very first evaluation of the worker script.

              2. -
              3. Set scriptResource's has ever been evaluated flag.
              4. +
              5. Set script's has ever been evaluated flag.
            52. Run the responsible event loop specified by settingsObject until it is destroyed.
            53. diff --git a/spec/service_worker/index.html b/spec/service_worker/index.html index 7a9aaace..122bf8b5 100644 --- a/spec/service_worker/index.html +++ b/spec/service_worker/index.html @@ -1172,8 +1172,8 @@ a.self-link { position: absolute; top: 0; - left: calc(-1 * (3.5rem - 26px)); - width: calc(3.5rem - 26px); + left: -2.5em; + width: 2em; height: 2em; text-align: center; border: none; @@ -1186,6 +1186,9 @@ .heading > a.self-link { font-size: 83%; } + li > a.self-link { + left: -3.5em; + } dfn > a.self-link { top: auto; left: auto; @@ -1240,8 +1243,10 @@ .highlight .n { color: #0077aa } /* Name */ .highlight .o { color: #999999 } /* Operator */ .highlight .p { color: #999999 } /* Punctuation */ +.highlight .ch { color: #708090 } /* Comment.Hashbang */ .highlight .cm { color: #708090 } /* Comment.Multiline */ .highlight .cp { color: #708090 } /* Comment.Preproc */ +.highlight .cpf { color: #708090 } /* Comment.PreprocFile */ .highlight .c1 { color: #708090 } /* Comment.Single */ .highlight .cs { color: #708090 } /* Comment.Special */ .highlight .kc { color: #990055 } /* Keyword.Constant */ @@ -1294,7 +1299,7 @@

              Service Workers Nightly

              -

              Editor’s Draft,

              +

              Editor’s Draft,

              This version: @@ -1611,10 +1616,11 @@

              A service worker is a type of web worker. A service worker executes in the registering service worker client’s origin.

              A service worker has an associated state, which is one of parsed, installing, installed, activating, activated, and redundant. It is initially parsed.

              A service worker has an associated script url (a URL).

              +

              A service worker has an associated type which is either "classic" or "module". Unless stated otherwise, it is "classic".

              A service worker has an associated containing service worker registration (a service worker registration), which contains itself.

              A service worker has an associated id (an opaque string), which uniquely identifies itself during the lifetime of its containing service worker registration.

              A service worker is dispatched a set of lifecycle events, install and activate, and functional events including fetch.

              -

              A service worker has an associated script resource, which represents its own script resource. It is initially set to null. A script resource has an associated has ever been evaluated flag. It is initially unset.

              +

              A service worker has an associated script resource (a script), which represents its own script resource. It is initially set to null. A script resource has an associated has ever been evaluated flag. It is initially unset. A script resource has an associated HTTPS state which is "none", "deprecated", or "modern". Unless stated otherwise, it is "none".

              A service worker has an associated script resource map which is a List of the Record {[[key]], [[value]]} where [[key]] is a URL and [[value]] is a script resource.

              A service worker has an associated skip waiting flag. Unless stated otherwise it is unset.

              A service worker has an associated imported scripts updated flag. It is initially unset.

              @@ -1653,9 +1659,9 @@

              A service worker client has an associated active worker (an active worker) which currently controls it. It is initially set to null.

              A service worker client has an associated id (an opaque string), which uniquely identifies itself during its lifetime. It is initially set to a new unique value when the corresponding environment settings object that it represents is created.

              A service worker client has an associated frame type, which is one of auxiliary, top-level, nested, and none. Unless stated otherwise it is none.

              -

              A window client is a service worker client whose global object is a Window object.

              -

              A dedicated worker client is a service worker client whose global object is a DedicatedWorkerGlobalScope object.

              -

              A shared worker client is a service worker client whose global object is a SharedWorkerGlobalScope object.

              +

              A window client is a service worker client whose global object is a Window object.

              +

              A dedicated worker client is a service worker client whose global object is a DedicatedWorkerGlobalScope object.

              +

              A shared worker client is a service worker client whose global object is a SharedWorkerGlobalScope object.

              A worker client is either a dedicated worker client or a shared worker client.

              @@ -1796,7 +1802,7 @@

              <
            54. Create an event e that uses the ExtendableMessageEvent interface, with the event type message, which does not bubble, is not cancelable, and has no default action.
            55. Let the data attribute of e be initialized to clonedMessage.
            56. Let the origin attribute of e be initialized to the Unicode serialisation of the origin specified by the incumbent settings object. -
            57. If the global object globalObject specified by the incumbent settings object is a ServiceWorkerGlobalScope object, let the source attribute of e be initialized to a new ServiceWorker object that represents globalObject’s service worker. +
            58. If the global object globalObject specified by the incumbent settings object is a ServiceWorkerGlobalScope object, let the source attribute of e be initialized to a new ServiceWorker object that represents globalObject’s service worker.
            59. Else if globalObject is a Window object, let the source attribute of e be initialized to a new WindowClient object that represents globalObject’s browsing context.
            60. Else, let it be initialized to a new Client object that represents globalObject’s worker environment.
            61. Let the ports attribute of e be initialized to newPorts. @@ -1954,11 +1960,12 @@

              dictionary RegistrationOptions {
                 USVString scope;
              +  WorkerType type = "classic";
               };
               

              The user agent must create a ServiceWorkerContainer object when a Navigator object or a WorkerNavigator object is created and associate it with that object.

              A ServiceWorkerContainer provides capabilities to register, unregister, and update the service worker registrations, and provides access to the state of the service worker registrations and their associated service workers.

              -

              A ServiceWorkerContainer has an associated service worker client, which is a service worker client whose global object is associated with the Navigator object or the WorkerNavigator object that the ServiceWorkerContainer is retrieved from.

              +

              A ServiceWorkerContainer has an associated service worker client, which is a service worker client whose global object is associated with the Navigator object or the WorkerNavigator object that the ServiceWorkerContainer is retrieved from.

              A ServiceWorkerContainer object has an associated ready promise (a promise). It is initially set to a new promise.

              @@ -2023,7 +2030,7 @@

            62. @@ -2395,7 +2402,7 @@

              Create an event e that uses the ServiceWorkerMessageEvent interface, with the event type message, which does not bubble, is not cancelable, and has no default action.
            63. Let the data attribute of e be initialized to clonedMessage.
            64. Let the origin attribute of e be initialized to the Unicode serialisation of the origin specified by the incumbent settings object. -
            65. Let the source attribute of e be initialized to a ServiceWorker object, setting its service worker client to destination’s service worker client, which represents the service worker associated with the global object specified by the incumbent settings object. +
            66. Let the source attribute of e be initialized to a ServiceWorker object, setting its service worker client to destination’s service worker client, which represents the service worker associated with the global object specified by the incumbent settings object.
            67. Let the ports attribute of e be initialized to newPorts.
            68. Dispatch e at destination.
            @@ -2419,7 +2426,7 @@

            in parallel:
              -
            1. Let browsingContext be the context object’s associated service worker client’s global object’s browsing context. +
            2. Let browsingContext be the context object’s associated service worker client’s global object’s browsing context.
            3. Let visibilityState be null.
            4. Let focusState be null.
            5. @@ -2444,12 +2451,12 @@

              Let url be the result of parsing url with entry settings object’s API base URL.
            6. If url is failure, return a promise rejected with a TypeError.
            7. If url is about:blank, return a promise rejected with a TypeError. -
            8. If the context object’s associated service worker client’s active worker is not the incumbent settings object’s global object’s service worker, return a promise rejected with a TypeError. +
            9. If the context object’s associated service worker client’s active worker is not the incumbent settings object’s global object’s service worker, return a promise rejected with a TypeError.
            10. Let promise be a new promise.
            11. Run these substeps in parallel:
                -
              1. Let browsingContext be the context object’s associated service worker client’s global object’s browsing context. +
              2. Let browsingContext be the context object’s associated service worker client’s global object’s browsing context.
              3. If browsingContext has discarded its Document, reject promise with a TypeError and abort these steps.
              4. Let navigateFailed to false.
              5. Let visibilityState be null. @@ -2519,7 +2526,7 @@

                window client, then:
                  -
                1. Let browsingContext be client’s global object’s browsing context. +
                2. Let browsingContext be client’s global object’s browsing context.
                3. Let visibilityState be null.
                4. Let focusState be null.
                5. @@ -2576,7 +2583,7 @@

                  type is "window", and client is a window client, then:
                    -
                  1. Let browsingContext be client’s global object’s browsing context. +
                  2. Let browsingContext be client’s global object’s browsing context.
                  3. Let visibilityState be null.
                  4. Let focusState be null.
                  5. @@ -2603,7 +2610,7 @@

                    window client, then:
                      -
                    1. Let browsingContext be client’s global object’s browsing context. +
                    2. Let browsingContext be client’s global object’s browsing context.
                    3. Let visibilityState be null.
                    4. Let focusState be null.
                    5. @@ -2781,7 +2788,7 @@

                      scopes is empty throw a TypeError and abort these steps. -
                    6. Let scopeString be the incumbent settings object’s global object’s service worker’s containing service worker registration’s scope url, serialized. +
                    7. Let scopeString be the incumbent settings object’s global object’s service worker’s containing service worker registration’s scope url, serialized.
                    8. Let subScopeURLs be an empty list of URLs.
                    9. For each subScope in options.scopes: @@ -3407,12 +3414,12 @@

                      CacheStorage interface is designed to largely conform to ECMAScript 6 Map objects but entirely async, and with additional convenience methods. The methods, clear, forEach, entries and values, are intentionally excluded from the scope of the first version resorting to the ongoing discussion about the async iteration by TC39.

                      The user agent must create a CacheStorage object when a Window object or a WorkerGlobalScope object is created and associate it with that object.

                      -

                      A CacheStorage object represents a name to cache map of its associated global object’s environment settings object’s origin. Multiple separate objects implementing the CacheStorage interface across document environments and worker environments can all be associated with the same name to cache map simultaneously.

                      +

                      A CacheStorage object represents a name to cache map of its associated global object’s environment settings object’s origin. Multiple separate objects implementing the CacheStorage interface across document environments and worker environments can all be associated with the same name to cache map simultaneously.

                      5.5.1. match(request, options)

                      match(request, options) method must run these steps or their equivalent:

                        -
                      1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                      2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                      3. If options.cacheName is present, then:
                          @@ -3454,7 +3461,7 @@

                          5.5.2. has(cacheName)

                          has(cacheName) method must run these steps or their equivalent:

                            -
                          1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                          2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                          3. Return a promise p resolved with the result of running the following substeps:
                              @@ -3475,7 +3482,7 @@

                              5.5.3. open(cacheName)

                              open(cacheName) method must run these steps or their equivalent:

                                -
                              1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                              2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                              3. Let p be a new promise.
                              4. Run the following substeps: @@ -3501,7 +3508,7 @@

                                5.5.4. delete(cacheName)

                                delete(cacheName) method must run these steps or their equivalent:

                                  -
                                1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                                2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                                3. Let p be the result of running the algorithm specified in has(cacheName) method with cacheName as the argument.
                                4. Return the result of transforming p with a fulfillment handler that, when called with argument cacheExists, performs the following substeps in parallel: @@ -3527,7 +3534,7 @@

                                  keys() method must run these steps or their equivalent:

                                  The promise returned from this method resolves with the sequence of keys, cache names in DOMString, in insertion order.

                                    -
                                  1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                                  2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                                  3. Let resultArray be an empty array.
                                  4. Return a promise p resolved with the result of running the following substeps: @@ -3572,7 +3579,7 @@

                                    validate the state, the user agent must do nothing.

                                    To get a fetch result, the user agent must run the following steps:

                                      -
                                    1. Let serviceWorker be the settings object’s global object’s service worker. +
                                    2. Let serviceWorker be the settings object’s global object’s service worker.
                                    3. If serviceWorker’s imported scripts updated flag is unset, then:
                                        @@ -3673,6 +3680,7 @@

                                        Appendix A: Al

                                        A job has a job type, which is one of register, update, and unregister.

                                        A job has a scope url (a URL).

                                        A job has a script url (a URL).

                                        +

                                        A job has a worker type ("classic" or "module").

                                        A job has a client (a service worker client). It is initially null.

                                        A job has a promise (a promise). It is initially null.

                                        A job has a list of equivalent job promises (a list of promises). It is initially the empty list.

                                        @@ -3691,6 +3699,7 @@

                                        Crea
                                        jobType, a job type
                                        scopeURL, a URL
                                        scriptURL, a URL +
                                        workerExecutionType, "classic" or "module"
                                        promise, a promise
                                        client, a service worker client
                                        Output @@ -3701,6 +3710,7 @@

                                        Crea
                                      1. Set job’s job type to jobType.
                                      2. Set job’s scope url to scopeURL.
                                      3. Set job’s script url to scriptURL. +
                                      4. Set job’s worker type to workerExecutionType.
                                      5. Set job’s promise to promise.
                                      6. Set job’s client to client.
                                      7. Return job. @@ -3899,74 +3909,85 @@

                                        UpdateLet newestWorker be the result of running Get Newest Worker algorithm passing registration as the argument.
                                      8. If job’s job type is update, and newestWorker’s script url is not job’s script url, invoke Finish Job with job.
                                      9. - Let r be the associated request of the result of invoking the initial value of Request as constructor with job’s serialized script url. If this throws an exception, then: -
                                          -
                                        1. Invoke Reject Job Promise with job and the exception. -
                                        2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. -
                                        3. Invoke Finish Job with job and abort these steps. -
                                        -
                                      10. Set r’s initiator to "" and destination to "serviceworker". -
                                      11. Set r’s client to job’s client. -
                                      12. - Append `Service-Worker`/`script` to r’s header list. -

                                        See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.

                                        -
                                      13. Set r’s skip service worker flag, r’s synchronous flag, and r’s redirect mode to "manual". -
                                      14. - If newestWorker is not null and registration’s last update check time is not null, then: -
                                          -
                                        1. If the time difference in seconds calculated by the current time minus registration’s last update check time is greater than 86400, or force bypass cache flag is set, set r’s cache mode to "reload". -
                                        -

                                        Even if the cache mode is not set to "reload", the user agent obeys Cache-Control header’s max-age value in the network layer to determine if it should bypass the browser cache.

                                        -
                                      15. Let response be the result of running fetch using r. -
                                      16. - If response is a network error or response’s status is not in the range 200 to 299, then: -
                                          -
                                        1. Invoke Reject Job Promise with job and a TypeError. -
                                        2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. -
                                        3. Invoke Finish Job with job and abort these steps. -
                                        -
                                      17. - Extract a MIME type from the response’s header list. If this MIME type (ignoring parameters) is not one of text/javascript, application/x-javascript, and application/javascript, then: -
                                          -
                                        1. Invoke Reject Job Promise with job and a "SecurityError" exception. -
                                        2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. -
                                        3. Invoke Finish Job with job and abort these steps. -
                                        -
                                      18. - Let serviceWorkerAllowed be the result of parsing `Service-Worker-Allowed` in response’s header list. -

                                        See the definition of the Service-Worker-Allowed header in Appendix B: Extended HTTP headers.

                                        -
                                      19. - If serviceWorkerAllowed is failure, then: -
                                          -
                                        1. Invoke Reject Job Promise with job and a TypeError. -
                                        2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. -
                                        3. Invoke Finish Job with job and abort these steps. -
                                        -
                                      20. Let scopeURL be registration’s scope url. -
                                      21. Let maxScopeString be null. -
                                      22. - If serviceWorkerAllowed is null, then: -
                                          -
                                        1. Set maxScopeString to "/" concatenated with the strings, except the last string that denotes the script’s file name, in job’s script url’s path (including empty strings), separated from each other by "/". -
                                        -
                                      23. - Else: + Switching on job’s worker type, run these substeps with the following options: +
                                        +
                                        "classic" +
                                        +

                                        Fetch a classic worker script given job’s serialized script url, job’s client, and "serviceworker".

                                        +
                                        "module" +
                                        +

                                        Fetch a module script tree given job’s serialized script url, "omit", "serviceworker", and job’s client.

                                        +
                                        +

                                        To set up the request given request, run the following steps:

                                          -
                                        1. Let maxScope be the result of parsing serviceWorkerAllowed with job’s script url. -
                                        2. Set maxScopeString to "/" concatenated with the strings in maxScope’s path (including empty strings), separated from each other by "/". +
                                        3. + Append `Service-Worker`/`script` to request’s header list. +

                                          See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.

                                          +
                                        4. Set request’s skip service worker flag and request’s redirect mode to "error". +
                                        5. + If newestWorker is not null and registration’s last update check time is not null, then: +
                                            +
                                          1. If the time difference in seconds calculated by the current time minus registration’s last update check time is greater than 86400, or force bypass cache flag is set, set request’s cache mode to "reload". +
                                          +

                                          Even if the cache mode is not set to "reload", the user agent obeys Cache-Control header’s max-age value in the network layer to determine if it should bypass the browser cache.

                                        -
                                      24. Let scopeString be "/" concatenated with the strings in scopeURL’s path (including empty strings), separated from each other by "/". -
                                      25. If scopeString starts with maxScopeString, do nothing. -
                                      26. - Else: +

                                        To validate the response given response, run the following steps:

                                          -
                                        1. Invoke Reject Job Promise with job and a "SecurityError" exception. -
                                        2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. -
                                        3. Invoke Finish Job with job and abort these steps. +
                                        4. + If response’s type is "error" or response’s status is not an ok status, then: +
                                            +
                                          1. Invoke Reject Job Promise with job and a TypeError. +
                                          2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. +
                                          3. Invoke Finish Job with job. +
                                          4. Return false and abort these steps. +
                                          +
                                        5. + Extract a MIME type from the response’s header list. If this MIME type (ignoring parameters) is not one of text/javascript, application/x-javascript, and application/javascript, then: +
                                            +
                                          1. Invoke Reject Job Promise with job and a "SecurityError" exception. +
                                          2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. +
                                          3. Invoke Finish Job with job. +
                                          4. Return false and abort these steps. +
                                          +
                                        6. + Let serviceWorkerAllowed be the result of parsing `Service-Worker-Allowed` in response’s header list. +

                                          See the definition of the Service-Worker-Allowed header in Appendix B: Extended HTTP headers.

                                          +
                                        7. + If serviceWorkerAllowed is failure, then: +
                                            +
                                          1. Invoke Reject Job Promise with job and a TypeError. +
                                          2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. +
                                          3. Invoke Finish Job with job. +
                                          4. Return false and abort these steps. +
                                          +
                                        8. Let scopeURL be registration’s scope url. +
                                        9. Let maxScopeString be null. +
                                        10. + If serviceWorkerAllowed is null, then: +
                                            +
                                          1. Set maxScopeString to "/" concatenated with the strings, except the last string that denotes the script’s file name, in job’s script url’s path (including empty strings), separated from each other by "/". +
                                          +
                                        11. + Else: +
                                            +
                                          1. Let maxScope be the result of parsing serviceWorkerAllowed with job’s script url. +
                                          2. Set maxScopeString to "/" concatenated with the strings in maxScope’s path (including empty strings), separated from each other by "/". +
                                          +
                                        12. Let scopeString be "/" concatenated with the strings in scopeURL’s path (including empty strings), separated from each other by "/". +
                                        13. If scopeString starts with maxScopeString, do nothing. +
                                        14. + Else: +
                                            +
                                          1. Invoke Reject Job Promise with job and a "SecurityError" exception. +
                                          2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. +
                                          3. Invoke Finish Job with job. +
                                          4. Return false and abort these steps. +
                                          +
                                        15. If response’s cache state is not "local", set registration’s last update check time to the current time. +
                                        16. Return true.
                                        -
                                      27. If response’s cache state is not "local", set registration’s last update check time to the current time.
                                      28. - If newestWorker is not null, newestWorker’s script url equals job’s script url with the exclude fragments flag set, and response is a byte-for-byte match with the script resource of newestWorker, then: + If newestWorker is not null, newestWorker’s script url equals job’s script url with the exclude fragments flag set, and script is a byte-for-byte match with newestWorker’s script resource, then:
                                        1. Invoke Resolve Job Promise with job and the ServiceWorkerRegistration object, setting its service worker client to job’s client, which represents registration.
                                        2. Invoke Finish Job with job and abort these steps. @@ -3976,7 +3997,7 @@

                                          Update
                                        3. Let worker be a new service worker.
                                        4. Generate a unique opaque string and set worker’s id to the value. -
                                        5. Set worker’s script url to job’s script url, worker’s script resource to the script resource retrieved from the fetched response. +
                                        6. Set worker’s script url to job’s script url, worker’s script resource to script, and worker’s type to job’s worker type.
                                        7. Invoke Run Service Worker algorithm with worker as the argument.
                                        8. If an uncaught runtime script error occurs during the above step, then: @@ -4036,7 +4057,7 @@

                                          In Queue a task task to run the following substeps:
                                          1. Create a trusted event e that uses the InstallEvent interface, with the event type install, which does not bubble, is not cancelable, and has no default action. -
                                          2. Dispatch e at installingWorker’s environment settings object’s global object globalObject. +
                                          3. Dispatch e at installingWorker’s environment settings object’s global object globalObject.
                                          4. Let extendLifetimePromises be an empty array.
                                          5. For each event listener invoked: @@ -4126,7 +4147,7 @@

                                            Acti For each service worker client client whose creation url matches registration’s scope url:
                                            1. If client is a window client, unassociate client’s responsible document from its application cache, if it has one. -
                                            2. Else if client is a shared worker client, unassociate client’s global object from its application cache, if it has one. +
                                            3. Else if client is a shared worker client, unassociate client’s global object from its application cache, if it has one.

                                            Resources will now use the service worker registration instead of the existing application cache.

                                          6. @@ -4141,7 +4162,7 @@

                                            Acti Queue a task task to run the following substeps:
                                            1. Create a trusted event e that uses the ExtendableEvent interface, with the event type activate, which does not bubble, is not cancelable, and has no default action. -
                                            2. Dispatch e at activeWorker’s environment settings object’s global object. +
                                            3. Dispatch e at activeWorker’s environment settings object’s global object.
                                            4. Let extendLifetimePromises be an empty array.
                                            5. For each event listener invoked: @@ -4165,46 +4186,56 @@

                                              script url. +
                                            6. Let script be serviceWorker’s script resource. +
                                            7. Assert: script is not null.
                                            8. If serviceWorker is already running, abort these steps. -
                                            9. Let workerGlobalScope be a new ServiceWorkerGlobalScope object. +
                                            10. 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. +
                                            11. + Call the JavaScript InitializeHostDefinedRealm() abstract operation with the following customizations: +
                                            12. Let workerEventLoop be a newly created event loop. -
                                            13. If serviceWorker is an active worker, and there are any tasks queued in serviceWorker’s containing service worker registration’s task queues, queue them to serviceWorker’s event loop’s task queues in the same order using their original task sources. +
                                            14. Let workerGlobalScope be realmExecutionContext’s global object.
                                            15. Let settingsObject be a new environment settings object whose algorithms are defined as follows:
                                              -
                                              The script execution environments -
                                              When the environment settings object is created, for each language supported by the user agent, create an appropriate execution environment as defined by the relevant specification. -
                                              When a script execution environment is needed, return the appropriate one from those created when the environment settings object was created. -
                                              The global object +
                                              The realm execution context +
                                              Return realmExecutionContext. +
                                              The global object
                                              Return workerGlobalScope.
                                              The responsible event loop
                                              Return workerEventLoop.
                                              The referrer source
                                              Return serviceWorker’s script url. +

                                              Remove this definition after sorting out the referencing sites.

                                              The API URL character encoding
                                              Return UTF-8.
                                              The API base URL
                                              Return serviceWorker’s script url.
                                              The origin and effective script origin
                                              Return its registering service worker client’s origin. +
                                              The creation URL +
                                              Return workerGlobalScope’s url. +
                                              The HTTPS state +
                                              Return workerGlobalScope’s HTTPS state.
                                              -
                                            16. 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. -
                                            17. Let source be the result of running the UTF-8 decode algorithm on serviceWorker’s script resource scriptResource. -
                                            18. Let language be JavaScript. -
                                            19. In the newly created execution environment, create a JavaScript global environment whose global object is workerGlobalScope. (The JavaScript global environment whose global object is a ServiceWorkerGlobalScope object is defined as the service worker environment, which is a type of worker environments.) -
                                            20. Let script be a new script. -
                                            21. Obtain the appropriate script execution environment for the scripting language language from settingsObject. -
                                            22. Parse/compile/initialize source using that script execution environment, as appropriate for language, and thus obtain a code entry-point. If the script was not compiled successfully, let the code entry-point be a no-op script, and act as if a corresponding uncaught script error had occurred. -
                                            23. Let script’s settings object be settingsObject. -
                                            24. Jump to the script’s code entry-point, and let that run until it either returns, fails to catch an exception, or gets aborted by the kill a worker or Terminate Service Worker algorithms. +
                                            25. Set workerGlobalScope’s url to serviceWorker’s script url. +
                                            26. Set workerGlobalScope’s HTTPS state to serviceWorker’s script resource’s HTTPS state. +
                                            27. Set workerGlobalScope’s type to serviceWorker’s type. +
                                            28. Create a new WorkerLocation object and associate it with workerGlobalScope. +
                                            29. If serviceWorker is an active worker, and there are any tasks queued in serviceWorker’s containing service worker registration’s task queues, queue them to serviceWorker’s event loop’s task queues in the same order using their original task sources. +
                                            30. + If script is a classic script, then run the classic script script. Otherwise, it is a module script; run the module script script. +

                                              In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the kill a worker or terminate a worker algorithms.

                                            31. - If scriptResource’s has ever been evaluated flag is unset, then: + If script’s has ever been evaluated flag is unset, then:
                                              1. - Set workerGlobalScope’s associated service worker’s set of event types to handle to the set of event types created from settingsObject’s global object’s associated list of event listeners' event types. + Set workerGlobalScope’s associated service worker’s set of event types to handle to the set of event types created from settingsObject’s global object’s associated list of event listeners' event types.

                                                If the global object’s associated list of event listeners does not have any event listener added at this moment, the service worker’s set of event types to handle is set to an empty set. The user agents are encouraged to show a warning that the event listeners must be added on the very first evaluation of the worker script.

                                                -
                                              2. Set scriptResource’s has ever been evaluated flag. +
                                              3. Set script’s has ever been evaluated flag.
                                            32. Run the responsible event loop specified by settingsObject until it is destroyed.
                                            33. Empty workerGlobalScope’s list of active timers. @@ -4220,7 +4251,7 @@

                                              1. If serviceWorker is not running, abort these steps. -
                                              2. Let serviceWorkerGlobalScope be serviceWorker environment settings object’s global object. +
                                              3. Let serviceWorkerGlobalScope be serviceWorker environment settings object’s global object.
                                              4. Set serviceWorkerGlobalScope’s closing flag to true.
                                              5. If there are any tasks, whose task source is either the handle fetch task source or the handle functional event task source, queued in serviceWorkerGlobalScope’s event loop’s task queues, queue them to serviceWorker’s containing service worker registration’s corresponding task queues in the same order using their original task sources, and discard all the tasks (including tasks whose task source is neither the handle fetch task source nor the handle functional event task source) from serviceWorkerGlobalScope’s event loop’s task queues without processing them. @@ -4283,7 +4314,7 @@

                                                request attribute of e be initialized to r.
                                              6. Let the clientId attribute of e be initialized to client’s id if request is not a non-subresource request, and to null otherwise.
                                              7. Let the isReload attribute of e be initialized to true if request’s client is a window client and the event was dispatched with the user’s intention for the page reload, and false otherwise. -
                                              8. Dispatch e at activeWorker’s environment settings object’s global object. +
                                              9. Dispatch e at activeWorker’s environment settings object’s global object.
                                              10. For each event listener invoked:
                                                  @@ -4388,7 +4419,7 @@

                                                1. Create a trusted event e that uses the FetchEvent interface, with the event type foreignfetch, which does not bubble and has no default action.
                                                2. Let the request attribute of e be initialized to r. -
                                                3. Dispatch e at activeWorker’s environment settings object’s global object. +
                                                4. Dispatch e at activeWorker’s environment settings object’s global object.
                                                5. For each event listener invoked:
                                                    @@ -4484,7 +4515,7 @@

                                                    state is activating, wait for activeWorker’s state to become activated.
                                                  1. Invoke Run Service Worker algorithm with activeWorker as the argument.
                                                  2. - Queue a task task to invoke callbackSteps with activeWorker’s environment settings object’s global object as its argument. + Queue a task task to invoke callbackSteps with activeWorker’s environment settings object’s global object as its argument.

                                                    The task must use activeWorker’s event loop and the handle functional event task source.

                                                  3. Wait for task to have executed or been discarded.
                                                  4. If the time difference in seconds calculated by the current time minus registration’s last update check time is greater than 86400, invoke Soft Update algorithm, or its equivalent, with registration. @@ -5113,6 +5144,7 @@

                                                    handle functional event task source, in §2.5
                                                  5. has(cacheName), in §5.5.2
                                                  6. has ever been evaluated flag, in §2.1 +
                                                  7. HTTPS state, in §2.1
                                                  8. id
                                                  9. ServiceWorkerContainer, in §3.4 -
                                                  10. service worker environment, in §Unnumbered section
                                                  11. ServiceWorkerGlobalScope, in §4.1
                                                  12. ServiceWorkerMessageEvent, in §3.5
                                                  13. ServiceWorkerMessageEventInit, in §3.5 @@ -5335,6 +5366,8 @@

                                                    type @@ -5353,6 +5386,7 @@

                                                    window client, in §2.3
                                                  14. WindowClient, in §4.2
                                                  15. worker client, in §2.3 +
                                                  16. worker type, in §Unnumbered section

                                                    Terms defined by reference

                                                    @@ -5687,6 +5730,7 @@

                                                    IDL Inde dictionary RegistrationOptions { USVString scope; + WorkerType type = "classic"; }; [Constructor(DOMString type, optional ServiceWorkerMessageEventInit eventInitDict), Exposed=(Window,Worker)] @@ -5863,9 +5907,26 @@

                                                    IDL Inde [NewObject] Promise<sequence<DOMString>> keys(); }; +partial interface ServiceWorkerRegistration { + // e.g. define an API namespace + readonly attribute APISpaceType APISpace; + // e.g. define a method + Promise<T> methodName(list of arguments); +}; + +// e.g. define FunctionalEvent interface +interface FunctionalEvent : ExtendableEvent { + // add a functional event’s own attributes and methods +}; + +partial interface ServiceWorkerGlobalScope { + attribute EventHandler onfunctionalevent; +}; +

                                                    Issues Index

                                                    The behavior of the attribute getter in non-secure contexts is in discussion.
                                                    +
                                                    Remove this definition after sorting out the referencing sites.
                                                    This needs an extra step in the HTTP fetch algorithm in between step 3 and 4, to call this algorithm for all requests if response is null at that point.
                                                    \ No newline at end of file diff --git a/spec/service_worker_1/index.html b/spec/service_worker_1/index.html index 3f516ec4..7891c2da 100644 --- a/spec/service_worker_1/index.html +++ b/spec/service_worker_1/index.html @@ -1172,8 +1172,8 @@ a.self-link { position: absolute; top: 0; - left: calc(-1 * (3.5rem - 26px)); - width: calc(3.5rem - 26px); + left: -2.5em; + width: 2em; height: 2em; text-align: center; border: none; @@ -1186,6 +1186,9 @@ .heading > a.self-link { font-size: 83%; } + li > a.self-link { + left: -3.5em; + } dfn > a.self-link { top: auto; left: auto; @@ -1240,8 +1243,10 @@ .highlight .n { color: #0077aa } /* Name */ .highlight .o { color: #999999 } /* Operator */ .highlight .p { color: #999999 } /* Punctuation */ +.highlight .ch { color: #708090 } /* Comment.Hashbang */ .highlight .cm { color: #708090 } /* Comment.Multiline */ .highlight .cp { color: #708090 } /* Comment.Preproc */ +.highlight .cpf { color: #708090 } /* Comment.PreprocFile */ .highlight .c1 { color: #708090 } /* Comment.Single */ .highlight .cs { color: #708090 } /* Comment.Special */ .highlight .kc { color: #990055 } /* Keyword.Constant */ @@ -1294,7 +1299,7 @@

                                                    Service Workers 1

                                                    -

                                                    Editor’s Draft,

                                                    +

                                                    Editor’s Draft,

                                                    This version: @@ -1644,9 +1649,9 @@

                                                    A service worker client has an associated active worker (an active worker) which currently controls it. It is initially set to null.

                                                    A service worker client has an associated id (an opaque string), which uniquely identifies itself during its lifetime. It is initially set to a new unique value when the corresponding environment settings object that it represents is created.

                                                    A service worker client has an associated frame type, which is one of auxiliary, top-level, nested, and none. Unless stated otherwise it is none.

                                                    -

                                                    A window client is a service worker client whose global object is a Window object.

                                                    -

                                                    A dedicated worker client is a service worker client whose global object is a DedicatedWorkerGlobalScope object.

                                                    -

                                                    A shared worker client is a service worker client whose global object is a SharedWorkerGlobalScope object.

                                                    +

                                                    A window client is a service worker client whose global object is a Window object.

                                                    +

                                                    A dedicated worker client is a service worker client whose global object is a DedicatedWorkerGlobalScope object.

                                                    +

                                                    A shared worker client is a service worker client whose global object is a SharedWorkerGlobalScope object.

                                                    A worker client is either a dedicated worker client or a shared worker client.

                      @@ -1787,7 +1792,7 @@

                      <
                    10. Create an event e that uses the ExtendableMessageEvent interface, with the event type message, which does not bubble, is not cancelable, and has no default action.
                    11. Let the data attribute of e be initialized to clonedMessage.
                    12. Let the origin attribute of e be initialized to the Unicode serialisation of the origin specified by the incumbent settings object. -
                    13. If the global object globalObject specified by the incumbent settings object is a ServiceWorkerGlobalScope object, let the source attribute of e be initialized to a new ServiceWorker object that represents globalObject’s service worker. +
                    14. If the global object globalObject specified by the incumbent settings object is a ServiceWorkerGlobalScope object, let the source attribute of e be initialized to a new ServiceWorker object that represents globalObject’s service worker.
                    15. Else if globalObject is a Window object, let the source attribute of e be initialized to a new WindowClient object that represents globalObject’s browsing context.
                    16. Else, let it be initialized to a new Client object that represents globalObject’s worker environment.
                    17. Let the ports attribute of e be initialized to newPorts. @@ -1949,7 +1954,7 @@

                      The user agent must create a ServiceWorkerContainer object when a Navigator object or a WorkerNavigator object is created and associate it with that object.

                      A ServiceWorkerContainer provides capabilities to register, unregister, and update the service worker registrations, and provides access to the state of the service worker registrations and their associated service workers.

                      -

                      A ServiceWorkerContainer has an associated service worker client, which is a service worker client whose global object is associated with the Navigator object or the WorkerNavigator object that the ServiceWorkerContainer is retrieved from.

                      +

                      A ServiceWorkerContainer has an associated service worker client, which is a service worker client whose global object is associated with the Navigator object or the WorkerNavigator object that the ServiceWorkerContainer is retrieved from.

                      A ServiceWorkerContainer object has an associated ready promise (a promise). It is initially set to a new promise.

                      @@ -2337,15 +2342,15 @@

                      auxiliary
                      "auxiliary" -

                      The window client’s global object’s browsing context is an auxiliary browsing context.

                      +

                      The window client’s global object’s browsing context is an auxiliary browsing context.

                      top-level
                      "top-level" -

                      The window client’s global object’s browsing context is a top-level browsing context.

                      +

                      The window client’s global object’s browsing context is a top-level browsing context.

                      nested
                      "nested" -

                      The window client’s global object’s browsing context is a nested browsing context.

                      +

                      The window client’s global object’s browsing context is a nested browsing context.

                      none
                      "none" @@ -2382,7 +2387,7 @@

                      Create an event e that uses the ServiceWorkerMessageEvent interface, with the event type message, which does not bubble, is not cancelable, and has no default action.
                    18. Let the data attribute of e be initialized to clonedMessage.
                    19. Let the origin attribute of e be initialized to the Unicode serialisation of the origin specified by the incumbent settings object. -
                    20. Let the source attribute of e be initialized to a ServiceWorker object, setting its service worker client to destination’s service worker client, which represents the service worker associated with the global object specified by the incumbent settings object. +
                    21. Let the source attribute of e be initialized to a ServiceWorker object, setting its service worker client to destination’s service worker client, which represents the service worker associated with the global object specified by the incumbent settings object.
                    22. Let the ports attribute of e be initialized to newPorts.
                    23. Dispatch e at destination.
                    @@ -2406,7 +2411,7 @@

                    in parallel:
                      -
                    1. Let browsingContext be the context object’s associated service worker client’s global object’s browsing context. +
                    2. Let browsingContext be the context object’s associated service worker client’s global object’s browsing context.
                    3. Let visibilityState be null.
                    4. Let focusState be null.
                    5. @@ -2431,12 +2436,12 @@

                      Let url be the result of parsing url with entry settings object’s API base URL.
                    6. If url is failure, return a promise rejected with a TypeError.
                    7. If url is about:blank, return a promise rejected with a TypeError. -
                    8. If the context object’s associated service worker client’s active worker is not the incumbent settings object’s global object’s service worker, return a promise rejected with a TypeError. +
                    9. If the context object’s associated service worker client’s active worker is not the incumbent settings object’s global object’s service worker, return a promise rejected with a TypeError.
                    10. Let promise be a new promise.
                    11. Run these substeps in parallel:
                        -
                      1. Let browsingContext be the context object’s associated service worker client’s global object’s browsing context. +
                      2. Let browsingContext be the context object’s associated service worker client’s global object’s browsing context.
                      3. If browsingContext has discarded its Document, reject promise with a TypeError and abort these steps.
                      4. Let navigateFailed to false.
                      5. Let visibilityState be null. @@ -2506,7 +2511,7 @@

                        window client, then:
                          -
                        1. Let browsingContext be client’s global object’s browsing context. +
                        2. Let browsingContext be client’s global object’s browsing context.
                        3. Let visibilityState be null.
                        4. Let focusState be null.
                        5. @@ -2563,7 +2568,7 @@

                          type is "window", and client is a window client, then:
                            -
                          1. Let browsingContext be client’s global object’s browsing context. +
                          2. Let browsingContext be client’s global object’s browsing context.
                          3. Let visibilityState be null.
                          4. Let focusState be null.
                          5. @@ -2590,7 +2595,7 @@

                            window client, then:
                              -
                            1. Let browsingContext be client’s global object’s browsing context. +
                            2. Let browsingContext be client’s global object’s browsing context.
                            3. Let visibilityState be null.
                            4. Let focusState be null.
                            5. @@ -3338,12 +3343,12 @@

                              CacheStorage interface is designed to largely conform to ECMAScript 6 Map objects but entirely async, and with additional convenience methods. The methods, clear, forEach, entries and values, are intentionally excluded from the scope of the first version resorting to the ongoing discussion about the async iteration by TC39.

                              The user agent must create a CacheStorage object when a Window object or a WorkerGlobalScope object is created and associate it with that object.

                              -

                              A CacheStorage object represents a name to cache map of its associated global object’s environment settings object’s origin. Multiple separate objects implementing the CacheStorage interface across document environments and worker environments can all be associated with the same name to cache map simultaneously.

                              +

                              A CacheStorage object represents a name to cache map of its associated global object’s environment settings object’s origin. Multiple separate objects implementing the CacheStorage interface across document environments and worker environments can all be associated with the same name to cache map simultaneously.

                              5.5.1. match(request, options)

                              match(request, options) method must run these steps or their equivalent:

                                -
                              1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                              2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                              3. If options.cacheName is present, then:
                                  @@ -3385,7 +3390,7 @@

                                  5.5.2. has(cacheName)

                                  has(cacheName) method must run these steps or their equivalent:

                                    -
                                  1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                                  2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                                  3. Return a promise p resolved with the result of running the following substeps:
                                      @@ -3406,7 +3411,7 @@

                                      5.5.3. open(cacheName)

                                      open(cacheName) method must run these steps or their equivalent:

                                        -
                                      1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                                      2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                                      3. Let p be a new promise.
                                      4. Run the following substeps: @@ -3432,7 +3437,7 @@

                                        5.5.4. delete(cacheName)

                                        delete(cacheName) method must run these steps or their equivalent:

                                          -
                                        1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                                        2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                                        3. Let p be the result of running the algorithm specified in has(cacheName) method with cacheName as the argument.
                                        4. Return the result of transforming p with a fulfillment handler that, when called with argument cacheExists, performs the following substeps in parallel: @@ -3458,7 +3463,7 @@

                                          keys() method must run these steps or their equivalent:

                                          The promise returned from this method resolves with the sequence of keys, cache names in DOMString, in insertion order.

                                            -
                                          1. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception. +
                                          2. If the context object’s associated global object’s environment settings object is not a secure context, return a promise rejected with a "SecurityError" exception.
                                          3. Let resultArray be an empty array.
                                          4. Return a promise p resolved with the result of running the following substeps: @@ -3503,7 +3508,7 @@

                                            validate the state, the user agent must do nothing.

                                            To get a fetch result, the user agent must run the following steps:

                                              -
                                            1. Let serviceWorker be the settings object’s global object’s service worker. +
                                            2. Let serviceWorker be the settings object’s global object’s service worker.
                                            3. If serviceWorker’s imported scripts updated flag is unset, then:
                                                @@ -3967,7 +3972,7 @@

                                                In Queue a task task to run the following substeps:
                                                1. Create a trusted event e that uses the ExtendableEvent interface, with the event type install, which does not bubble, is not cancelable, and has no default action. -
                                                2. Dispatch e at installingWorker’s environment settings object’s global object globalObject. +
                                                3. Dispatch e at installingWorker’s environment settings object’s global object globalObject.
                                                4. Let extendLifetimePromises be an empty array.
                                                5. For each event listener invoked: @@ -4057,7 +4062,7 @@

                                                  Acti For each service worker client client whose creation url matches registration’s scope url:
                                                  1. If client is a window client, unassociate client’s responsible document from its application cache, if it has one. -
                                                  2. Else if client is a shared worker client, unassociate client’s global object from its application cache, if it has one. +
                                                  3. Else if client is a shared worker client, unassociate client’s global object from its application cache, if it has one.

                                                  Resources will now use the service worker registration instead of the existing application cache.

                                                6. @@ -4072,7 +4077,7 @@

                                                  Acti Queue a task task to run the following substeps:
                                                  1. Create a trusted event e that uses the ExtendableEvent interface, with the event type activate, which does not bubble, is not cancelable, and has no default action. -
                                                  2. Dispatch e at activeWorker’s environment settings object’s global object. +
                                                  3. Dispatch e at activeWorker’s environment settings object’s global object.
                                                  4. Let extendLifetimePromises be an empty array.
                                                  5. For each event listener invoked: @@ -4107,7 +4112,7 @@

                                                    script execution environments
                                                    When the environment settings object is created, for each language supported by the user agent, create an appropriate execution environment as defined by the relevant specification.
                                                    When a script execution environment is needed, return the appropriate one from those created when the environment settings object was created. -
                                                    The global object +
                                                    The global object
                                                    Return workerGlobalScope.
                                                    The responsible event loop
                                                    Return workerEventLoop. @@ -4124,7 +4129,7 @@

                                                    UTF-8 decode algorithm on serviceWorker’s script resource scriptResource.
                                                  6. Let language be JavaScript.
                                                  7. In the newly created execution environment, create a JavaScript global environment whose global object is workerGlobalScope. (The JavaScript global environment whose global object is a ServiceWorkerGlobalScope object is defined as the service worker environment, which is a type of worker environments.) -
                                                  8. Let script be a new script. +
                                                  9. Let script be a new script.
                                                  10. Obtain the appropriate script execution environment for the scripting language language from settingsObject.
                                                  11. Parse/compile/initialize source using that script execution environment, as appropriate for language, and thus obtain a code entry-point. If the script was not compiled successfully, let the code entry-point be a no-op script, and act as if a corresponding uncaught script error had occurred.
                                                  12. Let script’s settings object be settingsObject. @@ -4133,7 +4138,7 @@

                                                    has ever been evaluated flag is unset, then:
                                                    1. - Set workerGlobalScope’s associated service worker’s set of event types to handle to the set of event types created from settingsObject’s global object’s associated list of event listeners' event types. + Set workerGlobalScope’s associated service worker’s set of event types to handle to the set of event types created from settingsObject’s global object’s associated list of event listeners' event types.

                                                      If the global object’s associated list of event listeners does not have any event listener added at this moment, the service worker’s set of event types to handle is set to an empty set. The user agents are encouraged to show a warning that the event listeners must be added on the very first evaluation of the worker script.

                                                    2. Set scriptResource’s has ever been evaluated flag.
                                                    @@ -4151,7 +4156,7 @@

                                                    1. If serviceWorker is not running, abort these steps. -
                                                    2. Let serviceWorkerGlobalScope be serviceWorker environment settings object’s global object. +
                                                    3. Let serviceWorkerGlobalScope be serviceWorker environment settings object’s global object.
                                                    4. Set serviceWorkerGlobalScope’s closing flag to true.
                                                    5. If there are any tasks, whose task source is either the handle fetch task source or the handle functional event task source, queued in serviceWorkerGlobalScope’s event loop’s task queues, queue them to serviceWorker’s containing service worker registration’s corresponding task queues in the same order using their original task sources, and discard all the tasks (including tasks whose task source is neither the handle fetch task source nor the handle functional event task source) from serviceWorkerGlobalScope’s event loop’s task queues without processing them. @@ -4214,7 +4219,7 @@

                                                      request attribute of e be initialized to r.
                                                    6. Let the clientId attribute of e be initialized to client’s id if request is not a non-subresource request, and to null otherwise.
                                                    7. Let the isReload attribute of e be initialized to true if request’s client is a window client and the event was dispatched with the user’s intention for the page reload, and false otherwise. -
                                                    8. Dispatch e at activeWorker’s environment settings object’s global object. +
                                                    9. Dispatch e at activeWorker’s environment settings object’s global object.
                                                    10. For each event listener invoked:
                                                        @@ -4297,7 +4302,7 @@

                                                        state is activating, wait for activeWorker’s state to become activated.
                                                      1. Invoke Run Service Worker algorithm with activeWorker as the argument.
                                                      2. - Queue a task task to invoke callbackSteps with activeWorker’s environment settings object’s global object as its argument. + Queue a task task to invoke callbackSteps with activeWorker’s environment settings object’s global object as its argument.

                                                        The task must use activeWorker’s event loop and the handle functional event task source.

                                                      3. Wait for task to have executed or been discarded.
                                                      4. If the time difference in seconds calculated by the current time minus registration’s last update check time is greater than 86400, invoke Soft Update algorithm, or its equivalent, with registration. @@ -5254,7 +5259,7 @@

                                                        fire a simple event
                                                      5. focusing steps
                                                      6. get a fetch result -
                                                      7. global object +
                                                      8. global object
                                                      9. has focus steps
                                                      10. import scripts into worker global scope
                                                      11. importScripts(urls) @@ -5278,7 +5283,7 @@

                                                        responsible event loop
                                                      12. runtime script errors handling
                                                      13. same origin -
                                                      14. script +
                                                      15. script
                                                      16. settings object
                                                      17. shared workers
                                                      18. source browsing context @@ -5630,6 +5635,22 @@

                                                        IDL Inde [NewObject] Promise<sequence<DOMString>> keys(); }; +partial interface ServiceWorkerRegistration { + // e.g. define an API namespace + readonly attribute APISpaceType APISpace; + // e.g. define a method + Promise<T> methodName(list of arguments); +}; + +// e.g. define FunctionalEvent interface +interface FunctionalEvent : ExtendableEvent { + // add a functional event’s own attributes and methods +}; + +partial interface ServiceWorkerGlobalScope { + attribute EventHandler onfunctionalevent; +}; +

                                                        Issues Index