Skip to main content

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 (its byteLength is set to 0).
  • 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 transfer list.
  • A MessagePort cannot be listed together with its counterpart port from the same MessageChannel in the same transfer operation.
  • Duplicate or otherwise invalid entries will cause a DataCloneError DOMException to 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 #

List of transferable objects whose ownership is moved instead of cloned.

你找到了你需要的东西吗?

隐私政策