Skip to content

Commit 45bdea5

Browse files
Define Indexed DB as a storage endpoint, use hooks
1 parent 1b311f3 commit 45bdea5

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

index.bs

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spec: ecma-262; urlPrefix: https://tc39.github.io/ecma262/
4343
spec: storage; urlPrefix: https://storage.spec.whatwg.org/
4444
type: dfn
4545
text: storage bucket; url: storage-bucket
46-
text: storage key; url: storage-key
46+
text: storage identifier; url: storage-identifier
4747
</pre>
4848

4949
<style>
@@ -396,14 +396,14 @@ To <dfn>create a sorted name list</dfn> from a [=/list=] |names|, run these step
396396
## Database ## {#database-construct}
397397
<!-- ============================================================ -->
398398

399-
Each [=/storage key=] has an associated set of [=/databases=]. A
399+
Each [=/storage bucket=] has an associated set of [=/databases=]. A
400400
<dfn>database</dfn> has zero or more [=/object stores=] which
401401
hold the data stored in the database.
402402

403403
<div dfn-for=database>
404404

405405
A [=/database=] has a <dfn>name</dfn> which identifies it within a
406-
specific [=/storage key=]. The name is a [=/name=],
406+
specific [=/storage bucket=]. The name is a [=/name=],
407407
and stays constant for the lifetime of the database.
408408

409409
A [=/database=] has a <dfn>version</dfn>. When a database is first
@@ -419,6 +419,17 @@ which is either null or an [=/upgrade transaction=], and is initially null.
419419

420420
</div>
421421

422+
<!-- ============================================================ -->
423+
### Database storage ### {#database-storage}
424+
<!-- ============================================================ -->
425+
426+
Indexed DB is a [=/storage endpoint=], with the [=/storage identifier=] `"indexedDB"`.
427+
428+
A <dfn>pumpkin</dfn> is a [=/struct=] consisting of a <dfn for="pumpkin">queue</dfn> (a [=/connection queue=]) and a <dfn for="pumpkin">database</dfn> (a [=/database=]).
429+
430+
A <dfn>new pumpkin</dfn> is a [=/pumpkin=] whose [=pumpkin/queue=] is an empty [=/connection queue=], and whose [=pumpkin/database=] is null.
431+
432+
422433
<!-- ============================================================ -->
423434
### Database connection ### {#database-connection}
424435
<!-- ============================================================ -->
@@ -465,7 +476,7 @@ it hasn't already been.
465476

466477
A [=/connection=] may be closed by a user agent in exceptional
467478
circumstances, for example due to loss of access to the file system, a
468-
permission change, or clearing of the [=/storage key=]'s storage. If this occurs
479+
permission change, or clearing the [=/storage bucket=]. If this occurs
469480
the user agent must run [=close a database
470481
connection=] with the [=/connection=] and with the <var ignore>forced flag</var> set to true.
471482

@@ -1267,8 +1278,8 @@ An [=request/open request=]'s [=get the parent=] algorithm returns null.
12671278
<!-- ============================================================ -->
12681279

12691280
[=request/Open requests=] are processed in a <dfn>connection queue</dfn>.
1270-
The queue contains all [=request/open requests=] associated with an
1271-
[=/storage key=] and a [=database/name=]. Requests added to the
1281+
The queue contains all [=request/open requests=] associated with
1282+
a [=database/name=] in a [=/storage bucket=]. Requests added to the
12721283
[=/connection queue=] processed in order and each request must run
12731284
to completion before the next request is processed. An open request
12741285
may be blocked on other [=/connections=], requiring those
@@ -2181,7 +2192,7 @@ dictionary IDBDatabaseInfo {
21812192
: |result| = await indexedDB . {{IDBFactory/databases()|databases}}()
21822193
::
21832194
Returns a promise which resolves to a list of objects giving a snapshot
2184-
of the names and versions of databases within the [=/storage key=].
2195+
of the names and versions of databases within the [=/storage bucket=].
21852196

21862197
This API is intended for web applications to introspect the use of databases,
21872198
for example to clean up from earlier versions of a site's code. Note that
@@ -2198,15 +2209,14 @@ The <dfn method for=IDBFactory>open(|name|, |version|)</dfn> method steps are:
21982209

21992210
1. Let |environment| be [=/this=]'s [=/relevant settings object=].
22002211

2201-
1. Let |storageKey| be the result of running [=obtain a storage key=] given |environment|.
2202-
If failure is returned, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}} and abort these steps.
2212+
1. Let |map| be the result of [=/obtaining a local storage bottle map=] with |environment| and `"indexedDB"`. If this returns failure, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}} and abort these steps.
22032213

