From ea3190fef912d3a0a3a7514546233ed96ed70c98 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 13 Jul 2020 12:18:22 -0400 Subject: [PATCH] Check BroadcastChannel origin against creation-time current ...instead of against the creation-time incumbent. This helps with #1430, and allows a good amount of simplification as we no longer have to track the "BroadcastChannel settings object" separately from the relevant settings object. This also modernizes and cleans up the BroadcastChannel section editorially, and adds messageerror events to the garbage collection considerations. --- source | 99 +++++++++++++++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/source b/source index c84943b108d..ccaffd303ce 100644 --- a/source +++ b/source @@ -98179,88 +98179,79 @@ interface BroadcastChannel : EventTarget {
-

A BroadcastChannel object has a channel name, a - BroadcastChannel settings object, and a A BroadcastChannel object has a channel name and a closed flag.

-

The BroadcastChannel() constructor, when - invoked, must create and return a BroadcastChannel object whose channel - name is the constructor's first argument, whose BroadcastChannel - settings object is the incumbent settings object, and whose closed flag is false.

- -

The name attribute must return the - channel name.

- -

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

+

The new BroadcastChannel(name) + constructor steps are:

    -
  1. Let source be this BroadcastChannel.

  2. +
  3. Set this's channel name to name.

  4. -
  5. Let sourceSettings be source's BroadcastChannel - settings object.

  6. +
  7. Set this's closed flag + to false.

  8. +
-
  • If source's closed flag - is true, then throw an "InvalidStateError" DOMException.

  • +

    The name getter steps are to return + this's channel name.

    -
  • Let sourceChannel be source's channel name.

  • +

    The postMessage(message) method + steps are:

    -
  • Let targetRealm be an implementation-defined Realm.

  • +
      +
    1. If this's closed flag + is true, then throw an "InvalidStateError" + DOMException.

    2. Let serialized be StructuredSerialize(message). Rethrow any exceptions.

    3. +
    4. Let sourceOrigin be this's relevant settings object's + origin.

    5. +
    6. Let destinations be a list of BroadcastChannel objects that match the following criteria:

      • -

        Their BroadcastChannel settings object specifies either:

        +

        Their relevant global object is either:

          -
        • a global object that is a - Window object whose associated +

        • a Window object whose associated Document is fully active, or

        • -
        • a global object that is a - WorkerGlobalScope object whose

          a WorkerGlobalScope object whose closing flag is false and whose worker is not a suspendable worker.

      • -
      • Their BroadcastChannel settings object's

        Their relevant settings object's origin is same origin with - sourceSettings's origin.

      • + sourceOrigin.

        -
      • Their channel name is sourceChannel.

      • +
      • Their channel name is this's channel + name.

    7. Remove source from destinations.

    8. Sort destinations such that all BroadcastChannel objects whose - BroadcastChannel settings - objects specify the same responsible event loop are sorted in creation - order, oldest first. (This does not define a complete ordering. Within this constraint, user - agents may sort the list in any implementation-defined manner.)

    9. + relevant agents are the same are sorted in creation order, + oldest first. (This does not define a complete ordering. Within this constraint, user agents may + sort the list in any implementation-defined manner.)

    10. -

      For each BroadcastChannel object destination in - destinations, queue a task on the DOM manipulation task - source of destination's relevant agent's event loop that runs the following steps. If that event - loop is a window event loop, then the task's - document must be set to destination's - BroadcastChannel settings object's responsible document.

      +

      For each destination in destinations, queue a global task + on the DOM manipulation task source given destination's relevant + global object to perform the following steps:

      1. If destination's closed - flag is true, then return.

      2. + flag is true, then abort these steps.

      3. Let targetRealm be destination's relevant Realm.

      4. @@ -98273,8 +98264,8 @@ interface BroadcastChannel : EventTarget { event named messageerror at destination, using MessageEvent, with the origin attribute initialized to the serialization of sourceSettings's origin, and then return.

        + data-x="serialization of an origin">serialization of sourceOrigin, and then + abort these steps.

      5. Fire an event named BroadcastChannel : EventTarget { MessageEvent, with the data attribute initialized to data and the origin attribute initialized to the serialization of - sourceSettings's origin.

      6. + sourceOrigin.

    While a BroadcastChannel object whose closed flag is false has an event listener - registered for message events, there must be a strong - reference from global object specified by - the BroadcastChannel object's BroadcastChannel settings - object to the BroadcastChannel object itself.

    + registered for message or messageerror events, there must be a strong reference from the + BroadcastChannel object's relevant global object to the + BroadcastChannel object itself.

    -

    The close() method must set the - closed flag of the - BroadcastChannel object on which it was invoked to true.

    +

    The close() method steps are to set + this's closed flag to true.

    + +

    Authors are strongly encouraged to explicitly close BroadcastChannel objects when they are no longer needed, so that they can be garbage collected. Creating many @@ -98306,6 +98297,8 @@ interface BroadcastChannel : EventTarget { continue to live for as long as they have an event listener (or until their page or worker is closed).

    +
    +

    The following are the event handlers (and their corresponding