From 060b6c36778b8e5b83c4173996bac62a384e595d 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 +++- docs/index.html | 402 ++++++++++++++++++++++++++---------------------- 2 files changed, 242 insertions(+), 188 deletions(-) diff --git a/docs/index.bs b/docs/index.bs index 9ba5deb8..4bbd7664 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -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; @@ -356,11 +357,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|:
@@ -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<object> transfer = []); + void postMessage(any message, sequence<object> transfer); + void postMessage(any message, optional PostMessageOptions options); }; [Exposed=ServiceWorker] @@ -1045,10 +1056,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=]. diff --git a/docs/index.html b/docs/index.html index 623d65c2..941e042e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1213,9 +1213,9 @@ } - + - +