From 653aa906d80638e6b361f37d4652d2a38f8a5aa3 Mon Sep 17 00:00:00 2001 From: Ayu Ishii <48255136+ayuishii@users.noreply.github.com> Date: Wed, 15 Feb 2023 09:10:45 -0800 Subject: [PATCH] use bucket map & update persist() (#71) * Expand usage of bucket map * remove the * Use bucket map for clear site data * short-circuit if bucket is already persistent --- index.bs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/index.bs b/index.bs index 116abab..c00a369 100644 --- a/index.bs +++ b/index.bs @@ -72,10 +72,10 @@ dictionary StorageBucketOptions { The open(|name|, |options|) 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=]. @@ -83,7 +83,7 @@ The open(|name|, |options|) method 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. @@ -95,7 +95,7 @@ The open(|name|, |options|) method
-To open a bucket for a |storageKey| given a bucket |name| and optional |options|, run the following steps: +To open a bucket 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. @@ -113,7 +113,7 @@ To open a bucket 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: @@ -168,9 +168,9 @@ The delete(|name|) 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=]. @@ -178,7 +178,7 @@ The delete(|name|) method steps are 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|. @@ -268,6 +268,8 @@ The persist() 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, @@ -560,13 +562,15 @@ Issue: add the steps below to the algorithm in [[clear-site-data#clear-response] To clear data with buckets, 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|.