<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>12340</bug_id>
          
          <creation_ts>2011-03-19 14:10:01 +0000</creation_ts>
          <short_desc>It is not clear which worker to use when using nameless SharedWorker</short_desc>
          <delta_ts>2011-06-21 21:24:39 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>Web Workers (editor: Ian Hickson)</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Olli Pettay">bugs</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>art.barstow</cc>
    
    <cc>atwilson</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>46835</commentid>
    <comment_count>0</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-03-19 14:10:01 +0000</bug_when>
    <thetext>http://www.w3.org/TR/2011/WD-workers-20110310/#shared-workers-and-the-sharedworker-interface

Step 7.5 is
&quot;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 whose location attribute represents an absolute URL with the same origin as scriptURL, then let worker global scope be that SharedWorkerGlobalScope object.&quot;

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

7.8 is
&quot;Create a new SharedWorkerGlobalScope object. Let worker global scope be this new object.&quot;


Example web page is
&lt;script&gt;
  var sw1 = new SharedWorker(&quot;worker.js&quot;, &quot;1&quot;);
  sw1.port.onmessage = function(e) { alert(&quot;sw1: &quot; + e.data); }
  var sw2 = new SharedWorker(&quot;worker.js&quot;, &quot;2&quot;);
  sw2.port.onmessage = function(e) { alert(&quot;sw2: &quot; + e.data); }
  var sw3 = new SharedWorker(&quot;worker.js&quot;);
  sw3.port.onmessage = function(e) { alert(&quot;sw3: &quot; + e.data); }
&lt;/script&gt;

and worker 
onconnect = function(e) {
  var port = e.ports[0];
  port.postMessage(&quot;worker name: &quot; + name);
}

Since sw1 and sw2 have different names, they get separate workers per 7.5 and 7.8.

Because sw3 doesn&apos;t have name, 7.6 applies. Both sw1 and sw2 fulfill the criteria of a worker
whose closing flag is false and location attribute is the same as sw3&apos;s location, so sw3 is
connected randomly to either one of those workers.
That is very strange.


Opera seems to implement what the spec says, Chrome creates a new worker for sw3.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>47781</commentid>
    <comment_count>1</comment_count>
    <who name="Drew Wilson">atwilson</who>
    <bug_when>2011-04-28 18:26:18 +0000</bug_when>
    <thetext>I think that the current spec language doesn&apos;t really capture the intent properly. The start of the discussion around the optional name parameter can be found here:

http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2009-August/022050.html

The idea was that if the name is omitted, the URL itself becomes the identifier of the worker, and only matches other instances whose name is empty.

In WebKit, an existing SharedWorker resource is reused if the name matches, or if both names are omitted/empty and the URLs match.

That said, the goal of allowing names to be omitted is to provide a way for developers to avoid collisions from different pages trying to use shared workers under the same domain, where it would otherwise be difficult to coordinate the use of names. I think that either implementation (WebKit or Opera) would satisfy this requirement.

That said, I think the current WebKit implementation makes more sense. It doesn&apos;t make sense to me that:

new SharedWorker(url, &quot;name&quot;)

and

new SharedWorker(url, &quot;name2&quot;)

would yield distinct shared workers, but somehow the special case of:

new SharedWorker(url, &quot;&quot;)

would be treated differently (&quot;pick a random instance, ignoring names&quot;). The WebKit implementation has the advantage of having deterministic behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50057</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-06-21 21:24:27 +0000</bug_when>
    <thetext>Yeah the intent was to still match on name, but also match on URL. Fixed. Behaviour should be deterministic where possible!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50058</commentid>
    <comment_count>3</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-06-21 21:24:39 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r6264.
Check-in comment: Oops, checking the name got dropped somehow in the name=&apos;&apos; case.
http://html5.org/tools/web-apps-tracker?from=6263&amp;to=6264</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>