interface StructuredSerializeOptions
Options that control structured serialization operations such as
structuredClone(value, options) and MessagePort.postMessage(message, options).
The optional transfer array lists Transferable objects whose
underlying resources should be moved (transferred) to the receiving side
instead of being cloned. After a successful transfer:
- For an
ArrayBuffer, the original buffer becomes neutered (itsbyteLengthis set to0). - For a
MessagePort, the port becomes unusable on the sending side and future events will arrive only on the transferred port at the receiver.
Validation rules:
- Each transferable may appear only once in the
transferlist. - A
MessagePortcannot be listed together with its counterpart port from the sameMessageChannelin the same transfer operation. - Duplicate or otherwise invalid entries will cause a
DataCloneErrorDOMExceptionto be thrown.
Transferring improves performance for large binary data and allows moving communication endpoints without copying.
Examples #
#
// Transferring an ArrayBuffer (zero-copy for large data)
const buffer = new ArrayBuffer(16);
const cloned = structuredClone(buffer, { transfer: [buffer] });
// After transfer, the original buffer is neutered
console.log(buffer.byteLength); // 0
console.log(cloned.byteLength); // 16
Properties #
#transfer: Transferable[] optional
List of transferable objects whose ownership is moved instead of cloned.