Skip to content

Commit 3b31974

Browse files
dtapuskamfalken
authored andcommitted
Add API for postMessage with PostMessageOptions
This is similar to the HTML changes in whatwg/html#3800
1 parent b4a9916 commit 3b31974

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

docs/index.bs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
314314
interface ServiceWorker : EventTarget {
315315
readonly attribute USVString scriptURL;
316316
readonly attribute ServiceWorkerState state;
317-
void postMessage(any message, optional sequence<object> transfer = []);
317+
void postMessage(any message, sequence<object> transfer);
318+
void postMessage(any message, optional PostMessageOptions options);
318319

319320
// event
320321
attribute EventHandler onstatechange;
@@ -362,11 +363,20 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
362363

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

366+
1. Let |options| be «[ "transfer" → |transfer| ]».
367+
1. Invoke {{ServiceWorker/postMessage(message, options)}} with |message| and |options| as the arguments.
368+
</section>
369+
370+
<section algorithm="service-worker-postmessage-options">
371+
<h4 id="service-worker-postmessage-options">{{ServiceWorker/postMessage(message, options)}}</h4>
372+
373+
The <dfn method for="ServiceWorker"><code>postMessage(|message|, |options|)</code></dfn> method *must* run these steps:
374+
365375
1. If the {{ServiceWorker/state}} attribute value of the <a>context object</a> is {{"redundant"}}, [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
366376
1. Let |serviceWorker| be the [=/service worker=] represented by the <a>context object</a>.
367377
1. Invoke <a>Run Service Worker</a> algorithm with |serviceWorker| as the argument.
368378
1. Let |incumbentSettings| be the <a>incumbent settings object</a>, and |incumbentGlobal| its [=environment settings object/global object=].
369-
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |transfer|). Rethrow any exceptions.
379+
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |options|.transfer). Rethrow any exceptions.
370380
1. [=Queue a task=] on the [=DOM manipulation task source=] to run the following steps:
371381
1. Let |source| be determined by switching on the type of |incumbentGlobal|:
372382
<dl class="switch">
@@ -982,7 +992,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
982992
readonly attribute FrameType frameType;
983993
readonly attribute DOMString id;
984994
readonly attribute ClientType type;
985-
void postMessage(any message, optional sequence&lt;object&gt; transfer = []);
995+
void postMessage(any message, sequence&lt;object&gt; transfer);
996+
void postMessage(any message, optional PostMessageOptions options);
986997
};
987998

988999
[Exposed=ServiceWorker]
@@ -1051,10 +1062,19 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
10511062

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

1065+
1. Let |options| be «[ "transfer" → |transfer| ]».
1066+
1. Invoke {{Client/postMessage(message, options)}} with |message| and |options| as the arguments.
1067+
</section>
1068+
1069+
<section algorithm="client-postmessage-options">
1070+
<h4 id="client-postmessage-options">{{Client/postMessage(message, options)}}</h4>
1071+
1072+
The <dfn method for="Client"><code>postMessage(|message|, |options|)</code></dfn> method *must* run these steps:
1073+
10541074
1. Let |sourceSettings| be the <a>context object</a>'s <a>relevant settings object</a>.
10551075
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.
10561076
1. If |destination| is null, <a>throw</a> an "{{InvalidStateError}}" {{DOMException}}.
1057-
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |transfer|). Rethrow any exceptions.
1077+
1. Let |serializeWithTransferResult| be <a abstract-op>StructuredSerializeWithTransfer</a>(|message|, |options|.transfer). Rethrow any exceptions.
10581078
1. Add a <a>task</a> that runs the following steps to |destination|'s [=ServiceWorkerContainer/client message queue=]:
10591079
1. Let |origin| be the [=Unicode serialization of an origin|Unicode serialization=] of |sourceSettings|'s [=environment settings object/origin=].
10601080
1. Let |source| be a {{ServiceWorker}} object, which represents the [=ServiceWorkerGlobalScope/service worker=] associated with |sourceSettings|'s [=environment settings object/global object=].

0 commit comments

Comments
 (0)