Skip to content

Commit

Permalink
Add API for postMessage with PostMessageOptions
Browse files Browse the repository at this point in the history
This is similar to the HTML changes in whatwg/html#3800
  • Loading branch information
dtapuska committed Oct 29, 2018
1 parent 7b85d13 commit 060b6c3
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 188 deletions.
28 changes: 24 additions & 4 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
interface ServiceWorker : EventTarget {
readonly attribute USVString scriptURL;
readonly attribute ServiceWorkerState state;
void postMessage(any message, optional sequence<object> transfer = []);
void postMessage(any message, sequence<object> transfer);
void postMessage(any message, optional PostMessageOptions options);

// event
attribute EventHandler onstatechange;
Expand Down Expand Up @@ -356,11 +357,20 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe

The <dfn method for="ServiceWorker"><code>postMessage(|message|, |transfer|)</code></dfn> method *must* run these steps:

1. Let |options| be «[ "transfer" → |transfer| ]».
1. Invoke {{ServiceWorker/postMessage(message, options)}} with |message| and |options| as the arguments.
</section>

<section algorithm="service-worker-postmessage-options">
<h4 id="service-worker-postmessage-options">{{ServiceWorker/postMessage(message, options)}}</h4>

The <dfn method for="ServiceWorker"><code>postMessage(|message|, |options|)</code></dfn> method *must* run these steps:

1. If the {{ServiceWorker/state}} attribute value of the <a>context object</a> is {{"redundant"}}, [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
1. Let |serviceWorker| be the [=/service worker=] represented by the <a>context object</a>.
1. Invoke <a>Run Service Worker</a> algorithm with |serviceWorker| as the argument.
1. Let |incumbentSettings| be the <a>incumbent settings object</a>, and |incumbentGlobal| its [=environment settings object/global object=].
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |transfer|). Rethrow any exceptions.
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |options|.transfer). Rethrow any exceptions.
1. [=Queue a task=] on the [=DOM manipulation task source=] to run the following steps:
1. Let |source| be determined by switching on the type of |incumbentGlobal|:
<dl class="switch">
Expand Down Expand Up @@ -976,7 +986,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
readonly attribute FrameType frameType;
readonly attribute DOMString id;
readonly attribute ClientType type;
void postMessage(any message, optional sequence&lt;object&gt; transfer = []);
void postMessage(any message, sequence&lt;object&gt; transfer);
void postMessage(any message, optional PostMessageOptions options);
};

[Exposed=ServiceWorker]
Expand Down Expand Up @@ -1045,10 +1056,19 @@ 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 |options| be «[ "transfer" → |transfer| ]».
1. Invoke {{Client/postMessage(message, options)}} with |message| and |options| as the arguments.
</section>

<section algorithm="client-postmessage-options">
<h4 id="client-postmessage-options">{{Client/postMessage(message, options)}}</h4>

The <dfn method for="Client"><code>postMessage(|message|, |options|)</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. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |options|.transfer). Rethrow any exceptions.
1. Add a <a>task</a> 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=].
Expand Down
Loading

0 comments on commit 060b6c3

Please sign in to comment.