Skip to content

Commit

Permalink
Make Client.postMessage to unloaded client not throw
Browse files Browse the repository at this point in the history
cf834f0
clarified the target object can be null, and it must throw in that case.

But #1291 pointed out that we
cannot implement that behavior without blocking the service worker
process in multi-process browser architectures.

This change makes the control return right away if the target client has
been unloaded.

Fixes #1291.
  • Loading branch information
jungkees committed Mar 27, 2018
1 parent 0efd007 commit 79b6c54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
The <dfn method for="Client"><code>postMessage(|message|, |transfer|)</code></dfn> method *must* run these steps:

1. Let |sourceSettings| be the <a>context object</a>'s <a>relevant settings object</a>.
1. Let |destination| be the {{ServiceWorkerContainer}} object whose [=ServiceWorkerContainer/service worker client=] is the <a>context object</a>'s [=Client/service worker client=], or null if no match is found.
1. If |destination| is null, <a>throw</a> an "{{InvalidStateError}}" {{DOMException}}.
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |transfer|). Rethrow any exceptions.
1. Add a <a>task</a> that runs the following steps to |destination|'s [=ServiceWorkerContainer/client message queue=]:
1. Let |targetClient| be the [=context object=]'s [=Client/service worker client=], or null if it does not exist (i.e. if the [=/service worker client=] has been [=Handle Service Worker Client Unload|unloaded=]).
1. If |targetClient| is null, return.
1. Let |destination| be |targetClient|'s {{ServiceWorkerContainer}} object (i.e. the {{ServiceWorkerContainer}} object's [=relevant settings object=] is |targetClient|).
1. Add a [=task=] that runs the following steps to |destination|'s [=ServiceWorkerContainer/client message queue=]:
1. Let |origin| be the [=Unicode serialization of an origin|Unicode serialization=] of |sourceSettings|'s [=environment settings object/origin=].
1. Let |source| be a {{ServiceWorker}} object, which represents the [=ServiceWorkerGlobalScope/service worker=] associated with |sourceSettings|'s [=environment settings object/global object=].
1. Let |deserializeRecord| be <a abstract-op>StructuredDeserializeWithTransfer</a>(|serializeWithTransferResult|, |destination|'s [=relevant Realm=]).
Expand Down Expand Up @@ -1087,7 +1088,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
<section algorithm="client-navigate">
<h4 id="client-navigate">{{WindowClient/navigate(url)}}</h4>

The <dfn method for="WindowClient"><code>navigate()</code></dfn> method *must* run these steps:
The <dfn method for="WindowClient"><code>navigate(|url|)</code></dfn> method *must* run these steps:

1. Let |url| be the result of <a lt="URL parser">parsing</a> |url| with the <a>context object</a>'s <a>relevant settings object</a>'s <a>API base URL</a>.
1. If |url| is failure, return a <a>promise</a> rejected with a <code>TypeError</code>.
Expand Down
9 changes: 5 additions & 4 deletions docs/v1/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
The <dfn method for="Client"><code>postMessage(|message|, |transfer|)</code></dfn> method *must* run these steps:

1. Let |sourceSettings| be the <a>context object</a>'s <a>relevant settings object</a>.
1. Let |destination| be the {{ServiceWorkerContainer}} object whose [=ServiceWorkerContainer/service worker client=] is the <a>context object</a>'s [=Client/service worker client=], or null if no match is found.
1. If |destination| is null, <a>throw</a> an "{{InvalidStateError}}" {{DOMException}}.
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |transfer|). Rethrow any exceptions.
1. Add a <a>task</a> that runs the following steps to |destination|'s [=ServiceWorkerContainer/client message queue=]:
1. Let |targetClient| be the [=context object=]'s [=Client/service worker client=], or null if it does not exist (i.e. if the [=/service worker client=] has been [=Handle Service Worker Client Unload|unloaded=]).
1. If |targetClient| is null, return.
1. Let |destination| be |targetClient|'s {{ServiceWorkerContainer}} object (i.e. the {{ServiceWorkerContainer}} object's [=relevant settings object=] is |targetClient|).
1. Add a [=task=] that runs the following steps to |destination|'s [=ServiceWorkerContainer/client message queue=]:
1. Let |origin| be the [=Unicode serialization of an origin|Unicode serialization=] of |sourceSettings|'s [=environment settings object/origin=].
1. Let |source| be a {{ServiceWorker}} object, which represents the [=ServiceWorkerGlobalScope/service worker=] associated with |sourceSettings|'s [=environment settings object/global object=].
1. Let |deserializeRecord| be <a abstract-op>StructuredDeserializeWithTransfer</a>(|serializeWithTransferResult|, |destination|'s [=relevant Realm=]).
Expand Down Expand Up @@ -1025,7 +1026,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
<section algorithm="client-navigate">
<h4 id="client-navigate">{{WindowClient/navigate(url)}}</h4>

The <dfn method for="WindowClient"><code>navigate()</code></dfn> method *must* run these steps:
The <dfn method for="WindowClient"><code>navigate(|url|)</code></dfn> method *must* run these steps:

1. Let |url| be the result of <a lt="URL parser">parsing</a> |url| with the <a>context object</a>'s <a>relevant settings object</a>'s <a>API base URL</a>.
1. If |url| is failure, return a <a>promise</a> rejected with a <code>TypeError</code>.
Expand Down

0 comments on commit 79b6c54

Please sign in to comment.