forked from whatwg/html
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit 34796af
Breaking: refactor structured clone into serialize/deserialize
This rewrites most of the cloneable and transferable object
infrastructure to better reflect the reality that structured cloning
requires separate serialization and deserialization steps, instead of a
single operation that creates a new object in the target Realm. This is
most evident in the case of MessagePorts, as noted in whatwg#2277. It also
allows us to avoid awkward double-cloning with an intermediate
"user-agent defined Realm", as seen in e.g. history.state or IndexedB;
instead we can simply store the serialized form and later deserialize.
Concretely, this:
* Replaces the concept of cloneable objects with serializable objects.
For platform objects, instead of defining a [[Clone]]() internal
method, serializable platform objects are annotated with the new
[Serializable] IDL attribute, and include serialization and
deserialization steps in their definition.
* Updates the concept of transferable objects. For platform objects,
instead of defining a [[Transfer]]() internal method, transferable
platform objects are annotated with the new [Transferable] IDL
attribute, and include transfer and transfer-receiving steps.
Additionally, the [[Detached]] internal slot for such objects is now
managed more automatically.
* Removes the StructuredClone() abstract operation in favor of separate
StructuredSerialize() and StructuredDeserialize() abstract operations.
In practice we found that performing a structured clone alone is never
necessary in specs. It is always either coupled with a transfer list,
for which StructuredCloneWithTransfer() can be used, or it is best
expressed as separate serialization and deserialization steps.
* Removes IsTransferable() and Transfer() abstract operations. When
defined more properly, these became less useful by themselves, so they
were inlined into the rest of the machinery.
* Introduces StructuredSerialzieWithTransfer() and
StructuredDeserializeWithTransfer(), which can be used by other
specifications which need to define their own postMessage()-style
algorithm but for which StructuredCloneWithTransfer() is not
sufficient.
Closes whatwg#785. Closes whatwg#935. Closes whatwg#2277. Closes whatwg#1162. Sets the stage for
whatwg#936 and whatwg#2260/whatwg#2361.1 parent 57ba68d commit 34796afCopy full SHA for 34796af
Expand file treeCollapse file tree
1 file changed
+1124
-515
lines changed
0 commit comments