Skip to content

Commit

Permalink
Handle deserialization failures in postMessage()
Browse files Browse the repository at this point in the history
This is part of whatwg/html#2530; see related links there for more information. Closes w3c#1116.
  • Loading branch information
domenic committed Apr 20, 2017
1 parent 066d0d5 commit 2b481ca
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Let |origin| be the [=Unicode serialization of an origin|Unicode serialization=] of |incumbentSettings|'s [=environment settings object/origin=].
1. Let |destination| be the {{ServiceWorkerGlobalScope}} object associated with |serviceWorker|.
1. Let |deserializeRecord| be <a abstract-op>StructuredDeserializeWithTransfer</a>(|serializeWithTransferResult|, |destination|'s [=global object/Realm=]).

If this throws an exception, [=fire an event=] named {{messageerror!!event}} at |destination|, using {{MessageEvent}}, with the {{MessageEvent/origin}} attribute initialized to |origin| and the {{MessageEvent/source}} attribute initialized to |source|, and then abort these steps.
1. Let |messageClone| be |deserializeRecord|.\[[Deserialized]].
1. Let |newPorts| be a new [=frozen array type|frozen array=] consisting of all {{MessagePort}} objects in |deserializeRecord|.\[[TransferredValues]], if any, maintaining their relative order.
1. Let |e| be the result of [=creating an event=] named {{message!!event}}, using {{ExtendableMessageEvent}}, with the {{ExtendableMessageEvent/origin}} attribute initialized to |origin|, the {{ExtendableMessageEvent/source}} attribute initialized to |source|, the {{ExtendableMessageEvent/data}} attribute initialized to |messageClone|, and the {{ExtendableMessageEvent/ports}} attribute initialized to |newPorts|.
Expand Down Expand Up @@ -554,6 +556,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
// events
attribute EventHandler oncontrollerchange;
attribute EventHandler onmessage; // event.source of message events is ServiceWorker object
attribute EventHandler onmessageerror;
};
</pre>
<pre class="idl" id="registration-option-list-dictionary">
Expand Down Expand Up @@ -687,6 +690,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
<td><dfn attribute for="ServiceWorkerContainer"><code>onmessage</code></dfn></td>
<td>{{ServiceWorkerContainer/message!!event}}</td>
</tr>
<tr>
<td><dfn attribute for="ServiceWorkerContainer"><code>onmessageerror</code></dfn></td>
<td>{{ServiceWorkerContainer/messageerror!!event}}</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -880,6 +887,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe

// event
attribute EventHandler onmessage; // event.source of the message events is Client object
attribute EventHandler onmessageerror;
};
</pre>

Expand Down Expand Up @@ -947,6 +955,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
<td><dfn attribute for="ServiceWorkerGlobalScope"><code>onmessage</code></dfn></td>
<td>{{message!!event}}</td>
</tr>
<tr>
<td><dfn attribute for="ServiceWorkerGlobalScope"><code>onmessageerror</code></dfn></td>
<td>{{messageerror!!event}}</td>
</tr>
</tbody>
</table>
</section>
Expand Down Expand Up @@ -1030,6 +1042,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
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=]).

If this throws an exception, [=fire an event=] named {{messageerror!!event}} at |destination|, using {{MessageEvent}}, with the {{MessageEvent/origin}} attribute initialized to |origin| and the {{MessageEvent/source}} attribute initialized to |source|, and then abort these steps.
1. Let |messageClone| be |deserializeRecord|.\[[Deserialized]].
1. Let |newPorts| be a new [=frozen array type|frozen array=] consisting of all {{MessagePort}} objects in |deserializeRecord|.\[[TransferredValues]], if any,
1. [=Dispatch|Dispatch an event=] named {{Window/message!!event}} at |destination|, using {{MessageEvent}}, with the {{MessageEvent/origin}} attribute initialized to |origin|, the {{MessageEvent/source}} attribute initialized to |source|, the {{MessageEvent/data}} attribute initialized to |messageClone|, and the {{MessageEvent/ports}} attribute initialized to |newPorts|.
Expand Down Expand Up @@ -1739,6 +1753,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
<td>{{ExtendableMessageEvent}}</td>
<td>When it receives a message.</td>
</tr>
<tr>
<td><dfn event><code>messageerror</code></dfn></td>
<td>{{MessageEvent}}</td>
<td>When it was sent a message that cannot be deserialized.</td>
</tr>
</tbody>
</table>
</section>
Expand Down

0 comments on commit 2b481ca

Please sign in to comment.