diff --git a/source b/source index b7d731bcacb..e4d773ecd9c 100644 --- a/source +++ b/source @@ -102361,6 +102361,13 @@ new PaymentRequest(…); // Allowed to use
  • Set document's salvageable state to false.

  • +
  • Let ports be the list of MessagePorts whose relevant global + object's associated Document is + document.

  • + +
  • For each port in ports, disentangle + port.

  • +
  • Run any unloading document cleanup steps for document that are defined by this specification and other applicable specifications.

  • @@ -114575,6 +114582,7 @@ interface MessagePort : EventTarget { // event handlers attribute EventHandler onmessage; attribute EventHandler onmessageerror; + attribute EventHandler onclose; }; dictionary StructuredSerializeOptions { @@ -114669,6 +114677,40 @@ dictionary StructuredSerializeOptions { +

    The disentangle steps, given a MessagePort initiatorPort + which initiates disentangling, are as follows:

    + +
      +
    1. Let otherPort be the MessagePort which initiatorPort + was entangled with.

    2. + +
    3. Assert: otherPort exists.

    4. + +
    5. Disentangle initiatorPort and otherPort, so that they are no longer + entangled or associated with each other.

    6. + +
    7. Fire an event named close at otherPort.

    8. +
    + +
    +

    The close event will be fired even if the port is not + explicitly closed. The cases where this event is dispatched are:

    + + + +

    We only dispatch the event on otherPort because initiatorPort explicitly + triggered the close, its Document no longer exists, or it was already garbage + collected, as described above.

    +
    +

    MessagePort objects are transferable @@ -114829,7 +114871,7 @@ dictionary StructuredSerializeOptions {

    1. Set this's [[Detached]] internal slot value to true.

    2. -
    3. If this is entangled, disentangle it.

    4. +
    5. If this is entangled, disentangle it.


    @@ -114845,6 +114887,7 @@ dictionary StructuredSerializeOptions { onmessage message onmessageerror messageerror + onclose close

    The first time a MessagePort object's StructuredSerializeOptions { -

    Broadcasting to many ports

    - - - -

    Broadcasting to many ports is in principle relatively simple: keep an array of - MessagePort objects to send messages to, and iterate through the array to send a - message. However, this has one rather unfortunate effect: it prevents the ports from being garbage - collected, even if the other side has gone away. To avoid this problem, implement a simple - protocol whereby the other side acknowledges it still exists. If it doesn't do so after a certain - amount of time, assume it's gone, close the MessagePort object, and let it be garbage - collected.

    - -

    Ports and garbage collection

    +

    When a MessagePort object o is garbage collected, if o is + entangled, then the user agent must disentangle + o.

    + +

    When a MessagePort object o is entangled and message or messageerror + event listener is registered, user agents must act as if o's entangled + MessagePort object has a strong reference to o.

    -

    When a MessagePort object o is entangled, user agents must either act - as if o's entangled MessagePort object has a strong reference to - o, or as if o's relevant global object has a strong reference - to o.

    +

    Furthermore, a MessagePort object must not be garbage collected while there + exists an event referenced by a task in a task + queue that is to be dispatched on that MessagePort object, or while the + MessagePort object's port message queue is enabled and not empty.

    + + +
    @@ -114884,20 +114927,10 @@ dictionary StructuredSerializeOptions {

    Of course, if this was to occur on both sides of the channel, then both ports could be garbage collected, since they would not be reachable from live code, despite having a strong reference to - each other.

    + each other. However, if a message port has a pending message, it is not garbage collected.

    -

    Furthermore, a MessagePort object must not be garbage collected while there exists - an event referenced by a task in a task queue that is to be dispatched on that MessagePort - object, or while the MessagePort object's port message queue is enabled - and not empty.

    - - -

    Authors are strongly encouraged to explicitly close MessagePort @@ -139388,8 +139421,8 @@ INSERT INTERFACES HERE close Event - CloseWatcher, dialog elements - Fired at CloseWatcher objects or dialog elements when they are closed via a close request or via web developer code + CloseWatcher, dialog elements, MessagePort + Fired at CloseWatcher objects or dialog elements when they are closed via a close request or via web developer code, or at MessagePort objects when disentangled connect