Enum mozjs_sys::jsapi::JS::StructuredCloneScope
source · #[repr(u32)]pub enum StructuredCloneScope {
SameProcess = 1,
DifferentProcess = 2,
DifferentProcessForIndexedDB = 3,
Unassigned = 4,
UnknownDestination = 5,
}
Expand description
Indicates the “scope of validity” of serialized data.
Writing plain JS data produces an array of bytes that can be copied and
read in another process or whatever. The serialized data is Plain Old Data.
However, HTML also supports Transferable
objects, which, when cloned, can
be moved from the source object into the clone, like when you take a
photograph of someone and it steals their soul.
See https://developer.mozilla.org/en-US/docs/Web/API/Transferable.
We support cloning and transferring objects of many types.
For example, when we transfer an ArrayBuffer (within a process), we “detach” the ArrayBuffer, embed the raw buffer pointer in the serialized data, and later install it in a new ArrayBuffer in the destination realm. Ownership of that buffer memory is transferred from the original ArrayBuffer to the serialized data and then to the clone.
This only makes sense within a single address space. When we transfer an ArrayBuffer to another process, the contents of the buffer must be copied into the serialized data. (The original ArrayBuffer is still detached, though, for consistency; in some cases the caller shouldn’t know or care if the recipient is in the same process.)
ArrayBuffers are actually a lucky case; some objects (like MessagePorts) can’t reasonably be stored by value in serialized data – it’s pointers or nothing.
So there is a tradeoff between scope of validity – how far away the serialized data may be sent and still make sense – and efficiency or features. The read and write algorithms therefore take an argument of this type, allowing the user to control those trade-offs.
Variants§
SameProcess = 1
The most restrictive scope, with greatest efficiency and features.
When writing, this means: The caller promises that the serialized data
will not be shipped off to a different process or stored in a
database. However, it may be shipped to another thread. It’s OK to
produce serialized data that contains pointers to data that is safe to
send across threads, such as array buffers. In Rust terms, the
serialized data will be treated as Send
but not Copy
.
When reading, this means: Accept transferred objects and buffers (pointers). The caller promises that the serialized data was written using this API (otherwise, the serialized data may contain bogus pointers, leading to undefined behavior).
Starts from 1 because there used to be a SameProcessSameThread enum value of 0 and these values are encoded into the structured serialization format as part of the SCTAG_HEADER, and IndexedDB persists the representation to disk.
DifferentProcess = 2
When writing, this means we’re writing for an audience in a different process. Produce serialized data that can be sent to other processes, bitwise copied, or even stored as bytes in a database and read by later versions of Firefox years from now. The HTML5 spec refers to this as “ForStorage” as in StructuredSerializeForStorage, though we use DifferentProcess for IPC as well as storage.
Transferable objects are limited to ArrayBuffers, whose contents are copied into the serialized data (rather than just writing a pointer).
When reading, this means: Do not accept pointers.
DifferentProcessForIndexedDB = 3
Handle a backwards-compatibility case with IndexedDB (bug 1434308): when reading, this means to treat legacy SameProcess data as if it were DifferentProcess.
Do not use this for writing; use DifferentProcess instead.
Unassigned = 4
Existing code wants to be able to create an uninitialized JSStructuredCloneData without knowing the scope, then populate it with data (at which point the scope is known.)
UnknownDestination = 5
This scope is used when the deserialization context is unknown. When writing, DifferentProcess or SameProcess scope is chosen based on the nature of the object.
Trait Implementations§
source§impl Clone for StructuredCloneScope
impl Clone for StructuredCloneScope
source§fn clone(&self) -> StructuredCloneScope
fn clone(&self) -> StructuredCloneScope
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for StructuredCloneScope
impl Debug for StructuredCloneScope
source§impl Hash for StructuredCloneScope
impl Hash for StructuredCloneScope
source§impl PartialEq for StructuredCloneScope
impl PartialEq for StructuredCloneScope
source§fn eq(&self, other: &StructuredCloneScope) -> bool
fn eq(&self, other: &StructuredCloneScope) -> bool
self
and other
values to be equal, and is used
by ==
.impl Copy for StructuredCloneScope
impl Eq for StructuredCloneScope
impl StructuralPartialEq for StructuredCloneScope
Auto Trait Implementations§
impl Freeze for StructuredCloneScope
impl RefUnwindSafe for StructuredCloneScope
impl Send for StructuredCloneScope
impl Sync for StructuredCloneScope
impl Unpin for StructuredCloneScope
impl UnwindSafe for StructuredCloneScope
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more