From 3b3197431df710b2d60a69cdb94be6a63cc64f6d Mon Sep 17 00:00:00 2001 From: Dave Tapuska Date: Fri, 10 Aug 2018 15:48:19 -0400 Subject: [PATCH] Add API for postMessage with PostMessageOptions This is similar to the HTML changes in https://github.com/whatwg/html/pull/3800 --- docs/index.bs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/index.bs b/docs/index.bs index 6c336ae5..0f066ee6 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -314,7 +314,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; @@ -362,11 +363,20 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe The postMessage(|message|, |transfer|) method *must* run these steps: + 1. Let |options| be «[ "transfer" → |transfer| ]». + 1. Invoke {{ServiceWorker/postMessage(message, options)}} with |message| and |options| as the arguments. + + +
+

{{ServiceWorker/postMessage(message, options)}}

+ + The postMessage(|message|, |options|) method *must* run these steps: + 1. If the {{ServiceWorker/state}} attribute value of the context object is {{"redundant"}}, [=throw=] an "{{InvalidStateError}}" {{DOMException}}. 1. Let |serviceWorker| be the [=/service worker=] represented by the context object. 1. Invoke Run Service Worker algorithm with |serviceWorker| as the argument. 1. Let |incumbentSettings| be the incumbent settings object, and |incumbentGlobal| its [=environment settings object/global object=]. - 1. Let |serializeWithTransferResult| be StructuredSerializeWithTransfer(|message|, |transfer|). Rethrow any exceptions. + 1. Let |serializeWithTransferResult| be StructuredSerializeWithTransfer(|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|:
@@ -982,7 +992,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<object> transfer = []); + void postMessage(any message, sequence<object> transfer); + void postMessage(any message, optional PostMessageOptions options); }; [Exposed=ServiceWorker] @@ -1051,10 +1062,19 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe The postMessage(|message|, |transfer|) method *must* run these steps: + 1. Let |options| be «[ "transfer" → |transfer| ]». + 1. Invoke {{Client/postMessage(message, options)}} with |message| and |options| as the arguments. +
+ +
+

{{Client/postMessage(message, options)}}

+ + The postMessage(|message|, |options|) method *must* run these steps: + 1. Let |sourceSettings| be the context object's relevant settings object. 1. Let |destination| be the {{ServiceWorkerContainer}} object whose [=ServiceWorkerContainer/service worker client=] is the context object's [=Client/service worker client=], or null if no match is found. 1. If |destination| is null, throw an "{{InvalidStateError}}" {{DOMException}}. - 1. Let |serializeWithTransferResult| be StructuredSerializeWithTransfer(|message|, |transfer|). Rethrow any exceptions. + 1. Let |serializeWithTransferResult| be StructuredSerializeWithTransfer(|message|, |options|.transfer). Rethrow any exceptions. 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=].