From b620471ff823e8e6507b077cf0785a530762f5e3 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 18 Sep 2015 11:01:39 +0200 Subject: [PATCH] Give workers a base URL and clean up shared workers This fixes the following from #164: * It gives workers a base URL that matches the response's url. Per https://www.w3.org/Bugs/Public/show_bug.cgi?id=28835 this matches Firefox and would also be more consistent with how the platform determines base URLs in general. (The fix is slightly ugly as it puts the URL on the global object so it can be overridden later. In HTML Standard theory the global object is optional and non-JavaScript languages need not provide it, but I think we should move away from that: #167.) * It keys shared worker on constructor URL rather than "location". The latter takes redirects into account and if implemented results in racy behavior. Fortunately, neither Chrome nor Firefox implemented this and instead already use this new "constructor url" concept. * It references "in parallel" where used. * It defaults name to the empty string through IDL. --- source | 98 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 42 deletions(-) diff --git a/source b/source index a1acb9491fc..e0a303450c4 100644 --- a/source +++ b/source @@ -95172,13 +95172,17 @@ interface WorkerGlobalScope : EventTarget { attribute EventHandler ononline; }; +

A WorkerGlobalScope object has an associated url (null or a URL). It is initially + null. +

The self attribute must return the WorkerGlobalScope object itself.

The location attribute must return the WorkerLocation object created for the WorkerGlobalScope - object when the worker was created. It represents the absolute URL of the script that - was used to initialise the worker, after any redirects.

+ object when the worker was created. It represents the WorkerGlobalScope object's + url.


@@ -95278,14 +95282,20 @@ interface WorkerGlobalScope : EventTarget { attribute EventHandler onconnect; }; +

A SharedWorkerGlobalScope object has an associated constructor url and name. +

Shared workers receive message ports through connect events on their SharedWorkerGlobalScope object for each connection.

-

The name attribute must return - the value it was assigned when the SharedWorkerGlobalScope object was created by the - "run a worker" algorithm. Its value represents the name that can be used to obtain a - reference to the worker using the SharedWorker constructor.

+

The name attribute must + return the SharedWorkerGlobalScope object's name. Its value represents the name that can + be used to obtain a reference to the worker using the SharedWorker constructor.

The following are the event handlers (and their corresponding event handler event types) that must be supported, as event @@ -95470,6 +95480,10 @@ interface WorkerGlobalScope : EventTarget { event named error at that object. Abort these steps.

+
  • Set worker global scope's url to response's url.

  • +
  • In the newly created execution environment, create a JavaScript global environment whose global object is worker global scope. If worker global scope is a DedicatedWorkerGlobalScope object, then this is a @@ -95568,8 +95582,9 @@ interface WorkerGlobalScope : EventTarget {


    -

    When a user agent is to kill a worker it must run the following steps in parallel - with the worker's main loop (the "run a worker" processing model defined above):

    +

    When a user agent is to kill a worker it must run the following steps in + parallel with the worker's main loop (the "run a worker" processing model + defined above):

      @@ -95593,9 +95608,9 @@ interface WorkerGlobalScope : EventTarget {
      -

      When a user agent is to terminate a worker it must run the following steps in - parallel with the worker's main loop (the "run a worker" processing model defined - above):

      +

      When a user agent is to terminate a worker it must run the following steps in + parallel with the worker's main loop (the "run a worker" processing model + defined above):

        @@ -95685,9 +95700,8 @@ interface AbstractWorker {
        Script settings for workers
        -

        When the user agent is required to set up a worker environment settings object, given a - worker global scope and a URL script - address it must run the following steps:

        +

        When the user agent is required to set up a worker environment settings object, + given a worker global scope, it must run the following steps:

          @@ -95761,7 +95775,8 @@ interface AbstractWorker {
          The API base URL
          -

          Return script address.

          +

          Return worker global scope's url.

          @@ -95775,7 +95790,8 @@ interface AbstractWorker {
          The creation URL
          -

          Return script address.

          +

          Return worker global scope's url.

          @@ -95881,8 +95897,8 @@ interface Worker : EventTarget {
        1. Create a new DedicatedWorkerGlobalScope object. Let worker global scope be this new object.

        2. -
        3. Set up a worker environment settings object with worker global scope - and worker URL, and let settings object be the result.

        4. +
        5. Set up a worker environment settings object with worker global + scope, and let settings object be the result.

        6. Create a new Worker object, associated with worker global scope. Let worker be this new object.

        7. @@ -95932,7 +95948,7 @@ interface Worker : EventTarget {
          Shared workers and the SharedWorker interface
          -
          [Constructor(DOMString scriptURL, optional DOMString name), Exposed=(Window,Worker)]
          +  
          [Constructor(DOMString scriptURL, optional DOMString name = ""), Exposed=(Window,Worker)]
           interface SharedWorker : EventTarget {
             readonly attribute MessagePort port;
           };
          @@ -95958,9 +95974,6 @@ interface SharedWorker : EventTarget {
           
              
        8. Let scriptURL be the resulting absolute URL and parsed scriptURL be the resulting parsed URL.

        9. -
        10. Let name be the value of the second argument, or the empty string if - the second argument was omitted.

        11. -
        12. If the scheme component of parsed @@ -96005,20 +96018,20 @@ interface SharedWorker : EventTarget {

          If name is not the empty string and there exists a SharedWorkerGlobalScope object whose closing flag is false, whose name attribute is exactly equal to - name, and that is the global object specified by an environment - settings object that specifies as its origin the same origin - as the origin of scriptURL, then let worker global scope be + data-x="dom-WorkerGlobalScope-closing">closing flag is false, whose name is exactly equal to name, + and that is the global object specified by an environment settings + object that specifies as its origin the same origin as the + origin of scriptURL, then let worker global scope be that SharedWorkerGlobalScope object.

          Otherwise, if name is the empty string and there exists a SharedWorkerGlobalScope object whose closing flag is false, whose name attribute is the empty string, and whose - location attribute represents an - absolute URL that is exactly equal to scriptURL, then let worker - global scope be that SharedWorkerGlobalScope object.

          + data-x="dom-WorkerGlobalScope-closing">closing flag is false, whose name is the empty string, and whose constructor url is equal to + scriptURL, then let worker global scope be that + SharedWorkerGlobalScope object.

        13. @@ -96042,10 +96055,10 @@ interface SharedWorker : EventTarget {
            -
          1. If worker global scope's location attribute represents an absolute - URL that is not exactly equal to scriptURL, then throw a - URLMismatchError exception and abort all these steps.

          2. +
          3. If worker global scope's constructor url is not equal + to scriptURL, then throw a URLMismatchError exception and abort all + these steps.

          4. Associate worker with worker global scope.

          5. @@ -96102,13 +96115,14 @@ interface SharedWorker : EventTarget { global scope be this new object.

          6. Set up a worker environment settings object with worker global - scope and scriptURL, and let settings object be - the result.

          7. + scope, and let settings object be the result.

          8. Associate worker with worker global scope.

          9. -
          10. Set the name attribute of - worker global scope to name.

          11. +
          12. Set worker global scope's name to name and constructor url to + scriptURL.

          13. Create a new MessagePort object whose owner is settings object. Let inside @@ -96313,8 +96327,8 @@ interface WorkerNavigator {}; interface WorkerLocation { }; WorkerLocation implements URLUtilsReadOnly;

          -

          A WorkerLocation object represents an absolute URL set at its - creation.

          +

          A WorkerLocation object represents the WorkerGlobalScope object's + url.

          The WorkerLocation interface supports the URLUtilsReadOnly interface.