Skip to content

Commit

Permalink
use bucket map & update persist() (#71)
Browse files Browse the repository at this point in the history
* Expand usage of bucket map

* remove the

* Use bucket map for clear site data

* short-circuit if bucket is already persistent
  • Loading branch information
ayuishii authored Feb 15, 2023
1 parent cd7b0cf commit 653aa90
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ dictionary StorageBucketOptions {
The <dfn method for="StorageBucketManager">open(|name|, |options|)</dfn> method steps are:

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

1. Let |shelf| be the result of running [=obtain a local storage shelf=] given |environment|.

1. Let |storageKey| be the result of running [=obtain a storage key=] given |environment|.

1. If |storageKey| is failure, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}} and abort these steps.
1. If |shelf| is failure, then [=exception/throw=] an "{{UnknownError}}" {{DOMException}} and abort these steps.

1. Let |p| be [=a new promise=].

1. Run the following steps [=in parallel=]:

1. If the result of [=validate a bucket name=] with |name| is failure, then [=/reject=] |p| with an {{TypeError}} and abort these steps.

1. Let |r| be the result of running [=open a bucket=] with |storageKey|, |name|, and |options|.
1. Let |r| be the result of running [=open a bucket=] with |shelf|, |name|, and |options|.

1. If |r| is failure, then [=reject=] |p| with a {{TypeError}} and abort these steps.

Expand All @@ -95,7 +95,7 @@ The <dfn method for="StorageBucketManager">open(|name|, |options|)</dfn> method

<div algorithm>

To <dfn>open a bucket</dfn> for a |storageKey| given a bucket |name| and optional |options|, run the following steps:
To <dfn>open a bucket</dfn> for a |shelf| given a bucket |name| and optional |options|, run the following steps:

1. Let |expires| be |options|["{{StorageBucketOptions/expires}}"] if it exists, otherwise undefined.

Expand All @@ -113,7 +113,7 @@ To <dfn>open a bucket</dfn> for a |storageKey| given a bucket |name| and optiona

1. If |permission| is "{{PermissionState/granted}}", then set |persisted| to true.

1. Let |bucket| be the [=/storage bucket=] named |name| in |storageKey| or null otherwise.
1. Let |bucket| be |shelf|'s [=bucket map=][|name|] if exists or null otherwise.

1. If |bucket| is non-null and |bucket|'s [=StorageBucket/expiration value=] is less than or equal to now, then:

Expand Down Expand Up @@ -168,17 +168,17 @@ The <dfn method for="StorageBucketManager">delete(|name|)</dfn> method steps are

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

1. Let |storageKey| be the result of running [=obtain a storage key=] given |environment|.
1. Let |shelf| be the result of running [=obtain a local storage shelf=] given |environment|.

1. If |storageKey| is failure, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}} and abort these steps.
1. If |shelf| is failure, then [=exception/throw=] an "{{UnknownError}}" {{DOMException}} and abort these steps.

1. Let |p| be [=a new promise=].

1. Run the following steps [=in parallel=]:

1. If the result of [=validate a bucket name=] with |name| is failure, then [=/reject=] |p| with an {{InvalidCharacterError}} and abort these steps.

1. Let |bucket| be the [=/storage bucket=] with [=map/key=] |name| in [=bucket map=] if one exists. Otherwise return.
1. Let |bucket| be |shelf|'s [=bucket map=][|name|] if exists. Otherwise return.

1. Remove |bucket|.

Expand Down Expand Up @@ -268,6 +268,8 @@ The <dfn method for="StorageBucket">persist()</dfn> method steps are:
1. Let |bucket| be [=this=]'s [=/storage bucket=].

1. If |bucket| has been removed, [=reject=] |p| with {{InvalidStateError}}.

1. If |bucket|'s [=bucket mode=] is `"persistent"`, [=/resolve=] |p| with true.

1. Otherwise,

Expand Down Expand Up @@ -560,13 +562,15 @@ Issue: add the steps below to the algorithm in [[clear-site-data#clear-response]

To <dfn>clear data with buckets</dfn>, execute the following steps:

1. Let |shelf| be the result of running [=obtain a local storage shelf=] given |environment|.

1. If |shelf| is failure, then [=exception/throw=] an "{{UnknownError}}" {{DOMException}} and abort these steps.

1. For each |type| in |types|, execute the following steps:

1. If |type| is not a [=tuple=] or |type|[0] is not `"storage-bucket"`, abort these steps.

1. Let |bucket name| be |type|[1].

1. Let |bucket| be the [=/storage bucket=] named |bucket name| in |storageKey| if one exists. Otherwise abort these steps.
1. Let |bucket| be |shelf|'s [=bucket map=][|bucket name|] if one exists. Otherwise abort these steps

1. Remove |bucket|.

Expand Down

0 comments on commit 653aa90

Please sign in to comment.