Skip to content

Commit

Permalink
Implement transaction cleanup hook for [HTML]
Browse files Browse the repository at this point in the history
This defines a hook "cleanup IndexedDB transactions" that HTML
can invoke at the end of tasks, replacing the monkey patch 
"When control is returned to the event loop, the implementation 
must unset the active flag".
  • Loading branch information
inexorabletash committed Mar 7, 2017
1 parent 52cc96f commit 5ae70f2
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 101 deletions.
33 changes: 29 additions & 4 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,9 @@ if new [=requests=] can be made against the transaction. A
transaction is said to be <dfn>active</dfn> if its [=transaction/active flag=]
is set.

A [=/transaction=] optionally has a <dfn>cleanup event loop</dfn>
which is an [=event loop=].

A [=/transaction=] has a <dfn>request list</dfn> of [=requests=]
which have been made against the transaction.

Expand Down Expand Up @@ -1144,6 +1147,26 @@ The following constraints define when a [=/transaction=] can be

</div>

To <dfn export>cleanup Indexed Database transactions</dfn>,
run the following steps for each [=/transaction=]
with [=transaction/cleanup event loop=] matching the current
[=event loop=].

<div class=algorithm>
1. Unset the [=/transaction=]'s [=transaction/active flag=].

2. Clear the [=/transaction=]'s [=transaction/cleanup event loop=].
</div>

<aside class=note>
This behavior is invoked by [[HTML]]. It ensures that
[=/transactions=] created by a script call
to{{IDBDatabase/transaction()}} are deactivated once the task that
invoked the script has completed. The steps are run at most once for
each [=/transaction=].
</aside>


<!-- ============================================================ -->
<h4 id=upgrade-transaction-construct>Upgrade Transactions</h4>
<!-- ============================================================ -->
Expand Down Expand Up @@ -2550,8 +2573,8 @@ The <dfn method for=IDBDatabase>transaction(|storeNames|,
|connection|, |mode| and the set of [=/object stores=] named in
|scope|.

8. When control is returned to the [=event loop=], the implementation must
unset the [=transaction/active flag=].
8. Set |transaction|'s [=transaction/cleanup event loop=] to the
current [=event loop=].

9. Return an {{IDBTransaction}} object representing |transaction|.

Expand Down Expand Up @@ -5457,11 +5480,13 @@ for the [=database=], and a |request|.
1. Set |request|'s [=request/result=] to |connection|.
2. Set |request|'s [=request/transaction=] to |transaction|.
3. Set the [=request/done flag=] on the [=request=].
4. Let |didThrow| be the result of running the steps to
4. Set |transaction|'s [=transaction/active flag=].
5. Let |didThrow| be the result of running the steps to
[=fire a version change event=] named
<code>[=upgradeneeded=]</code> at |request| with |old
version| and |version|.
5. If |didThrow| is set, run the steps to [=abort a
6. Unset |transaction|'s [=transaction/active flag=].
7. If |didThrow| is set, run the steps to [=abort a
transaction=] with the |error| property set to a newly
<a for=exception>created</a> "{{AbortError}}" {{DOMException}}.

Expand Down
Loading

0 comments on commit 5ae70f2

Please sign in to comment.