22042214
1. Let |request| be a new [=request/open request=].
22052215

22062216
1. Run these steps [=in parallel=]:
22072217

22082218
1. Let |result| be the result of
2209-
[=/opening a database connection=], with |storageKey|,
2219+
[=/opening a database connection=], with |map|,
22102220
|name|, |version| if given and undefined
22112221
otherwise, and |request|.
22122222

@@ -2268,15 +2278,14 @@ The <dfn method for=IDBFactory>deleteDatabase(|name|)</dfn> method steps are:
22682278

22692279
1. Let |environment| be [=/this=]'s [=/relevant settings object=].
22702280

2271-
1. Let |storageKey| be the result of running [=obtain a storage key=] given |environment|.
2272-
If failure is returned, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}} and abort these steps.
2281+
1. Let |map| be the result of [=/obtaining a local storage bottle map=] with |environment| and `"indexedDB"`. If this returns failure, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}} and abort these steps.
22732282

22742283
1. Let |request| be a new [=request/open request=].
22752284

22762285
1. Run these steps [=in parallel=]:
22772286

22782287
1. Let |result| be the result of
2279-
[=/deleting a database=], with |storageKey|,
2288+
[=/deleting a database=], with |map|,
22802289
|name|, and |request|.
22812290

22822291
1. Set |request|'s [=request/processed flag=] to true.
@@ -2322,22 +2331,16 @@ The <dfn method for=IDBFactory>databases()</dfn> method steps are:
23222331

23232332
1. Let |environment| be [=/this=]'s [=/relevant settings object=].
23242333

2325-
1. Let |storageKey| be the result of running [=obtain a storage key=] given |environment|.
2326-
If failure is returned, then return [=/a promise rejected with=] a "{{SecurityError}}" {{DOMException}}
2327-
23282334
1. Let |p| be [=/a new promise=].
23292335

23302336
1. Run these steps [=in parallel=]:
23312337

2332-
1. Let |databases| be the [=/set=] of [=/databases=] in |storageKey|.
2333-
If this cannot be determined for any reason, then [=/reject=] |p| with
2334-
an appropriate error (e.g. an "{{UnknownError}}" {{DOMException}})
2335-
and terminate these steps.
2336-
2337-
1. Let |result| be a new [=/list=].
2338+
1. Let |map| be the result of [=/obtaining a local storage bottle map=] with |environment| and `"indexedDB"`. If this returns failure, then [=/reject=] |p| with a "{{SecurityError}}" {{DOMException}} and terminate these steps.
23382339

2339-
1. [=set/For each=] |db| of |databases|:
2340+
1. [=map/For each=] |pumpkin| of |map|'s [=map/values=]:
23402341

2342+
1. Let |db| be |pumpkin|'s [=pumpkin/database=].
2343+
1. If |db| is null, then [=iteration/continue=].
23412344
1. Let |info| be a new {{IDBDatabaseInfo}} dictionary.
23422345
1. Set |info|'s {{IDBDatabaseInfo/name}} dictionary member to |db|'s [=database/name=].
23432346
1. Set |info|'s {{IDBDatabaseInfo/version}} dictionary member to |db|'s [=database/version=].
@@ -4898,23 +4901,24 @@ NOTE:
48984901

48994902
<div algorithm>
49004903

4901-
To <dfn>open a database connection</dfn> with |storageKey| which requested the [=/database=] to be opened, a database |name|, a database |version|, and a |request|, run these steps:
4904+
To <dfn>open a database connection</dfn> with |map|, a database |name|, a database |version|, and a |request|, run these steps:
49024905

4903-
1. Let |queue| be the [=/connection queue=] for |storageKey| and |name|.
4906+
1. If |map|\[|name|] does not [=map/exist=], then set |map|\[|name|] to a [=/new pumpkin=].
4907+
4908+
1. Let |queue| be |map|\[|name|]'s [=pumpkin/queue=].
49044909

49054910
1. Add |request| to |queue|.
49064911

49074912
1. Wait until all previous requests in |queue| have been processed.
49084913

4909-
1. Let |db| be the [=/database=] [=database/named=] |name| in
4910-
|storageKey|, or null otherwise.
4914+
1. Let |db| be |map|\[|name|]'s [=pumpkin/database=].
49114915

