5.3. Deleting a database

The steps to delete a database are as follows. The algorithm in these steps takes three arguments: the origin that requested the database to be deleted, a database name, and a request.

  1. Let queue be the connection queue for origin and name.

  2. Add request to queue.

  3. Wait until all previous requests in queue have been processed.

  4. Let db be the database named name in origin, if one exists. Otherwise, return 0 (zero).

  5. Let openConnections be the set of all connections associated with db.

  6. For each entry in openConnections that does not have its close pending flag set, queue a task to fire a version change event named versionchange at entry with db’s version and null.

    Firing this event might cause one or more of the other objects in openConnections to be closed, in which case the versionchange event is not fired at those objects, even if that hasn’t yet been done.

  7. Wait for all of the events to be fired.

  8. If any of the connections in openConnections are still not closed, queue a task to fire a version change event named [blocked](#request-blocked) at request with db’s version and null.

  9. Wait until all connections in openConnections are closed.

  10. Let version be db’s version.

  11. Delete db. If this fails for any reason, return an appropriate error (e.g. “[QuotaExceededError](https://www.w3.org/TR/WebIDL-1/#quotaexceedederror)“ or “[UnknownError](https://www.w3.org/TR/WebIDL-1/#unknownerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException)).

  12. Return version.