基于 IndexedDB 规范,为什么打开的数据库连接会在 indexedDB.deleteDatabase 调用时关闭?
Based on the IndexedDB spec, why do open database connections get closed on indexedDB.deleteDatabase calls?
Let's look at what the IndexedDB spec says about deleting a database. 具体来说,我关心的是如果您尝试删除仍然有一个或多个打开的连接的数据库会发生什么,如下所示:
indexedDB.open('test', 1);
indexedDB.deleteDatabase('test');
规范是这样说的:
- Fire a versionchange event at each object in openDatabases that is open. The event MUST NOT be fired on objects which has the closePending flag set. The event MUST use the IDBVersionChangeEvent interface and have the oldVersion property set to db's version and have the newVersion property set to null. This event MUST NOT bubble or be cancelable.
- If any of the connections in openDatabases are still not closed, and request was provided, fire a blocked event at request. The event MUST use the IDBVersionChangeEvent interface and have the oldVersion property set to db's version and have the newVersion property set to null. This event MUST NOT bubble or be cancelable.
- Wait until all objects in openDatabases are closed and all of their transactions are finished.
我不明白第 7 步是如何完成的。在第 5 步或第 6 步中实际关闭打开的连接之一的是什么?除了让 onversionchange
和 onblocked
处理程序响应之外,这些步骤还做什么?
类似的语言出现在 steps for running a "versionchange" transaction 中,用于当您有一个打开的数据库连接时,您正试图升级版本,如下所示:
indexedDB.open('test', 1);
indexedDB.open('test', 2);
FWIW,我问这样一个平凡的问题是因为 this。
我的理解是所有连接都必须监听 versionchange
事件并关闭连接。否则较新的应用程序既不会增加新版本也不会删除数据库。较新的应用程序最终只会获得 block
事件。请注意,deleteDatabase
方法 return 是一个请求,但 close
方法不是。
I don't understand how step 7 ever completes. What is it in steps 5 or 6 that actually closes one of the open connections? What are those steps even doing besides just letting onversionchange and onblocked handlers respond?
这就是所有这些步骤。 UA 触发这些事件,并让脚本根据需要关闭现有连接。如果脚本选择不关闭现有连接,则第 7 步不会完成。
这在规范中没有描述,因为规范告诉 UA 做什么,而不是脚本。虽然它可能应该在非规范的介绍中描述。
Let's look at what the IndexedDB spec says about deleting a database. 具体来说,我关心的是如果您尝试删除仍然有一个或多个打开的连接的数据库会发生什么,如下所示:
indexedDB.open('test', 1);
indexedDB.deleteDatabase('test');
规范是这样说的:
- Fire a versionchange event at each object in openDatabases that is open. The event MUST NOT be fired on objects which has the closePending flag set. The event MUST use the IDBVersionChangeEvent interface and have the oldVersion property set to db's version and have the newVersion property set to null. This event MUST NOT bubble or be cancelable.
- If any of the connections in openDatabases are still not closed, and request was provided, fire a blocked event at request. The event MUST use the IDBVersionChangeEvent interface and have the oldVersion property set to db's version and have the newVersion property set to null. This event MUST NOT bubble or be cancelable.
- Wait until all objects in openDatabases are closed and all of their transactions are finished.
我不明白第 7 步是如何完成的。在第 5 步或第 6 步中实际关闭打开的连接之一的是什么?除了让 onversionchange
和 onblocked
处理程序响应之外,这些步骤还做什么?
类似的语言出现在 steps for running a "versionchange" transaction 中,用于当您有一个打开的数据库连接时,您正试图升级版本,如下所示:
indexedDB.open('test', 1);
indexedDB.open('test', 2);
FWIW,我问这样一个平凡的问题是因为 this。
我的理解是所有连接都必须监听 versionchange
事件并关闭连接。否则较新的应用程序既不会增加新版本也不会删除数据库。较新的应用程序最终只会获得 block
事件。请注意,deleteDatabase
方法 return 是一个请求,但 close
方法不是。
I don't understand how step 7 ever completes. What is it in steps 5 or 6 that actually closes one of the open connections? What are those steps even doing besides just letting onversionchange and onblocked handlers respond?
这就是所有这些步骤。 UA 触发这些事件,并让脚本根据需要关闭现有连接。如果脚本选择不关闭现有连接,则第 7 步不会完成。
这在规范中没有描述,因为规范告诉 UA 做什么,而不是脚本。虽然它可能应该在非规范的介绍中描述。