From b546c24c6fba8d91dc74661de8ff15693ba7c9d4 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Wed, 10 Aug 2016 18:29:00 -0400 Subject: [PATCH] Tidy up global object usage This commit is part of the effort in #922 to eliminate the use of entry and incumbent settings objects. It mostly just changes cases where all of relevant/current/entry/incumbent are equivalent, to use relevant. It also removes mention of "default action" for events, since that is not supposed to exist, and does some other tidying in the postMessage algorithms. There are no normative changes in this commit. --- spec/service_worker/index.bs | 39 ++++++++++++++++++---------------- spec/service_worker/index.html | 39 ++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/spec/service_worker/index.bs b/spec/service_worker/index.bs index 6926b492..5da13ff4 100644 --- a/spec/service_worker/index.bs +++ b/spec/service_worker/index.bs @@ -81,6 +81,7 @@ spec: html; type: dfn text: parent browsing context text: queue a task text: relevant settings object + text: the environment settings object's global object text: replacement enabled text: responsible browsing context text: responsible document @@ -518,17 +519,18 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
  • Invoke Run Service Worker algorithm with serviceWorker as the argument.
  • Let destination be the {{ServiceWorkerGlobalScope}} object associated with serviceWorker.
  • Let targetRealm be destination's Realm.
  • +
  • Let incumbentSettings be the incumbent settings object, and incumbentGlobal its global object.
  • Let cloneRecord be StructuredCloneWithTransfer(message, transfer, targetRealm). If this throws an exception, rethrow that exception and abort these steps.
  • Let clonedMessage be cloneRecord.\[[Clone]].
  • Let newPorts be a new frozen array consisting of all {{MessagePort}} objects in cloneRecord.\[[TransferList]], if any, maintaining their relative order.
  • Queue a task that runs the following steps:
      -
    1. 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.
    2. +
    3. Create an event e that uses the {{ExtendableMessageEvent}} interface, with the event type message, which does not bubble and is not cancelable.
    4. Let the {{ExtendableMessageEvent/data}} attribute of e be initialized to clonedMessage.
    5. -
    6. Let the {{ExtendableMessageEvent/origin}} attribute of e be initialized to the Unicode serialisation of the origin specified by the incumbent settings object.
    7. -
    8. If the global object globalObject specified by the incumbent settings object is a {{ServiceWorkerGlobalScope}} object, let the {{ExtendableMessageEvent/source}} attribute of e be initialized to a new {{ServiceWorker}} object that represents globalObject's service worker.
    9. -
    10. Else if globalObject is a {{Window}} object, let the {{ExtendableMessageEvent/source}} attribute of e be initialized to a new {{WindowClient}} object that represents globalObject's browsing context.
    11. -
    12. Else, let it be initialized to a new {{Client}} object that represents the worker associated with globalObject.
    13. +
    14. Let the {{ExtendableMessageEvent/origin}} attribute of e be initialized to the Unicode serialisation of incumbentSettings's origin.
    15. +
    16. If incumbentGlobal is a {{ServiceWorkerGlobalScope}} object, let the {{ExtendableMessageEvent/source}} attribute of e be initialized to a new {{ServiceWorker}} object that represents incumbentGlobal's service worker.
    17. +
    18. Else if incumbentGlobal is a {{Window}} object, let the {{ExtendableMessageEvent/source}} attribute of e be initialized to a new {{WindowClient}} object that represents incumbentGlobal's browsing context.
    19. +
    20. Else, let it be initialized to a new {{Client}} object that represents the worker associated with incumbentGlobal.
    21. Let the {{ExtendableMessageEvent/ports}} attribute of e be initialized to newPorts.
    22. Dispatch e at destination.
    @@ -1218,18 +1220,19 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

    The postMessage(message, transfer) method must run these steps or their equivalent:

      +
    1. Let sourceSettings be the context object's relevant settings object.
    2. Let destination be the {{ServiceWorkerContainer}} object whose service worker client is the context object's service worker client.
    3. If destination is null, throw an "{{InvalidStateError}}" exception.
    4. -
    5. Let targetRealm be destination's Realm.
    6. +
    7. Let targetRealm be destination's relevant Realm.
    8. Let cloneRecord be StructuredCloneWithTransfer(message, transfer, targetRealm). If this throws an exception, rethrow that exception and abort these steps.
    9. Let clonedMessage be cloneRecord.\[[Clone]].
    10. Let newPorts be a new frozen array consisting of all {{MessagePort}} objects in cloneRecord.\[[TransferList]], if any, maintaining their relative order.
    11. Add a task that runs the following steps to destination's client message queue:
        -
      1. 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.
      2. +
      3. Create an event e that uses the {{ServiceWorkerMessageEvent}} interface, with the event type message, which does not bubble and is not cancelable.
      4. Let the {{ServiceWorkerMessageEvent/data}} attribute of e be initialized to clonedMessage.
      5. -
      6. Let the {{ServiceWorkerMessageEvent/origin}} attribute of e be initialized to the Unicode serialisation of the origin specified by the incumbent settings object.
      7. -
      8. Let the {{ServiceWorkerMessageEvent/source}} attribute of e be initialized to a {{ServiceWorker}} object, which represents the service worker associated with the global object specified by the incumbent settings object.
      9. +
      10. Let the {{ServiceWorkerMessageEvent/origin}} attribute of e be initialized to the Unicode serialisation of sourceSettings's origin.
      11. +
      12. Let the {{ServiceWorkerMessageEvent/source}} attribute of e be initialized to a {{ServiceWorker}} object, which represents the service worker associated with sourceSettings's global object.
      13. Let the {{ServiceWorkerMessageEvent/ports}} attribute of e be initialized to newPorts.
      14. Dispatch e at destination.
      @@ -1285,10 +1288,10 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

      The navigate() method must run these steps or their equivalent:

        -
      1. Let url be the result of parsing url with entry settings object's API base URL.
      2. +
      3. Let url be the result of parsing url with the context object's relevant settings object's API base URL.
      4. If url is failure, return a promise rejected with a TypeError.
      5. If url is about:blank, return a promise rejected with a TypeError.
      6. -
      7. 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.
      8. +
      9. If the context object's associated service worker client's active worker is not the context object's relevant 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:
          @@ -1513,7 +1516,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

          The openWindow(url) method must run these steps or their equivalent:

            -
          1. Let url be the result of parsing url with entry settings object's API base URL.
          2. +
          3. Let url be the result of parsing url with the context object's relevant settings object's API base URL.
          4. If url is failure, return a promise rejected with a TypeError.
          5. If url is about:blank, return a promise rejected with a TypeError.
          6. If this algorithm is not triggered by user activation, return a promise rejected with an "{{InvalidAccessError}}" exception.
          7. @@ -1689,11 +1692,11 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
        1. If options.{{ForeignFetchOptions/scopes}} is empty throw a TypeError and abort these steps.
        2. -
        3. Let scopeString be the incumbent settings object's global object's service worker's containing service worker registration's scope url, serialized.
        4. +
        5. Let scopeString be the context object's relevant global object's service worker's containing service worker registration's scope url, serialized.
        6. Let subScopeURLs be an empty list of URLs.
        7. For each subScope in options.{{ForeignFetchOptions/scopes}}:
            -
          1. Let subScopeURL be the result of parsing subScope with entry settings object's API base URL.
          2. +
          3. Let subScopeURL be the result of parsing subScope with context object's relevant settings object's API base URL.
          4. If subScopeURL is failure, throw a TypeError and abort these steps.
          5. Let subScopeString be the serialized subScopeURL.
          6. If subScopeString does not start with scopeString, throw a TypeError and abort these steps.
          7. @@ -3387,7 +3390,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
          8. Invoke Run Service Worker algorithm with installingWorker as the argument.
          9. 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. +
            3. Create a trusted event e that uses the {{InstallEvent}} interface, with the event type install, which does not bubble and is not cancelable.
            4. Dispatch e at installingWorker's environment settings object's global object globalObject.
            5. WaitForAsynchronousExtensions: Run the following substeps in parallel:
                @@ -3477,7 +3480,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
              1. Invoke Run Service Worker algorithm with activeWorker as the argument.
              2. 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. +
                3. Create a trusted event e that uses the {{ExtendableEvent}} interface, with the event type activate, which does not bubble and is not cancelable.
                4. Dispatch e at activeWorker's environment settings object's global object.
                5. WaitForAsynchronousExtensions: Wait, in parallel, until e's extensions allowed flag is unset.
                @@ -3626,7 +3629,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
              3. Invoke Run Service Worker algorithm with activeWorker as the argument.
              4. Queue a task task to run the following substeps:
                  -
                1. Create a trusted event e that uses the {{FetchEvent}} interface, with the event type fetch, which does not bubble and has no default action.
                2. +
                3. Create a trusted event e that uses the {{FetchEvent}} interface, with the event type fetch, which does not bubble.
                4. Let the request attribute of e be initialized to r.
                5. Let the clientId attribute of e be initialized to client's id if request is not a non-subresource request, and to null otherwise.
                6. 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.
                7. @@ -3707,7 +3710,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
                8. Invoke [[#run-service-worker-algorithm]] algorithm with activeWorker as the argument.
                9. Queue a task task to run the following substeps:
                    -
                  1. Create a trusted event e that uses the {{ForeignFetchEvent}} interface, with the event type foreignfetch, which does not bubble and has no default action.
                  2. +
                  3. Create a trusted event e that uses the {{ForeignFetchEvent}} interface, with the event type foreignfetch, which does not bubble.
                  4. Let the {{ForeignFetchEvent/request}} attribute of e be initialized to r.
                  5. Let the {{ForeignFetchEvent/origin}} attribute of e be initialized to the Unicode serialization of request's origin.
                  6. Dispatch e at activeWorker's environment settings object's global object.
                  7. diff --git a/spec/service_worker/index.html b/spec/service_worker/index.html index a8dc388f..0773f4f5 100644 --- a/spec/service_worker/index.html +++ b/spec/service_worker/index.html @@ -1881,18 +1881,19 @@

                    <
                  8. Invoke Run Service Worker algorithm with serviceWorker as the argument.
                  9. Let destination be the ServiceWorkerGlobalScope object associated with serviceWorker.
                  10. Let targetRealm be destination’s Realm. +
                  11. Let incumbentSettings be the incumbent settings object, and incumbentGlobal its global object.
                  12. Let cloneRecord be StructuredCloneWithTransfer(message, transfer, targetRealm). If this throws an exception, rethrow that exception and abort these steps.
                  13. Let clonedMessage be cloneRecord.[[Clone]].
                  14. Let newPorts be a new frozen array consisting of all MessagePort objects in cloneRecord.[[TransferList]], if any, maintaining their relative order.
                  15. Queue a task that runs the following steps:
                      -
                    1. 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. +
                    2. Create an event e that uses the ExtendableMessageEvent interface, with the event type message, which does not bubble and is not cancelable.
                    3. Let the data attribute of e be initialized to clonedMessage. -
                    4. Let the origin attribute of e be initialized to the Unicode serialisation of the origin specified by the incumbent settings object. -
                    5. 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. -
                    6. 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. -
                    7. Else, let it be initialized to a new Client object that represents the worker associated with globalObject. +
                    8. Let the origin attribute of e be initialized to the Unicode serialisation of incumbentSettings’s origin. +
                    9. If incumbentGlobal is a ServiceWorkerGlobalScope object, let the source attribute of e be initialized to a new ServiceWorker object that represents incumbentGlobal’s service worker. +
                    10. Else if incumbentGlobal is a Window object, let the source attribute of e be initialized to a new WindowClient object that represents incumbentGlobal’s browsing context. +
                    11. Else, let it be initialized to a new Client object that represents the worker associated with incumbentGlobal.
                    12. Let the ports attribute of e be initialized to newPorts.
                    13. Dispatch e at destination.
                    @@ -2422,19 +2423,20 @@

                    4.2.4. postMessage(message, transfer)

                    The postMessage(message, transfer) method must run these steps or their equivalent:

                      +
                    1. Let sourceSettings be the context object’s relevant settings object.
                    2. Let destination be the ServiceWorkerContainer object whose service worker client is the context object’s service worker client.
                    3. If destination is null, throw an "InvalidStateError" exception. -
                    4. Let targetRealm be destination’s Realm. +
                    5. Let targetRealm be destination’s relevant Realm.
                    6. Let cloneRecord be StructuredCloneWithTransfer(message, transfer, targetRealm). If this throws an exception, rethrow that exception and abort these steps.
                    7. Let clonedMessage be cloneRecord.[[Clone]].
                    8. Let newPorts be a new frozen array consisting of all MessagePort objects in cloneRecord.[[TransferList]], if any, maintaining their relative order.
                    9. Add a task that runs the following steps to destination’s client message queue:
                        -
                      1. 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. +
                      2. Create an event e that uses the ServiceWorkerMessageEvent interface, with the event type message, which does not bubble and is not cancelable.
                      3. Let the data attribute of e be initialized to clonedMessage. -
                      4. Let the origin attribute of e be initialized to the Unicode serialisation of the origin specified by the incumbent settings object. -
                      5. Let the source attribute of e be initialized to a ServiceWorker object, which represents the service worker associated with the global object specified by the incumbent settings object. +
                      6. Let the origin attribute of e be initialized to the Unicode serialisation of sourceSettings’s origin. +
                      7. Let the source attribute of e be initialized to a ServiceWorker object, which represents the service worker associated with sourceSettings’s global object.
                      8. Let the ports attribute of e be initialized to newPorts.
                      9. Dispatch e at destination.
                      @@ -2479,10 +2481,10 @@

                      4.2.8. navigate(url)

                      The navigate() method must run these steps or their equivalent:

                        -
                      1. Let url be the result of parsing url with entry settings object’s API base URL. +
                      2. Let url be the result of parsing url with the context object’s relevant settings object’s API base URL.
                      3. If url is failure, return a promise rejected with a TypeError.
                      4. If url is about:blank, return a promise rejected with a TypeError. -
                      5. 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. +
                      6. If the context object’s associated service worker client’s active worker is not the context object’s relevant global object’s service worker, return a promise rejected with a TypeError.
                      7. Let promise be a new promise.
                      8. Run these substeps in parallel: @@ -2693,7 +2695,7 @@

                        4.3.3. openWindow(url)

                        The openWindow(url) method must run these steps or their equivalent:

                          -
                        1. Let url be the result of parsing url with entry settings object’s API base URL. +
                        2. Let url be the result of parsing url with the context object’s relevant settings object’s API base URL.
                        3. If url is failure, return a promise rejected with a TypeError.
                        4. If url is about:blank, return a promise rejected with a TypeError.
                        5. If this algorithm is not triggered by user activation, return a promise rejected with an "InvalidAccessError" exception. @@ -2842,12 +2844,12 @@

                          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 context object’s relevant 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:
                            -
                          1. Let subScopeURL be the result of parsing subScope with entry settings object’s API base URL. +
                          2. Let subScopeURL be the result of parsing subScope with context object’s relevant settings object’s API base URL.
                          3. If subScopeURL is failure, throw a TypeError and abort these steps.
                          4. Let subScopeString be the serialized subScopeURL.
                          5. If subScopeString does not start with scopeString, throw a TypeError and abort these steps. @@ -4324,7 +4326,7 @@

                            In
                          6. 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. Create a trusted event e that uses the InstallEvent interface, with the event type install, which does not bubble and is not cancelable.
                            3. Dispatch e at installingWorker’s environment settings object’s global object globalObject.
                            4. WaitForAsynchronousExtensions: Run the following substeps in parallel: @@ -4411,7 +4413,7 @@

                              Acti
                            5. 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. Create a trusted event e that uses the ExtendableEvent interface, with the event type activate, which does not bubble and is not cancelable.
                              3. Dispatch e at activeWorker’s environment settings object’s global object.
                              4. WaitForAsynchronousExtensions: Wait, in parallel, until e’s extensions allowed flag is unset.
                              @@ -4553,7 +4555,7 @@

                              Queue a task task to run the following substeps:
                                -
                              1. Create a trusted event e that uses the FetchEvent interface, with the event type fetch, which does not bubble and has no default action. +
                              2. Create a trusted event e that uses the FetchEvent interface, with the event type fetch, which does not bubble.
                              3. Let the request attribute of e be initialized to r.
                              4. Let the clientId attribute of e be initialized to client’s id if request is not a non-subresource request, and to null otherwise.
                              5. 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. @@ -4631,7 +4633,7 @@

                                Queue a task task to run the following substeps:
                                  -
                                1. Create a trusted event e that uses the ForeignFetchEvent interface, with the event type foreignfetch, which does not bubble and has no default action. +
                                2. Create a trusted event e that uses the ForeignFetchEvent interface, with the event type foreignfetch, which does not bubble.
                                3. Let the request attribute of e be initialized to r.
                                4. Let the origin attribute of e be initialized to the Unicode serialization of request’s origin.
                                5. Dispatch e at activeWorker’s environment settings object’s global object. @@ -5938,6 +5940,7 @@

                                  task source
                                6. tasks
                                7. terminate a worker +
                                8. the environment settings object's global object
                                9. the global object's realm
                                10. the worker's documents
                                11. top-level browsing context