Re: More on workerStart

On 6/2/15 1:28 PM, Ilya Grigorik wrote:
> The workerStart attribute MUST return a DOMHighResTimeStamp
> representing the difference between the time origin of WorkerGlobalScope
> of the AbstractWorker the getter is invoked on, and the [time origin of the
> context][1] that started it.

So what, exactly, does "the context that started it" mean?  The 
fundamental problem is that both "context" and "started it" are 
undefined.  As a simple example:

parent.html:

   <iframe></iframe>
   <iframe src="child.html"></iframe>
   <script>
     onload = function() {
       var w = new frames[0].SharedWorker(something, "myworker");
       frames[1].getTime(w);
     }
   </script>

child.html:

    <script>function getTime(w) { alert(w.workerStart); }</script>

Is w.workerStart relative to the parent page or the first subframe or 
the second subframe (which is where the code examining workerStart 
lives)?  Or, if there was already a SharedWorkerGlobalScope for 
"myworker" that was created from some other page, is it relative to that 
page?

Put another way, what are the actual use cases here?  Is it to allow 
whoever has a reference to the worker to convert its times into their 
own timebase?  Or is it to allow something else?

Because one plausible definition here would be to have the "workerStart" 
getter take the timebase of the incumbent settings object's global and 
return the offset between that and the timebase of the worker global. 
This would have the salutary effect that code like this would have the 
properties described in the comments in it:

   w.onmessage = function(e) {
     var workerTimeStamp = e.data; // in worker's timebase
     var timeStamp = workeTimeStamp + w.workerStart;
     // timeStamp is now in the same timebase as performance.now()
   }

no matter where w came from to reach this code.  So in my example above 
the answer would be "second subframe" when examined from inside the 
second subframe, but "parent page" if examined directly from the onload 
handler.

But this really comes back to how we expect people to actually use this 
property, of course.

-Boris

Received on Tuesday, 2 June 2015 17:52:17 UTC