@@ -28,11 +28,6 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
28
28
urlPrefix: dom.html
29
29
type: interface
30
30
text: Document; url: document
31
- urlPrefix: infrastructure.html
32
- type: abstract-op
33
- text: StructuredClone; url: structuredclone
34
- type: dfn
35
- text: cloneable objects; url: cloneable-objects
36
31
spec: ecma262; urlPrefix: https://tc39.github.io/ecma262/
37
32
type: dfn
38
33
url: sec-algorithm-conventions
@@ -60,6 +55,7 @@ spec: ecma262; urlPrefix: https://tc39.github.io/ecma262/
60
55
text: Promise; url: sec-promise-objects
61
56
text: Realm; url: realm
62
57
text: current Realm; url: current-realm
58
+ text: Record; url: sec-list-and-record-specification-type
63
59
spec: webidl; urlPrefix: https://heycam.github.io/webidl/
64
60
type: dfn
65
61
text: sequence<DOMString>; url: idl-sequence
@@ -566,13 +562,16 @@ transaction=] is running.
566
562
<!-- ============================================================ -->
567
563
568
564
Each record is associated with a <dfn>value</dfn> . User agents must
569
- support any [=cloneable object=] . This includes simple types
565
+ support any [=serializable object=] . This includes simple types
570
566
such as [=String=] primitive values and [=Date=] objects as well as
571
567
[=Object=] and [=Array=] instances, {{File}} objects, {{Blob}}
572
568
objects, {{ImageData}} objects, and so on. Record [=/values=] are
573
569
stored and retrieved by value rather than by reference; later changes
574
570
to a value have no effect on the record stored in the database.
575
571
572
+ Record [=/values=] are [=/Records=] output by the
573
+ <a abstract-op>StructuredSerialize</a> operation.
574
+
576
575
577
576
<!-- ============================================================ -->
578
577
<h3 id=key-construct>Keys</h3>
@@ -783,7 +782,7 @@ from a [=/value=]. A <dfn>valid key path</dfn> is one of:
783
782
</aside>
784
783
785
784
[=/Key path=] values can only be accessed from properties explicitly
786
- copied by <a abstract-op>StructuredClone </a> , as well as the
785
+ copied by <a abstract-op>StructuredSerialize </a> , as well as the
787
786
following type-specific properties:
788
787
789
788
<table class=props>
@@ -2960,9 +2959,17 @@ when invoked, must run these steps:
2960
2959
2961
2960
9. Let |targetRealm| be a user-agent defined [=Realm=] .
2962
2961
2963
- 10. Let |clone| be <a abstract-op>StructuredClone</a> ( |value|, |targetRealm|) .
2962
+ 10. Let |clone| be a [=clone=] of |value| in |targetRealm|.
2964
2963
Rethrow any exceptions.
2965
2964
2965
+ <details class=note>
2966
+ <summary> Why create a copy of the value?</summary>
2967
+ The value must be serialized when stored. Treating it as a copy
2968
+ here allows other algorithms in this specification to treat it as
2969
+ an ECMAScript value, but implementations may optimize this
2970
+ if the difference in behavior is not observable.
2971
+ </details>
2972
+
2966
2973
11. If |store| uses [=in-line keys=] , run these substeps:
2967
2974
2968
2975
1. Let |kpk| be the result of running the steps to [=extract a
@@ -3031,9 +3038,17 @@ when invoked, must run these steps:
3031
3038
3032
3039
9. Let |targetRealm| be a user-agent defined [=Realm=] .
3033
3040
3034
- 10. Let |clone| be <a abstract-op>StructuredClone</a> ( |value|, |targetRealm|) .
3041
+ 10. Let |clone| be a [=clone=] of |value| in |targetRealm|.
3035
3042
Rethrow any exceptions.
3036
3043
3044
+ <details class=note>
3045
+ <summary> Why create a copy of the value?</summary>
3046
+ The value must be serialized when stored. Treating it as a copy
3047
+ here allows other algorithms in this specification to treat it as
3048
+ an ECMAScript value, but implementations may optimize this
3049
+ if the difference in behavior is not observable.
3050
+ </details>
3051
+
3037
3052
11. If |store| uses [=in-line keys=] , run these substeps:
3038
3053
3039
3054
1. Let |kpk| be the result of running the steps to [=extract a
@@ -4895,9 +4910,17 @@ invoked, must run these steps:
4895
4910
4896
4911
7. Let |targetRealm| be a user-agent defined [=Realm=] .
4897
4912
4898
- 8. Let |clone| be <a abstract-op>StructuredClone</a> ( |value|, |targetRealm|) .
4913
+ 8. Let |clone| be a [=clone=] of |value| in |targetRealm|.
4899
4914
Rethrow any exceptions.
4900
4915
4916
+ <details class=note>
4917
+ <summary> Why create a copy of the value?</summary>
4918
+ The value must be serialized when stored. Treating it as a copy
4919
+ here allows other algorithms in this specification to treat it as
4920
+ an ECMAScript value, but implementations may optimize this
4921
+ if the difference in behavior is not observable.
4922
+ </details>
4923
+
4901
4924
9. If the [=effective object store=] of this cursor uses [=in-line
4902
4925
keys=] , run these substeps:
4903
4926
@@ -5766,6 +5789,23 @@ the implementation must run the following steps:
5766
5789
5767
5790
</div>
5768
5791
5792
+ <!-- ============================================================ -->
5793
+ <h3 id=clone-value>Clone a value</h3>
5794
+ <!-- ============================================================ -->
5795
+
5796
+ <div class=algorithm>
5797
+
5798
+ To make a <dfn>clone</dfn> of |value| in |targetRealm|,
5799
+ the implementation must run the following steps:
5800
+
5801
+ 1. Let |serialized| be [=?=] <a abstract-op>StructuredSerialize</a> (|value|).
5802
+
5803
+ 2. Let |clone| be [=?=] <a abstract-op>StructuredDeserialize</a> (|serialized|, |targetRealm|).
5804
+
5805
+ 3. Return |clone|.
5806
+
5807
+ </div>
5808
+
5769
5809
5770
5810
<!-- ============================================================ -->
5771
5811
<h2 id=database-operations>Database operations</h2>
@@ -5777,9 +5817,10 @@ These operations are run by the steps to [=asynchronously execute
5777
5817
a request=] .
5778
5818
5779
5819
<aside class=note>
5780
- Invocations of <a abstract-op>StructuredClone</a> () in the operation steps below
5781
- can be asserted not to throw (as indicated by the [=!=] prefix)
5782
- because they operate only on previously cloned data.
5820
+ Invocations of <a abstract-op>StructuredDeserialize</a> () in the operation
5821
+ steps below can be asserted not to throw (as indicated by the [=!=] prefix)
5822
+ because they operate only on previous output of
5823
+ <a abstract-op>StructuredSerialize</a> ().
5783
5824
</aside>
5784
5825
5785
5826
<!-- ============================================================ -->
@@ -5820,7 +5861,8 @@ follows.
5820
5861
to=] |key|, then remove the [=object-store/record=] from |store| using the
5821
5862
steps to [=delete records from an object store=] .
5822
5863
5823
- 4. Store a record in |store| containing |key| as its key and |value|
5864
+ 4. Store a record in |store| containing |key| as its key and
5865
+ <a abstract-op>StructuredSerialize</a> (|value|)
5824
5866
as its value. The record is stored in the object store's
5825
5867
[=object-store/list of records=] such that the list is sorted
5826
5868
according to the key of the records in [=ascending=] order.
@@ -5903,9 +5945,9 @@ The steps to <dfn>retrieve a value from an object store</dfn> with
5903
5945
5904
5946
2. If |record| was not found, return undefined.
5905
5947
5906
- 3. Let |value | be of |record|'s [=/value=] .
5948
+ 3. Let |serialized | be of |record|'s [=/value=] .
5907
5949
5908
- 4. Return [=!=] <a abstract-op>StructuredClone </a> (|value |, |targetRealm|).
5950
+ 4. Return [=!=] <a abstract-op>StructuredDeserialize </a> (|serialized |, |targetRealm|).
5909
5951
5910
5952
</div>
5911
5953
@@ -5925,8 +5967,8 @@ store</dfn> with |targetRealm|, |store|, |range| and optional |count| are as fol
5925
5967
5926
5968
4. For each |record| in |records|, run these substeps:
5927
5969
5928
- 1. Let |value | be |record|'s [=/value=] .
5929
- 2. Let |entry| be [=!=] <a abstract-op>StructuredClone </a> (|value |, |targetRealm|).
5970
+ 1. Let |serialized | be |record|'s [=/value=] .
5971
+ 2. Let |entry| be [=!=] <a abstract-op>StructuredDeserialize </a> (|serialized |, |targetRealm|).
5930
5972
3. Append |entry| to |list|.
5931
5973
5932
5974
5. Return |list| converted to a [=sequence<any>=] .
@@ -5989,9 +6031,9 @@ with |targetRealm|, |index| and |range| are as follows.
5989
6031
5990
6032
2. If |record| was not found, return undefined.
5991
6033
5992
- 3. Let |value | be |record|'s [=referenced value=] .
6034
+ 3. Let |serialized | be |record|'s [=referenced value=] .
5993
6035
5994
- 4. Return [=!=] <a abstract-op>StructuredClone </a> (|value |, |targetRealm|).
6036
+ 4. Return [=!=] <a abstract-op>StructuredDeserialize </a> (|serialized |, |targetRealm|).
5995
6037
5996
6038
</div>
5997
6039
@@ -6010,8 +6052,8 @@ index</dfn> with |targetRealm|, |index|, |range| and optional |count| are as fol
6010
6052
6011
6053
4. For each |record| in |records|, run these substeps:
6012
6054
6013
- 1. Let |value | be |record|'s [=referenced value=] .
6014
- 2. Let |entry| be [=!=] <a abstract-op>StructuredClone </a> (|value |, |targetRealm|).
6055
+ 1. Let |serialized | be |record|'s [=referenced value=] .
6056
+ 2. Let |entry| be [=!=] <a abstract-op>StructuredDeserialize </a> (|serialized |, |targetRealm|).
6015
6057
3. Append |entry| to |list|.
6016
6058
6017
6059
5. Return |list| converted to a [=sequence<any>=] .
@@ -6285,9 +6327,9 @@ follows.
6285
6327
6286
6328
13. If |cursor|'s [=key only flag=] is unset, run these substeps:
6287
6329
6288
- 1. Let |value | be |found record|'s [=referenced value=] .
6330
+ 1. Let |serialized | be |found record|'s [=referenced value=] .
6289
6331
2. Set |cursor|'s [=cursor/value=] to
6290
- [=!=] <a abstract-op>StructuredClone </a> (|value |, |targetRealm|)
6332
+ [=!=] <a abstract-op>StructuredDeserialize </a> (|serialized |, |targetRealm|)
6291
6333
6292
6334
14. Set |cursor|'s [=got value flag=] .
6293
6335
@@ -6432,7 +6474,7 @@ ECMAScript value or failure, or the steps may throw an exception.
6432
6474
6433
6475
<aside class=note>
6434
6476
Assertions can be made in the above steps because this algorithm is
6435
- only applied to values that are the output of <a abstract-op>StructuredClone </a>
6477
+ only applied to values that are the output of <a abstract-op>StructuredDeserialize </a>
6436
6478
and only access "own" properties.
6437
6479
</aside>
6438
6480
@@ -6480,7 +6522,7 @@ true or false.
6480
6522
6481
6523
<aside class=note>
6482
6524
Assertions can be made in the above steps because this algorithm is
6483
- only applied to values that are the output of <a abstract-op>StructuredClone </a> .
6525
+ only applied to values that are the output of <a abstract-op>StructuredDeserialize </a> .
6484
6526
</aside>
6485
6527
6486
6528
<div class=algorithm>
@@ -6528,7 +6570,7 @@ as follows. The algorithm takes a |value|, a |key| and a |keyPath|.
6528
6570
6529
6571
<aside class=note>
6530
6572
Assertions can be made in the above steps because this algorithm is
6531
- only applied to values that are the output of <a abstract-op>StructuredClone </a> ,
6573
+ only applied to values that are the output of <a abstract-op>StructuredDeserialize </a> ,
6532
6574
and the steps to [=check that a key could be injected into a value=] have
6533
6575
been run.
6534
6576
</aside>
@@ -6961,7 +7003,7 @@ basic serialization concerns, serialized data could encode assumptions
6961
7003
which are not valid in newer versions of the user agent.
6962
7004
6963
7005
A practical example of this is the [=RegExp=] type. The <a
6964
- abstract-op> StructuredClone </a> operation allows cloning [=RegExp=]
7006
+ abstract-op> StructuredSerialize </a> operation allows serializing [=RegExp=]
6965
7007
objects. A typical user agent will compile a regular expression into
6966
7008
native machine instructions, with assumptions about how the input data
6967
7009
is passed and results returned. If this internal state was serialized
@@ -7068,9 +7110,6 @@ document's Revision History</a>.
7068
7110
* Add non-normative documentation for every method.
7069
7111
(<a href="https://github.com/w3c/IndexedDB/issues/110">bug #110</a> )
7070
7112
7071
- * Use [[HTML]] 's <a abstract-op>StructuredClone</a> hook.
7072
- (<a href="https://github.com/w3c/IndexedDB/issues/135">bug #135</a> )
7073
-
7074
7113
* Throw {{SecurityError}} if {{IDBFactory/open()}} or
7075
7114
{{IDBFactory/deleteDatabase()}} is called from an opaque origin.
7076
7115
(<a href="https://github.com/w3c/IndexedDB/issues/148">bug #148</a> )
@@ -7086,6 +7125,10 @@ document's Revision History</a>.
7086
7125
* Fix handling of edge cases in key generation algorithm.
7087
7126
(<a href="https://github.com/w3c/IndexedDB/issues/147">bug #147</a> )
7088
7127
7128
+ * Use [[HTML]] 's <a abstract-op>StructuredSerialize</a> and
7129
+ <a abstract-op>StructuredDeserialize</a> hooks.
7130
+ (<a href="https://github.com/w3c/IndexedDB/issues/170">bug #170</a> )
7131
+
7089
7132
7090
7133
<!-- ============================================================ -->
7091
7134
<h2 id=acknowledgements>Acknowledgements</h2>
0 commit comments