Re: [ServiceWorker] ServiceWorker to "service worker" mapping and stability (#622)

@nikhilm I'm not able to repro the behavior you report on a recent build. However, I found a similar issue. 
In the statechange for 'installed', r.installing is null but r.waiting's state is 'installing'.

The reason is that Blink can mint multiple ServiceWorker JS objects representing the same Service Worker. Therefore one JS object can have its state modified and the statechange event dispatched before another one representing the same worker gets the state modification. I believe this is a spec violation, because Update State first sets state on the "worker" before dispatching the event to each of the JS objects. Do you agree, and does Firefox do it correctly?

Here is my test case:
```javascript
promise_test(function(t) {
    var scope = 'resources/state/';
    var registration;
    var sw;

    return navigator.serviceWorker.register('resources/empty-worker.js', { scope: scope })
      .then(function(r) {
          sw = r.installing;
          return new Promise(function(resolve) {
              r.installing.addEventListener('statechange', function(e) {
                  if (e.target.state != 'installed')
                    return;
                  // These pass on Blink.
                  assert_equals(r.installing, null);
                  assert_equals(r.waiting.scriptURL, sw.scriptURL);
                  assert_equals(r.active, null);
                 // This fails on Blink, it's still 'installing'.
                 assert_equals(r.waiting.state, 'installed');
                  resolve();
                });
            });
        });
  }, 'statechange');
```

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/622#issuecomment-74870990

Received on Wednesday, 18 February 2015 14:24:09 UTC