Re: [w3c/ServiceWorker] unclear how Client.postMessage looks up its destination (#1042)

> Is it possible to make the mapping from service worker client -> ServiceWorkerContainer more explicit?

Please see the definition of the association between a `ServiceWorkerContainer` and a service worker client: https://w3c.github.io/ServiceWorker/#serviceworkercontainer-service-worker-client. `client.postMessage()` basically tries to reference the `ServiceWorkerContainer` object that is associated with the service worker client in that sense. Informally speaking, that's the captured client's document's `ServiceWorkerContainer` object.

> It's not clear in what cases it wouldn't find one.

`Client` objects retrieved from client APIs are snapshots. So, the states are captured in the `Client` creation time: https://w3c.github.io/ServiceWorker/#create-client. So, by the time the steps of the `postMessage()` is running, the client may already have been closed. The null-check is a guard against this occasion.

Note that by introducing the "reserved client concept" lately, the message queuing mechanism for `client.postMessage()` needs changes since it can be possible that a `ServiceWorkerContainer` object hasn't been created by the time 'postMessage()` is run. The issue filed in https://github.com/w3c/ServiceWorker/issues/1035.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1042#issuecomment-269933897

Received on Monday, 2 January 2017 04:40:19 UTC