-
Notifications
You must be signed in to change notification settings - Fork 0
Description
You say:
Structured cloning algorithm defines the semantics of copying a well-defined subset of ECMAScript objects between Code Realms.
I think you know what you are talking about, but if so you are misusing the "realm" that that make everything else hard to follow.
An ECMAScript "Vat" (to used Mark Miller's term) is an operating instance of an ECMAScript engine. It consists of a heap of objects (and other values) and a single thread of execution. The objects within a Vat may only primitively references other objects that are within the same Vat. A Vat has one or more (Code) Realms that roughly correspond to an ECMAScript global object and its associated built-in objects. Each ECMAScript function object is associated with a specific Realm. Realms are not in anyway isolated from each other. An object created by or associated with some specific Realm may contain primitive references to objects created by or associated with any other Realm of the same Vat. The Vat's thread of control may freely move back and forth among functions that are associated with different Realms.
Vats are much like Unix processes (prior to the introduction of threads). Different Vats are logically isolated from each other. They do not share a heap, logical address space or thread of control. Objects in a Vat A cannot primitively reference objects in a Vat B and Vat A's thread of control cannot not execute code from Vat B or visa versa. Separate Vats can only exchange or share information by going through some sort of shared communication channel and by encoding data from objects into some sort of serialized data that can be transmitted across such channels.
Structured Clone is a serialization mechanism for serializing and logically duplicating objects(with reasonable fidelity) between Vats. Not all kinds of objects are reasonably serializable or serializable with high fidelity. For example, it is very difficult to serialize an arbitrary ECMAScript function closure object with full semantic fidelity.
Structure Clone is not needed to primitively transfer data between Realms because any ECMAScript function closures can directly reference and manipulate objects that originated in other Realms (There may be platform or application reasons for wanting to logically issolate Realms, but that isn't an ES language level concern).
I think it's very important to not confuse Realms with Vats when talking about Structured Clone. You need to design Structured Clone to work between Vats. In you accomplish that, then the same design can also be applied to logically isolated Realm. The opposite is not necessary true. A Structure Clone design that works between Realms within a single Vat will not necessarily be able to work between independent Vats.