From 32e3822b17be39ad2d6dea96f5c5a6b88cd5c47a Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 2 Mar 2016 11:04:03 +0100 Subject: [PATCH] Make StructuredClone throw if an object is not explicitly cloneable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StructuredClone used to throw for “host objects” (now objects with a [[Clone]] internal method) and objects whose [[Class]] was not “Object” (now objects which have an internal slot other than [[Prototype]] or [[Extensible]]). This commit restores that behavior. This also fixes the invocation of [[Clone]] by passing memory too. This regressed in bfb960c938580c95e77365e614218b952f96375b. This fixes #766. This affects Chrome. Edge and Firefox already do the right thing. --- source | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/source b/source index af244027587..e9766d7cd76 100644 --- a/source +++ b/source @@ -7607,16 +7607,21 @@ interface DOMStringMap { cloneable objects and not all aspects of objects that are cloneable objects are necessarily preserved when cloned.

-

IDL-defined cloneable objects are cloneable objects defined through IDL that have - the following internal method:

+

IDL-defined objects have the following internal method:

[[Clone]] ( targetRealm, memory )

-

IDL-defined clonable objects must define the [[Clone]] internal method such that - it either throws or returns a clone of this, created in targetRealm. It is up to - IDL-defined cloneable objects to define what cloning means for them.

+

Unless specified otherwise, invoking the [[Clone]] internal method must throw a + DataCloneError exception. (By default, IDL-defined objects are not cloneable + objects.)

+ +

IDL-defined cloneable objects are cloneable objects defined through IDL whose + [[Clone]] internal method is specified to run a series of steps. The result of + running those steps must be a thrown exception or a clone of this, created in + targetRealm. It is up to IDL-defined cloneable objects to define what cloning means for + them.

Objects defined in the JavaScript specification are handled by the StructuredClone abstract operation directly.

@@ -7640,11 +7645,15 @@ interface DOMStringMap { +

Whereas all IDL-defined objects have a [[Clone]] internal method, not + all have a [[Detached]] internal slot and a [[Transfer]] internal + method.

+

IDL-defined transferable objects must define the [[Transfer]] internal method such - that it either throws or returns a clone of this, created in targetRealm, with - this's underlying data shared with the return value, and this's - [[Detached]] internal slot value set to true. It is up to IDL-defined transferable - objects to define what transfering means for them.

+ that it either throws an exception or returns a clone of this, created in + targetRealm, with this's underlying data shared with the return value, and + this's [[Detached]] internal slot value set to true. It is up to IDL-defined + transferable objects to define what transfering means for them.

Objects defined in the JavaScript specification are handled by the StructuredCloneWithTransfer abstract operation directly. (Technically, by @@ -7853,17 +7862,26 @@ interface DOMStringMap { +

  • Otherwise, if input has a [[Clone]] internal method, then let + output be ? input.[[Clone]](targetRealm, + memory).

  • +
  • Otherwise, if IsCallable(input) is true, then throw a DataCloneError exception.

  • -
  • Otherwise, if input has an [[ErrorData]] internal slot, then throw a - DataCloneError exception.

  • +
  • +

    Otherwise, if input has any internal slot other than [[Prototype]] or + [[Extensible]], then throw a DataCloneError exception.

    -
  • Otherwise, if input has a [[Clone]] internal method, then let - output be ? input.[[Clone]](targetRealm).

  • +

    For instance, a [[PromiseState]] or [[WeakMapData]] internal slot.

    + -
  • Otherwise, if input is an exotic object, then throw a - DataCloneError exception.

  • +
  • +

    Otherwise, if input is an exotic object, then throw a + DataCloneError exception.

    + +

    For instance, a proxy object.

    +
  • Otherwise: