The structured clone algorithm is an algorithm defined by the HTML5 specification for copying complex JavaScript objects. It is used internally when transferring data to and from Workers via postMessage()
or when storing objects with IndexedDB. It builds up a clone by recursing through the input object while maintaining a map of previously visited references in order to avoid infinitely traversing cycles.
Error
and Function
objects cannot be duplicated by the structured clone algorithm; attempting to do so will throw a DATA_CLONE_ERR
exception.DATA_CLONE_ERR
exception.lastIndex
field of RegExp
objects is not preserved.Object type | Notes |
---|---|
All primitive types | However not symbols |
Boolean object | |
String object | |
Date | |
RegExp | The lastIndex field is not preserved. |
Blob | |
File | |
FileList | |
ArrayBuffer | |
ArrayBufferView | This basically means all typed arrays like Int32Array etc. |
ImageData | |
Array | |
Object | This just includes plain objects (e.g. from object literals) |
Map | |
Set |
window.history
window.postMessage()
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm