From 089985e86d541b5688e98d9d0281a3ba2fc86e20 Mon Sep 17 00:00:00 2001 From: Dave Tapuska Date: Thu, 5 Jul 2018 13:37:33 -0400 Subject: [PATCH] Add postMessage overloads that provide PostMessageOptions. Fixes issue #3799 --- source | 147 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 118 insertions(+), 29 deletions(-) diff --git a/source b/source index 38faf31d6e4..a26c64cf568 100644 --- a/source +++ b/source @@ -78170,9 +78170,13 @@ interface Window : Eve void print(); void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []); + void postMessage(any message, optional WindowPostMessageOptions options); }; Window includes GlobalEventHandlers; -Window includes WindowEventHandlers; + +dictionary WindowPostMessageOptions : PostMessageOptions { + USVString targetOrigin = "/"; +}; -
  • Let targetWindow be this Window object.

    -
  • Let targetRealm be targetWindow's Realm.

  • @@ -95928,6 +95937,9 @@ function receiver(e) { window, in same-origin cases. See discussion at https://github.com/whatwg/html/issues/1542#issuecomment-233502636 --> +
  • Let targetOrigin be the value of options's targetOrigin member.

  • +
  • If targetOrigin is a single U+002F SOLIDUS character (/), then set targetOrigin to incumbentSettings's origin.

    @@ -95948,6 +95960,9 @@ function receiver(e) {
  • +
  • Let transfer be the value of options's transfer member.

  • +
  • Let serializeWithTransferResult be StructuredSerializeWithTransfer(message, transfer). Rethrow any exceptions.

  • @@ -96001,6 +96016,30 @@ function receiver(e) { +

    The postMessage(message, + options) method, when invoked on a + Window object, must run the following steps:

    +
      +
    1. Let targetWindow be this Window object.

    2. + +
    3. Run the window post message steps providing targetWindow, + message, and options.

    4. +
    + +

    The postMessage(message, + targetOrigin, transfer) method, when invoked on a + Window object, must run the following steps:

    + +
      +
    1. Let targetWindow be this Window object.

    2. + +
    3. Let options be «[ "targetOrigin" → targetOrigin, + "transfer" → transfer ]».

    4. + +
    5. Run the window post message steps providing + targetWindow, message, and options.

    6. +
    + @@ -96276,16 +96315,22 @@ interface MessageChannel {
    [Exposed=(Window,Worker,AudioWorklet), Transferable]
     interface MessagePort : EventTarget {
       void postMessage(any message, optional sequence<object> transfer = []);
    +  void postMessage(any message, PostMessageOptions options);
       void start();
       void close();
     
       // event handlers
       attribute EventHandler onmessage;
       attribute EventHandler onmessageerror;
    +};
    +
    +dictionary PostMessageOptions {
    +  sequence<object> transfer = [];
     };
    port . postMessage(message [, transfer] )
    +
    port . postMessage(message [, options] )

    Posts a message through the channel. Objects listed in transfer are transferred, not just cloned, meaning that they are no longer usable on the sending side.

    @@ -96437,13 +96482,12 @@ interface MessagePort : EventTarget {
    -

    The postMessage(message, - transfer) method, when invoked on a MessagePort object, must - run the following steps:

    +

    The message port post message steps, given a targetPort, message + and options are as follows:

      -
    1. Let targetPort be the port with which this MessagePort is - entangled, if any; otherwise let it be null.

    2. +
    3. Let transfer be the value of options's transfer member.

    4. If transfer contains this MessagePort, then throw a "DataCloneError" @@ -96512,6 +96556,35 @@ interface MessagePort : EventTarget {


      +

      The postMessage(message, + options) method, when invoked on a + MessagePort object must run the following steps:

      +
        +
      1. Let targetPort be the port with which this MessagePort is + entangled, if any; otherwise let it be null.

      2. + +
      3. Run the message port post message steps providing targetPort, + message and options.

      4. +
      + +
      + +

      The postMessage(message, + transfer) method, when invoked on a MessagePort object + must run the following steps:

      + +
        +
      1. Let targetPort be the port with which this MessagePort is + entangled, if any; otherwise let it be null.

      2. + +
      3. Let options be «[ "transfer" → transfer ]».

      4. + +
      5. Run the message port post message steps providing + targetPort, message and options.

      6. +
      + +
      +

      The start() method, when invoked, must enable this MessagePort object's port message queue, if it is not already enabled.

      @@ -97404,6 +97477,7 @@ interface DedicatedWorkerGlobalScope : WorkerGlobalScope [Replaceable] readonly attribute DOMString name; void postMessage(any message, optional sequence<object> transfer = []); + void postMessage(any message, PostMessageOptions options); void close(); @@ -97428,6 +97502,9 @@ interface DedicatedWorkerGlobalScope : WorkerGlobalScope
      dedicatedWorkerGlobal . postMessage(message [, transfer ])
      +
      dedicatedWorkerGlobal . postMessage(message [, + options ])
      Clones message and transmits it to the Worker object associated with dedicatedWorkerGlobal. transfer can be passed as a list of objects that are to be transferred rather than cloned.
      @@ -97444,10 +97521,16 @@ interface DedicatedWorkerGlobalScope : WorkerGlobalScope data-x="concept-WorkerGlobalScope-name">name. Its value represents the name given to the worker using the Worker constructor, used primarily for debugging purposes.

      -

      The postMessage() - method on DedicatedWorkerGlobalScope objects must act as if, when invoked, it - immediately invoked the method of the same name - on the port, with the same arguments, and returned the same return value.

      +

      The postMessage(message [, + transfer] ) and postMessage(message + [,options] ) methods on DedicatedWorkerGlobalScope objects + act as if, when invoked, it immediately invoked the respective postMessage(message [, transfer] + ) and postMessage(message + [,options] ) on the port, with the same arguments, and returned the same return + value.

      To close a worker, given a workerGlobal, run these steps:

      @@ -98139,6 +98222,7 @@ interface Worker : EventTarget { void terminate(); void postMessage(any message, optional sequence<object> transfer = []); + void postMessage(any message, PostMessageOptions options); attribute EventHandler onmessage; attribute EventHandler onmessageerror; }; @@ -98167,7 +98251,8 @@ enum WorkerType { "classic", "module" };
      worker . terminate()
      Aborts worker's associated global environment.
      -
      worker . postMessage(message [, transfer ]) +
      worker . postMessage(message [, transfer ] ) +
      worker . postMessage(message [, options ] )
      Clones message and transmits it to worker's global environment. transfer can be passed as a list of objects that are to be transferred rather than cloned.
      @@ -98186,10 +98271,14 @@ enum WorkerType { "classic", "module" };

      All messages received by that port must immediately be retargeted at the Worker object.

      -

      The postMessage() method on - Worker objects must act as if, when invoked, it immediately invoked the method of the same name on the port, with the same - arguments, and returned the same return value.

      +

      The postMessage(message [, + transfer ] ) and postMessage(message [, options ] + ) methods on Worker objects act as if, when invoked, it immediately + invoked the respective postMessage(message + [, transfer ] ) and postMessage(message [, options + ] ) on the port, with the same arguments, and returned the same return value.