49124916
1. If |version| is undefined, let |version| be 1 if |db| is null, or
49134917
|db|'s [=database/version=] otherwise.
49144918

49154919
1. If |db| is null, let |db| be a new [=/database=] with
49164920
[=database/name=] |name|, [=database/version=] 0 (zero), and with
4917-
no [=/object stores=]. If this fails for any reason, return an
4921+
no [=/object stores=], and [=map/set=] |map|\[|name|]'s [=pumpkin/database=] to |db|. If this fails for any reason, then return an
49184922
appropriate error (e.g. a "{{QuotaExceededError}}" or
49194923
"{{UnknownError}}" {{DOMException}}).
49204924

@@ -4993,7 +4997,7 @@ optional |forced flag|, run these steps:
49934997

49944998
NOTE:
49954999
The {{IDBDatabase/close!!event}} event only fires if the connection closes
4996-
abnormally, e.g. if the [=/storage key=]'s storage is cleared, or there is
5000+
abnormally, e.g. if the [=/storage bucket=] is cleared, or there is
49975001
corruption or an I/O error. If {{IDBDatabase/close()}} is called explicitly
49985002
the event *does not* fire.
49995003

@@ -5019,18 +5023,19 @@ NOTE:
50195023

50205024
<div algorithm>
50215025

5022-
To <dfn>delete a database</dfn> with the |storageKey| that
5023-
requested the [=/database=] to be deleted, a database |name|, and a
5024-
|request|, run these steps:
5026+
To <dfn>delete a database</dfn> with |map|, a database |name|, and a |request|, run these steps:
5027+
5028+
1. If |map|\[|name|] does not [=map/exist=], then set |map|\[|name|] to a [=/new pumpkin=].
50255029

5026-
1. Let |queue| be the [=/connection queue=] for |storageKey| and |name|.
5030+
1. Let |queue| be |map|\[|name|]'s [=pumpkin/queue=].
50275031

50285032
1. Add |request| to |queue|.
50295033

50305034
1. Wait until all previous requests in |queue| have been processed.
50315035

5032-
1. Let |db| be the [=/database=] [=database/named=] |name| in
5033-
|storageKey|, if one exists. Otherwise, return 0 (zero).
5036+
1. If |map|\[|name|]'s [=pumpkin/database=] is null, then return 0 (zero).
5037+
5038+
1. Otherwise, let |db| be |map|\[|name|]'s [=pumpkin/database=].
50345039

50355040
1. Let |openConnections| be the [=/set=] of all [=/connections=]
50365041
associated with |db|.
@@ -5059,7 +5064,7 @@ requested the [=/database=] to be deleted, a database |name|, and a
50595064

50605065
1. Let |version| be |db|'s [=database/version=].
50615066

5062-
1. Delete |db|. If this fails for any reason, return an appropriate
5067+
1. Set |map|\[|name|]'s [=pumpkin/database=] to null. If this fails for any reason, then return an appropriate
50635068
error (e.g. "{{QuotaExceededError}}" or "{{UnknownError}}" {{DOMException}}).
50645069

50655070
1. Return |version|.
@@ -6624,12 +6629,12 @@ user's wish list; or a hostile site could set a user's session
66246629
identifier to a known ID that the hostile site can then use to track
66256630
the user's actions on the victim site.
66266631

6627-
Thus, strictly following the storage key partitioning model described in
6632+
Thus, strictly following the storage partitioning model described in
66286633
this specification is important for user security.
66296634

66306635
If host names or database names are used to construct paths for
66316636
persistence to a file system they must be appropriately escaped to
6632-
prevent an adversary from accessing information from other [=/storage keys=]
6637+
prevent an adversary from accessing information from other [=/storage buckets=]
66336638
using relative paths such as "`../`".
66346639

66356640
## Persistence risks ## {#persistence-risks}
@@ -6716,6 +6721,7 @@ For the revision history of the second edition, see [that document's Revision Hi
67166721
* Specified the {{DOMException}} type for failures when reading a value from the underlying storage in [[#object-store-retrieval-operation]]. (<#423>)
67176722
* Updated [=convert a value to a key=] to return invalid for detached array buffers. (<#417>)
67186723
* Updated {{IDBFactory/open()}} to set its request's [=request/processed flag=] to true.
6724+
* Defined storage partitioning in terms of [[Storage]] primitives.
67196725

67206726
<!-- ============================================================ -->
67216727
# Acknowledgements # {#acknowledgements}

0 commit comments

Comments
 (0)