From c6ffb89942c33aa9c571c16090bda2f0123d0f23 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 13 Apr 2017 13:36:23 +0200 Subject: [PATCH] Define messageerror The messageerror event is used when deserialization fails. E.g., when an ArrayBuffer object cannot be allocated. This also removes StructuredCloneWithTransfer as deserializing errors now need to be handled on their own. Fixes part of #2260 and fixes #935. --- source | 178 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 103 insertions(+), 75 deletions(-) diff --git a/source b/source index 99ef71660f1..076388991c6 100644 --- a/source +++ b/source @@ -8566,19 +8566,6 @@ o.myself = o; -

StructuredCloneWithTransfer ( value, - transferList, targetRealm )

- -
    -
  1. Let serializeWithTransferResult be ? - StructuredSerializeWithTransfer(value, transferList).

  2. - -
  3. Return ? - StructuredDeserializeWithTransfer(serializeWithTransferResult, - targetRealm).

  4. -
-

Performing serialization and transferring from other specifications

@@ -8586,15 +8573,6 @@ o.myself = o; some guidance on when each abstract operation is typically useful, with examples.

-
StructuredCloneWithTransfer
-
-

Cloning a value into a known target JavaScript Realm, with a transfer list.

- -

window.postMessage() uses - StructuredCloneWithTransfer to allow cloning and transferring values between - different globals.

-
-
StructuredSerializeWithTransfer
StructuredDeserializeWithTransfer
@@ -8646,18 +8624,17 @@ o.myself = o;

Call sites that are not invoked as a result of author code synchronously calling into a user agent method must take care to properly prepare to run script and prepare to - run a callback before invoking StructuredCloneWithTransfer, - StructuredSerialize, or StructuredSerializeWithTransfer abstract - operations, if they are being performed on arbitrary objects. This is necessary because the - serialization process can invoke author-defined accessors as part of its final deep-serialization - steps, and these accessors could call into operations that rely on the entry and before invoking StructuredSerialize or + StructuredSerializeWithTransfer abstract operations, if they are being performed on + arbitrary objects. This is necessary because the serialization process can invoke author-defined + accessors as part of its final deep-serialization steps, and these accessors could call into + operations that rely on the entry and incumbent concepts being properly set up.

window.postMessage() performs - StructuredCloneWithTransfer on its arguments, but is careful to do so immediately, - inside the synchronous portion of its algorithm. Thus it is able to use the structured cloning - algorithms without needing to prepare to run script and prepare to run a + StructuredSerialize on its arguments, but is careful to do so immediately, inside the + synchronous portion of its algorithm. Thus it is able to use the structured cloning algorithms + without needing to prepare to run script and prepare to run a callback.

In contrast, a hypothetical API that used StructuredSerialize to @@ -14904,6 +14881,7 @@ c-end = "-->"

