Skip to content

Commit 8b0b7dd

Browse files
authored
Merge pull request #230 from WICG/yao-spec-refactor-set-append-into-dedicated-db-algo
[spec] Refactor set() and append() into dedicated database algorithms
2 parents 48acd25 + 491dffd commit 8b0b7dd

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

spec.bs

+34-25
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ When {{Worklet/addModule()}} is called for a worklet, it will run [=check if add
322322
- For creating a worklet, |environment| is the [=environment settings object=] associated with the {{Window}} that created the worklet, and |origin| is the module script url's [=url/origin=].
323323
- For running operations on a worklet (from a {{Window}}), |environment| is the [=environment settings object=] associated with the {{Window}} that created the worklet, and |origin| is the worklet's [=global scopes=][0]'s [=global object/realm=]'s [=realm/settings object=]'s [=environment settings object/origin=].
324324
- For [[#setter]], |environment| is either the current context (when called from a {{Window}}) or the [=environment settings object=] associated with the {{Window}} that created the worklet (when called from a {{SharedStorageWorkletGlobalScope}}), and |origin| is |environment|'s [=environment settings object/origin=].
325-
- For {{SharedStorage/get()}} invoked from a {{Window}} (which can only succeed in a [=fenced frame=]), |environment| is the current context, and |origin| is |environment|'s [=environment settings object/origin=].
325+
- For {{SharedStorage/get()}} invoked from a {{Window}} (which can only succeed in a [=fenced frame=]), |environment| is the current context, and |origin| is |environment|'s [=environment settings object/origin=].
326326
- For [[#ss-fetch-algo]], |environment| is the request's [=request/window=], and |origin| is the request's [=request/current URL=]'s [=url/origin=].
327327
- For [[#ss-fetch-algo]], for {{SharedStorage/createWorklet()}} called with a cross-origin worklet script using the <var ignore=''>dataOrigin</var> option with value `"script-origin"` (which would result in a worklet where [=SharedStorageWorklet/has cross-origin data origin=] is true), and for {{SharedStorageWorklet/selectURL()}} and {{SharedStorageWorklet/run()}} that operate on a worklet where [=SharedStorageWorklet/has cross-origin data origin=] is true, |allowedInOpaqueOriginContext| is true. For other methods, |allowedInOpaqueOriginContext| is false.
328328
</div>
@@ -1295,7 +1295,7 @@ The Shared Storage API will integrate into the [=Storage Model|Storage API=] as
12951295

12961296
[=User agents=] may specify a <dfn>default entry lifetime</dfn>, the default [=duration=] between when an [=shared storage database/entry=] is [=shared storage database/store an entry in the database|stored=] and when it expires. If the [=user agent=] specifies a [=default entry lifetime=], then it should have a timer periodically [=shared storage database/purge expired entries from the database=].
12971297

1298-
## The [=Shared Storage Database|Database=] Algorithms ## {#database-algorithms}
1298+
## The Core [=Shared Storage Database|Database=] Algorithms ## {#core-database-algorithms}
12991299

13001300
<div algorithm>
13011301
To <dfn for="shared storage database">store an entry in the database</dfn>, given a [=shared storage database/shared storage database queue=] |queue|, a [=storage proxy map=] |databaseMap|, an [=environment settings object=] |environment|, a [=entry/key=] |key|, and a [=value struct/value=] |value|, run the following steps on |queue|:
@@ -1386,6 +1386,35 @@ The Shared Storage API will integrate into the [=Storage Model|Storage API=] as
13861386
1. Otherwise, return false.
13871387
</div>
13881388

1389+
## The Specialized [=Shared Storage Database|Database=] Algorithms ## {#specialized-database-algorithms}
1390+
1391+
These algorithms, unlike the core algorithms in [[#core-database-algorithms]], either accept parameters with more specialized heuristics, or employ multi-step processes, or both, to handle more complex database operations.
1392+
1393+
<div algorithm>
1394+
1395+
To <dfn for="shared storage database">set an entry in the database</dfn>, given a [=shared storage database/shared storage database queue=] |queue|, a [=storage proxy map=] |databaseMap|, an [=environment settings object=] |environment|, a [=entry/key=] |key|, a [=value struct/value=] |value|, and a [=/boolean=] |ignoreIfPresent|, run the following steps on |queue|:
1396+
1397+
1. If |ignoreIfPresent|:
1398+
1. Let |currentValue| be the result of running [=shared storage database/retrieve an entry from the database=] with |queue|, |databaseMap|, |environment|, and |key|.
1399+
1. If |currentValue| is failure, then return false.
1400+
1. If |currentValue| is not undefined, then return true.
1401+
1. Return the result of running [=shared storage database/store an entry in the database=] with |queue|, |databaseMap|, |environment|, |key|, and |value|.
1402+
</div>
1403+
1404+
<div algorithm>
1405+
1406+
To <dfn for="shared storage database">append an entry in the database</dfn>, given a [=shared storage database/shared storage database queue=] |queue|, a [=storage proxy map=] |databaseMap|, an [=environment settings object=] |environment|, a [=entry/key=] |key|, and a [=value struct/value=] |value|, run the following steps on |queue|:
1407+
1408+
1. Let |currentValue| be the result of running [=shared storage database/retrieve an entry from the database=] with |queue|, |databaseMap|, |environment|, and |key|.
1409+
1. If |currentValue| is failure, then return false.
1410+
1. If |currentValue| is not undefined:
1411+
1. Let |list| be a new [=/list=].
1412+
1. [=list/Append=] |currentValue| to |list|.
1413+
1. [=list/Append=] |value| to |list|.
1414+
1. Set |value| to the result of running [=string/concatenate=] on |list|.
1415+
1. Return the result of running [=shared storage database/store an entry in the database=] with |queue|, |databaseMap|, |environment|, |key|, and |value|.
1416+
</div>
1417+
13891418

13901419
Extension to the {{Window}} interface {#window-extension}
13911420
=====================================================
@@ -1498,7 +1527,7 @@ A {{SharedStorageDeleteMethod}} has the following associated fields:
14981527
</div>
14991528

15001529
<div algorithm="SharedStorageAppendMethod">
1501-
1530+
15021531
The <dfn constructor for="SharedStorageAppendMethod" lt="SharedStorageAppendMethod(key, value)">new SharedStorageAppendMethod(|key|, |value|, |options|)</dfn> constructor steps are:
15031532

15041533
1. Let |globalObject| be the [=current realm=]'s [=global object=].
@@ -1758,15 +1787,7 @@ Note: The [=determine if a navigable has fully revoked network=] algorithm ensur
17581787
1. Let |realm| be the [=current realm=].
17591788
1. Let |onLockGrantedCallback| be an algorithm to perform the following steps:
17601789
1. [=Enqueue the following steps=] on |queue|:
1761-
1. If |options|["`ignoreIfPresent`"] is true:
1762-
1. Let |currentValue| be the result of running [=shared storage database/retrieve an entry from the database=] with |queue|, |databaseMap|, |environment|, and |key|.
1763-
1. If |currentValue| is failure and if |globalObject| is a {{SharedStorageWorkletGlobalScope}}:
1764-
1. [=Queue a global task=] on the [=DOM manipulation task source=], given |realm|'s [=global object=], to [=reject=] |promise| with a {{TypeError}}.
1765-
1. Abort these steps.
1766-
1. If |currentValue| is not undefined:
1767-
1. [=Queue a global task=] on the [=DOM manipulation task source=], given |realm|'s [=global object=], to [=resolve=] |promise| with undefined.
1768-
1. Abort these steps.
1769-
1. Let |result| be the result of running [=shared storage database/store an entry in the database=] with |queue|, |databaseMap|, |environment|, |key|, and |value|.
1790+
1. Let |result| be the result of running [=shared storage database/set an entry in the database=] with |queue|, |databaseMap|, |environment|, |key|, |value|, and |options|["`ignoreIfPresent`"].
17701791
1. If |result| is false and if |globalObject| is a {{SharedStorageWorkletGlobalScope}}:
17711792
1. [=Queue a global task=] on the [=DOM manipulation task source=], given |realm|'s [=global object=], to [=reject=] |promise| with a {{TypeError}}.
17721793
1. Abort these steps.
@@ -1800,19 +1821,7 @@ Note: The [=determine if a navigable has fully revoked network=] algorithm ensur
18001821
1. Let |realm| be the [=current realm=].
18011822
1. Let |onLockGrantedCallback| be an algorithm to perform the following steps:
18021823
1. [=Enqueue the following steps=] on |queue|:
1803-
1. Let |currentValue| be the result of running [=shared storage database/retrieve an entry from the database=] with |queue|, |databaseMap|, |environment|, and |key|.
1804-
1. If |currentValue| is failure:
1805-
1. If |globalObject| is a {{Window}}:
1806-
1. [=Queue a global task=] on the [=DOM manipulation task source=], given |realm|'s [=global object=], to [=resolve=] |promise| with undefined.
1807-
1. Else:
1808-
1. [=Queue a global task=] on the [=DOM manipulation task source=], given |realm|'s [=global object=], to [=reject=] |promise| with a {{TypeError}}.
1809-
1. Abort these steps.
1810-
1. If |currentValue| is not undefined:
1811-
1. Let |list| be a new [=/list=].
1812-
1. [=list/Append=] |currentValue| to |list|.
1813-
1. [=list/Append=] |value| to |list|.
1814-
1. Set |value| to the result of running [=string/concatenate=] on |list|.
1815-
1. Let |result| be the result of running [=shared storage database/store an entry in the database=] with |queue|, |databaseMap|, |environment|, |key|, and |value|.
1824+
1. Let |result| be the result of running [=shared storage database/append an entry in the database=] with |queue|, |databaseMap|, |environment|, |key|, and |value|.
18161825
1. If |result| is false and if |globalObject| is a {{SharedStorageWorkletGlobalScope}}:
18171826
1. [=Queue a global task=] on the [=DOM manipulation task source=], given |realm|'s [=global object=], to [=reject=] |promise| with a {{TypeError}}.
18181827
1. Abort these steps.

0 commit comments

Comments
 (0)