Skip to content

Commit

Permalink
Introduce a storage task source and queue a storage task
Browse files Browse the repository at this point in the history
Also make use of them internally. Additionally cross-reference more and adopt modern practices.

Helps with whatwg/fs#3. Fixes #89.

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
  • Loading branch information
a-sully and annevk authored Jan 16, 2023
1 parent 8b93c4c commit 1180744
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions storage.bs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
text: agent cluster; url: #sec-agent-clusters; type: dfn
</pre>

<pre class=link-defaults>
spec:infra; type:dfn; text:implementation-defined
</pre>



<h2 id=introduction>Introduction</h2>
Expand Down Expand Up @@ -466,6 +470,19 @@ is needed for <a href="https://github.com/whatwg/storage/issues/4">issue #4</a>
<a href="https://privacycg.github.io/storage-access/">Storage Access API</a>.


<h3 id=storage-task-source>Storage task source</h2>

<p>The <dfn export id=task-source>storage task source</dfn> is a <a for=/>task source</a> to be used
for all <a for=/>tasks</a> related to a <a>storage endpoint</a>. In particular those that relate to
a <a>storage endpoint</a>'s <a for="storage endpoint">quota</a>.

<div algorithm>
<p>To <dfn export>queue a storage task</dfn> given a <a for=/>global object</a> <var>global</var>
and a series of steps <var>steps</var>, <a>queue a global task</a> on the <a>storage task source</a>
with <var>global</var> and <var>steps</var>.
</div>



<h2 id=persistence>Persistence permission</h2>

Expand Down Expand Up @@ -602,15 +619,19 @@ dictionary StorageEstimate {
};
</pre>

<div algorithm>
<p>The <dfn method for=StorageManager><code>persisted()</code></dfn> method steps are:

<ol>
<li><p>Let <var>promise</var> be a new promise.
<li><p>Let <var>promise</var> be <a>a new promise</a>.

<li><p>Let <var>global</var> be <a>this</a>'s <a>relevant global object</a>.

<li><p>Let <var>shelf</var> be the result of running <a>obtain a local storage shelf</a> with
<a>this</a>'s <a>relevant settings object</a>.

<li><p>If <var>shelf</var> is failure, then reject <var>promise</var> with a {{TypeError}}.
<li><p>If <var>shelf</var> is failure, then <a for=/>reject</a> <var>promise</var> with a
{{TypeError}}.

<li>
<p>Otherwise, run these steps <a>in parallel</a>:
Expand All @@ -623,21 +644,27 @@ dictionary StorageEstimate {

<p class=note>It will be false when there's an internal error.

<li><p><a>Queue a task</a> to resolve <var>promise</var> with <var>persisted</var>.
<li><p><a>Queue a storage task</a> with <var>global</var> to <a for=/>resolve</a>
<var>promise</var> with <var>persisted</var>.
</ol>

<li><p>Return <var>promise</var>.
</ol>
</div>

<div algorithm>
<p>The <dfn method for=StorageManager><code>persist()</code></dfn> method steps are:

<ol>
<li><p>Let <var>promise</var> be a new promise.
<li><p>Let <var>promise</var> be <a>a new promise</a>.

<li><p>Let <var>global</var> be <a>this</a>'s <a>relevant global object</a>.

<li><p>Let <var>shelf</var> be the result of running <a>obtain a local storage shelf</a> with
<a>this</a>'s <a>relevant settings object</a>.

<li><p>If <var>shelf</var> is failure, then reject <var>promise</var> with a {{TypeError}}.
<li><p>If <var>shelf</var> is failure, then <a for=/>reject</a> <var>promise</var> with a
{{TypeError}}.

<li>
<p>Otherwise, run these steps <a>in parallel</a>:
Expand Down Expand Up @@ -670,21 +697,27 @@ dictionary StorageEstimate {
<li><p>If there was no internal error, then set <var>persisted</var> to true.
</ol>

<li><p><a>Queue a task</a> to resolve <var>promise</var> with <var>persisted</var>.
<li><p><a>Queue a storage task</a> with <var>global</var> to <a for=/>resolve</a>
<var>promise</var> with <var>persisted</var>.
</ol>

<li><p>Return <var>promise</var>.
</ol>
</div>

<div algorithm>
<p>The <dfn method for=StorageManager><code>estimate()</code></dfn> method steps are:

<ol>
<li><p>Let <var>promise</var> be a new promise.
<li><p>Let <var>promise</var> be <a>a new promise</a>.

<li><p>Let <var>global</var> be <a>this</a>'s <a>relevant global object</a>.

<li><p>Let <var>shelf</var> be the result of running <a>obtain a local storage shelf</a> with
<a>this</a>'s <a>relevant settings object</a>.

<li><p>If <var>shelf</var> is failure, then reject <var>promise</var> with a {{TypeError}}.
<li><p>If <var>shelf</var> is failure, then <a for=/>reject</a> <var>promise</var> with a
{{TypeError}}.

<li>
<p>Otherwise, run these steps <a>in parallel</a>:
Expand All @@ -699,17 +732,20 @@ dictionary StorageEstimate {

<li>
<p>If there was an internal error while obtaining <var>usage</var> and <var>quota</var>, then
<a>queue a task</a> to reject <var>promise</var> with a {{TypeError}}.
<a>queue a storage task</a> with <var>global</var> to <a for=/>reject</a> <var>promise</var>
with a {{TypeError}}.

<p class=note>Internal errors are supposed to be extremely rare and indicate some kind of
low-level platform or hardware fault. However, at the scale of the web with the diversity of
implementation and platforms, the unexpected does occur.

<li><p>Otherwise, <a>queue a task</a> to resolve <var>promise</var> with <var>dictionary</var>.
<li><p>Otherwise, <a>queue a storage task</a> with <var>global</var> to <a for=/>resolve</a>
<var>promise</var> with <var>dictionary</var>.
</ol>

<li><p>Return <var>promise</var>.
</ol>
</div>



Expand All @@ -722,6 +758,7 @@ Alex Russell,
Ali Alabbas,
Andrew Sutherland,
Andrew Williams,
Austin Sullivan,
Ben Kelly,
Ben Turner,
Dale Harvey,
Expand Down

0 comments on commit 1180744

Please sign in to comment.