onhashchange
onlanguagechange
onmessage
+
onmessageerror
onoffline
ononline
onpagehide
@@ -89885,6 +89863,7 @@ typedef OnBeforeUnloadEventHandlerNonNull? OnBeforeUnloadEvent onhashchange hashchange onlanguagechange languagechange onmessage message + onmessageerror messageerror onoffline offline ononline online onpagehide pagehide @@ -90009,6 +89988,7 @@ interface WindowEventHandlers { attribute EventHandler onhashchange; attribute EventHandler onlanguagechange; attribute EventHandler onmessage; + attribute EventHandler onmessageerror; attribute EventHandler onoffline; attribute EventHandler ononline; attribute EventHandler onpagehide; @@ -95498,37 +95478,57 @@ function receiver(e) { -
  • Let cloneRecord be StructuredCloneWithTransfer(message, - transfer, targetRealm). Rethrow any exceptions.

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

  • + +
  • +

    Queue a task on the posted message task source to run the + following steps:

    -
  • Let messageClone be cloneRecord.[[Deserialized]].

  • +
      +
    1. If the targetOrigin argument is not a single literal U+002A ASTERISK character + (*) and targetWindow's associated + Document's origin is not same origin with + targetOrigin, then abort these steps.

    2. + +
    3. Let origin be the Unicode + serialization of incumbentSettings's origin.

    4. -
    5. Let newPorts be a new frozen array consisting of all - MessagePort objects in cloneRecord.[[TransferredValues]], if any, - maintaining their relative order.

    6. +
    7. Let source be the WindowProxy object's corresponding to + incumbentSettings's global + object (a Window object).

    8. -
    9. Return, but continue running these steps in in parallel.

    10. +
    11. +

      Let deserializeRecord be + StructuredDeserializeWithTransfer(serializeWithTransferResult, + targetRealm).

      + +

      If this throws an exception, fire an event named + messageerror at targetWindow, using + MessageEvent, with the origin + attribute initialized to origin and the source attribute initialized to source, and + then abort these steps.

      +
    12. -
    13. If the targetOrigin argument is not a single literal U+002A ASTERISK character - (*) and targetWindow's associated - Document's origin is not same origin with - targetOrigin, then abort these steps.

    14. +
    15. Let messageClone be deserializeRecord.[[Deserialized]].

    16. -
    17. Queue a task on the posted message task source to fire an event named message at targetWindow, using - MessageEvent, with the data attribute - initialized to messageClone, the origin - attribute initialized to the Unicode - serialization of incumbentSettings's origin, the source attribute initialized to the - WindowProxy object's corresponding incumbentSettings's global object (a Window object), and - the ports attribute initialized to - newPorts.

    18. +
    19. Let newPorts be a new frozen array consisting of all + MessagePort objects in deserializeRecord.[[TransferredValues]], if any, + maintaining their relative order.

    20. +
    21. Fire an event named message at targetWindow, using + MessageEvent, with the origin + attribute initialized to origin, the source attribute initialized to source, the + data attribute initialized to + messageClone, and the ports attribute + initialized to newPorts.

    22. +
    + @@ -95811,6 +95811,7 @@ interface MessagePort : EventTarget { // event handlers attribute EventHandler onmessage; + attribute EventHandler onmessageerror; }; @@ -96030,11 +96031,15 @@ interface MessagePort : EventTarget {
  • Let targetRealm be finalTargetPort's relevant Realm.

  • -
  • Let deserializeRecord be - StructuredDeserializeWithTransfer(serializeWithTransferResult, - targetRealm).

  • - +
  • +

    Let deserializeRecord be + StructuredDeserializeWithTransfer(serializeWithTransferResult, + targetRealm).

    + +

    If this throws an exception, fire an event named + messageerror at finalTargetPort, using + MessageEvent, and then abort these steps. +

  • Let messageClone be deserializeRecord.[[Deserialized]].

  • @@ -96042,16 +96047,12 @@ interface MessagePort : EventTarget { MessagePort objects in deserializeRecord.[[TransferredValues]], if any, maintaining their relative order.

    -
  • Let e be the result of creating an event using - MessageEvent in targetRealm.

  • - -
  • Initialize e's type attribute to message, its data - attribute to messageClone, and its ports attribute to newPorts.

  • - -
  • Dispatch e at - finalTargetPort.

  • +
  • Fire an event named message at finalTargetPort, using + MessageEvent, with the data attribute + initialized to messageClone and the ports attribute initialized to + newPorts.

  • @@ -96129,6 +96130,7 @@ interface MessagePort : EventTarget { Event handler Event handler event type onmessage message + onmessageerror messageerror @@ -96215,6 +96217,7 @@ interface BroadcastChannel : EventTarget { void postMessage(any message); void close(); attribute EventHandler onmessage; + attribute EventHandler onmessageerror; };
    @@ -96339,10 +96342,17 @@ interface BroadcastChannel : EventTarget {
  • Let targetRealm be destination's relevant Realm.

  • -
  • Let data be StructuredDeserialize(serialized, - targetRealm).

  • - +
  • +

    Let data be StructuredDeserialize(serialized, + targetRealm).

    + +

    If this throws an exception, then fire an event + named messageerror at destination, using + MessageEvent, with the origin + attribute initialized to the Unicode + serialization of sourceSettings's origin, and then abort these steps.

    +
  • Fire an event named message at destination, using @@ -96393,6 +96403,7 @@ interface BroadcastChannel : EventTarget { Event handler Event handler event type onmessage message + onmessageerror messageerror @@ -96982,6 +96993,7 @@ interface DedicatedWorkerGlobalScope : WorkerGlobalScope void close(); attribute EventHandler onmessage; + attribute EventHandler onmessageerror; };

    DedicatedWorkerGlobalScope objects act as if they had an implicit @@ -97042,6 +97054,7 @@ interface DedicatedWorkerGlobalScope : WorkerGlobalScope Event handler Event handler event type onmessage message + onmessageerror messageerror

    For the purposes of the application cache networking model, a dedicated worker is @@ -97718,6 +97731,7 @@ interface Worker : EventTarget { void postMessage(any message, optional sequence<object> transfer = []); attribute EventHandler onmessage; + attribute EventHandler onmessageerror; }; dictionary WorkerOptions { @@ -97785,6 +97799,7 @@ enum WorkerType { "classic", "module" }; Event handler Event handler event type onmessage message + onmessageerror messageerror

    @@ -114974,6 +114989,7 @@ interface External { onhashchange; onlanguagechange; onmessage; + onmessageerror; onoffline; ononline; onpagehide; @@ -118111,6 +118127,12 @@ interface External { message event handler for Window object Event handler content attribute + + onmessageerror + body + messageerror event handler for Window object + Event handler content attribute + onmousedown HTML elements @@ -119002,6 +119024,12 @@ INSERT INTERFACES HERE Window, EventSource, WebSocket, MessagePort, BroadcastChannel, DedicatedWorkerGlobalScope, Worker, ServiceWorkerContainer Fired at an object when it receives a message + + messageerror + MessageEvent + Window, MessagePort, BroadcastChannel, DedicatedWorkerGlobalScope, Worker, ServiceWorkerContainer + Fired at an object when it receives a message that cannot be deserialized + offline Event