@@ -7967,13 +7967,24 @@ interface DOMStringList {
7967
7967
7968
7968
7969
7969
7970
-
7971
-
7972
7970
Safe passing of structured data
7973
7971
7972
+ To support passing JavaScript objects,
7973
+ including
platform objects , across
7974
+ realm">realm boundaries, this specification defines the following
7975
+ infrastructure for serializing and deserializing objects, including in some cases
7976
+ transferring the underlying data instead of copying it. Collectively this
7977
+ serialization/deserialization process is known as "structured cloning", although most APIs perform
7978
+ separate serialization and deserialization steps. (With the notable exception being the
7979
+ data-x="dom-structuredClone">structuredClone() method.)
7980
+
7981
+
7982
+
7974
7983
This section uses the terminology and typographic conventions from the JavaScript
7975
7984
specification.
7976
7985
7986
+
7987
+
7977
7988
Serializable objects
7978
7989
7979
7990
Serializable objects support being serialized, and later deserialized, in a way
@@ -7984,6 +7995,8 @@ interface DOMStringList {
7984
7995
Not all objects are serializable objects , and not all aspects of objects that are
7985
7996
serializable objects are necessarily preserved when they are serialized.
7986
7997
7998
+
7999
+
7987
8000
Platform objects can be serializable objects
7988
8001
if their primary interface is decorated with the
7989
8002
data-lt="Serializable" data-x="Serializable">[Serializable]
IDL extended
@@ -8091,6 +8104,8 @@ interface DOMStringList {
8091
8104
However, to better specify the behavior of certain more complex situations, the model was updated
8092
8105
to make the serialization and deserialization explicit.
8093
8106
8107
+
8108
+
8094
8109
Transferable objects
8095
8110
8096
8111
Transferable objects support being transferred across
@@ -8103,6 +8118,8 @@ interface DOMStringList {
8103
8118
Transferring is an irreversible and non-idempotent operation. Once an object has
8104
8119
been transferred, it cannot be transferred, or indeed used, again.
8105
8120
8121
+
8122
+
8106
8123
Platform objects can be transferable objects
8107
8124
if their primary interface is decorated with the
8108
8125
data-lt="Transferable" data-x="Transferable">[Transferable]
IDL extended
@@ -9138,11 +9155,6 @@ o.myself = o;
9138
9155
understood to perform an implicit conversion to the
9139
9156
JavaScript value before invoking these algorithms.
9140
9157
9141
-
9142
- to define a "structured clone" algorithm, and more recently a StructuredClone abstract operation.
9143
- However, in practice all known uses of it were better served by separate serialization and
9144
- deserialization steps, so it was removed.
9145
-
9146
9158
9147
9159
9148
9160
Call sites that are not invoked as a result of author code synchronously calling into a user
@@ -9170,6 +9182,38 @@ o.myself = o;
9170
9182
9171
9183
9172
9184
9185
+
Structured cloning API
9186
+
9187
+
9188
+
result = self.structuredClone
(value [, { transfer
}])
9189
+
9190
+ Takes the input value and returns a deep copy by performing the structured clone algorithm.
9191
+ Transferable objects listed in the
9192
+ data-x="dom-StructuredSerializeOptions-transfer">transfer array are transferred, not
9193
+ just cloned, meaning that they are no longer usable in the input value.
9194
+
9195
+ Throws a "DataCloneError
" DOMException
if any part of
9196
+ the input value is not serializable .
9197
+
9198
+
9199
+
9200
+
9201
+
9202
+
9203
+ data-x="dom-structuredClone">structuredClone(value ,
9204
+ options ) method steps are:
9205
+
9206
+
9207
+
9208
+ StructuredSerializeWithTransfer (value , options ["
9209
+ data-x="dom-StructuredSerializeOptions-transfer">transfer"]).
9210
+
9211
+ Return ? StructuredDeserialize (serialized , this 's
9212
+ relevant Realm ).
9213
+
9214
+
9215
+
9216
+
9173
9217
9174
9218
Semantics, structure, and APIs of HTML documents
9175
9219
@@ -80416,7 +80460,7 @@ interface Window : EventTarget {
80416
80460
Window includes GlobalEventHandlers ;
80417
80461
Window includes WindowEventHandlers ;
80418
80462
80419
- dictionary WindowPostMessageOptions : PostMessageOptions {
80463
+ dictionary WindowPostMessageOptions : StructuredSerializeOptions {
80420
80464
USVString targetOrigin = "/";
80421
80465
};
80422
80466
@@ -94809,6 +94853,9 @@ interface mixin WindowOrWorkerGlobalScope {
94809
94853
// ImageBitmap
94810
94854
Promise<ImageBitmap > createImageBitmap (ImageBitmapSource image, optional ImageBitmapOptions options = {});
94811
94855
Promise<ImageBitmap > createImageBitmap (ImageBitmapSource image, long sx, long sy, long sw, long sh, optional ImageBitmapOptions options = {});
94856
+
94857
+ // structured cloning
94858
+ any structuredClone (any value, optional StructuredSerializeOptions options = {});
94812
94859
};
94813
94860
Window includes WindowOrWorkerGlobalScope ;
94814
94861
WorkerGlobalScope includes WindowOrWorkerGlobalScope ;
@@ -99740,7 +99787,7 @@ function receiver(e) {
99740
99787
and can contain certain data objects such as File
Blob
,
99741
99788
FileList
, and ArrayBuffer
objects.
99742
99789
99743
- Objects listed in the PostMessageOptions-transfer">transfer
member
99790
+ Objects listed in the StructuredSerializeOptions-transfer">transfer
member
99744
99791
of options are transferred, not just cloned, meaning that they are no longer usable
99745
99792
on the sending side.
99746
99793
@@ -99816,7 +99863,7 @@ function receiver(e) {
99816
99863
99817
99864
99818
99865
Let transfer be options ["
99819
- data-x="dom-PostMessageOptions -transfer">transfer"].
99866
+ data-x="dom-StructuredSerializeOptions -transfer">transfer"].
99820
99867
99821
99868
Let serializeWithTransferResult be
99822
99869
StructuredSerializeWithTransfer (message , transfer ). Rethrow
@@ -99892,7 +99939,7 @@ function receiver(e) {
99892
99939
99893
99940
99894
99941
data-x="dom-WindowPostMessageOptions-targetOrigin">targetOrigin" →
99895
- targetOrigin , "PostMessageOptions-transfer">transfer
" →
99942
+ targetOrigin , "StructuredSerializeOptions-transfer">transfer
" →
99896
99943
transfer ]».
99897
99944
99898
99945
Run the window post message steps providing targetWindow ,
@@ -100160,7 +100207,7 @@ interface MessageChannel {
100160
100207
[Exposed=(Window,Worker,AudioWorklet), Transferable ]
100161
100208
interface MessagePort : EventTarget {
100162
100209
undefined postMessage (any message, sequence<object > transfer);
100163
- undefined postMessage (any message, optional PostMessageOptions options = {});
100210
+ undefined postMessage (any message, optional StructuredSerializeOptions options = {});
100164
100211
undefined start ();
100165
100212
undefined close ();
100166
100213
@@ -100169,8 +100216,8 @@ interface MessagePort : EventTarget {
100169
100216
attribute EventHandler onmessageerror ;
100170
100217
};
100171
100218
100172
- dictionary PostMessageOptions {
100173
- sequence<object > PostMessageOptions" data-x="dom-PostMessageOptions -transfer">transfer = [];
100219
+ dictionary StructuredSerializeOptions {
100220
+ sequence<object > StructuredSerializeOptions" data-x="dom-StructuredSerializeOptions -transfer">transfer = [];
100174
100221
};
100175
100222
100176
100223
@@ -100313,7 +100360,7 @@ dictionary PostMessageOptions {
100313
100360
100314
100361
100315
100362
Let transfer be options ["
100316
- data-x="dom-PostMessageOptions -transfer">transfer"].
100363
+ data-x="dom-StructuredSerializeOptions -transfer">transfer"].
100317
100364
100318
100365
If transfer contains this
100319
100366
MessagePort
, then throw a "DataCloneError
"
@@ -100403,7 +100450,8 @@ dictionary PostMessageOptions {
100403
100450
entangled, if any; otherwise let it be null.
100404
100451
100405
100452
100406
- data-x="dom-PostMessageOptions-transfer">transfer" → transfer ]».
100453
+ data-x="dom-StructuredSerializeOptions-transfer">transfer" →
100454
+ transfer ]».
100407
100455
100408
100456
Run the message port post message steps providing targetPort ,
100409
100457
message and options .
@@ -101272,7 +101320,7 @@ interface DedicatedWorkerGlobalScope : WorkerGlobalSc
101272
101320
[Replaceable] readonly attribute DOMString name ;
101273
101321
101274
101322
undefined postMessage (any message, sequence<object > transfer);
101275
- undefined postMessage (any message, optional PostMessageOptions options = {});
101323
+ undefined postMessage (any message, optional StructuredSerializeOptions options = {});
101276
101324
101277
101325
undefined close ();
101278
101326
@@ -101294,10 +101342,8 @@ interface DedicatedWorkerGlobalScope : WorkerGlobalSc
101294
101342
data-x="concept-WorkerGlobalScope-name">name, i.e. the value given to the
101295
101343
Worker
constructor. Primarily useful for debugging.
101296
101344
101297
-
dedicatedWorkerGlobal .postMessage (message [,
101298
- transfer ])
101299
-
dedicatedWorkerGlobal .postMessage (message
101300
- [, { transfer } ])
101345
+
dedicatedWorkerGlobal .postMessage (message [, transfer ])
101346
+
dedicatedWorkerGlobal .postMessage (message [, { transfer } ])
101301
101347
Clones message and transmits it to the Worker
object associated
101302
101348
with dedicatedWorkerGlobal . transfer can be passed as a list of objects
101303
101349
that are to be transferred rather than cloned.
@@ -102007,7 +102053,7 @@ interface Worker : EventTarget {
102007
102053
undefined terminate ();
102008
102054
102009
102055
undefined postMessage (any message, sequence<object > transfer);
102010
- undefined postMessage (any message, optional PostMessageOptions options = {});
102056
+ undefined postMessage (any message, optional StructuredSerializeOptions options = {});
102011
102057
attribute EventHandler onmessage ;
102012
102058
attribute EventHandler onmessageerror ;
102013
102059
};
@@ -102037,7 +102083,7 @@ enum WorkerType { "classic", "module" };
102037
102083
Aborts worker 's associated global environment.
102038
102084
102039
102085
worker .postMessage (message [, transfer ])
102040
-
worker .postMessage (message [, { PostMessageOptions -transfer">transfer } ])
102086
+
worker .postMessage (message [, { StructuredSerializeOptions -transfer">transfer } ])
102041
102087
Clones message and transmits it to worker 's global environment.
102042
102088
transfer can be passed as a list of objects that are to be transferred rather than
102043
102089
cloned.
0 commit comments