fake-indexeddb 6.2.1 → 6.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/auto/index.js CHANGED
@@ -22,27 +22,21 @@ var globalVar =
22
22
  ? global
23
23
  : Function("return this;")();
24
24
 
25
- // Match the native behavior for `globalThis.indexedDB`, `globlThis.IDBCursor`, etc.
26
- // Per the IDL, `indexedDB` is readonly but the others are readwrite
25
+ // Partly match the native behavior for `globalThis.indexedDB`, `globalThis.IDBCursor`, etc.
26
+ // Per the IDL, `indexedDB` is readonly but the others are readwrite. For us, though, we want it to still
27
+ // be overwritable with `globalThis.<global> = ...`, so we make them all readwrite.
27
28
  // https://w3c.github.io/IndexedDB/#idl-index
28
- const createPropertyDescriptor = (value, readOnly = false) => {
29
+ const createPropertyDescriptor = (value) => {
29
30
  return {
30
- ...(readOnly
31
- ? {
32
- set: undefined,
33
- get: () => value,
34
- }
35
- : {
36
- value,
37
- writable: true,
38
- }),
31
+ value,
39
32
  enumerable: true,
40
33
  configurable: true,
34
+ writable: true,
41
35
  };
42
36
  };
43
37
 
44
38
  Object.defineProperties(globalVar, {
45
- indexedDB: createPropertyDescriptor(fakeIndexedDB, true),
39
+ indexedDB: createPropertyDescriptor(fakeIndexedDB),
46
40
  IDBCursor: createPropertyDescriptor(FDBCursor),
47
41
  IDBCursorWithValue: createPropertyDescriptor(FDBCursorWithValue),
48
42
  IDBDatabase: createPropertyDescriptor(FDBDatabase),
package/auto/index.mjs CHANGED
@@ -22,27 +22,21 @@ var globalVar =
22
22
  ? global
23
23
  : Function("return this;")();
24
24
 
25
- // Match the native behavior for `globalThis.indexedDB`, `globlThis.IDBCursor`, etc.
26
- // Per the IDL, `indexedDB` is readonly but the others are readwrite
25
+ // Partly match the native behavior for `globalThis.indexedDB`, `globalThis.IDBCursor`, etc.
26
+ // Per the IDL, `indexedDB` is readonly but the others are readwrite. For us, though, we want it to still
27
+ // be overwritable with `globalThis.<global> = ...`, so we make them all readwrite.
27
28
  // https://w3c.github.io/IndexedDB/#idl-index
28
- const createPropertyDescriptor = (value, readOnly = false) => {
29
+ const createPropertyDescriptor = (value) => {
29
30
  return {
30
- ...(readOnly
31
- ? {
32
- set: undefined,
33
- get: () => value,
34
- }
35
- : {
36
- value,
37
- writable: true,
38
- }),
31
+ value,
39
32
  enumerable: true,
40
33
  configurable: true,
34
+ writable: true,
41
35
  };
42
36
  };
43
37
 
44
38
  Object.defineProperties(globalVar, {
45
- indexedDB: createPropertyDescriptor(fakeIndexedDB, true),
39
+ indexedDB: createPropertyDescriptor(fakeIndexedDB),
46
40
  IDBCursor: createPropertyDescriptor(FDBCursor),
47
41
  IDBCursorWithValue: createPropertyDescriptor(FDBCursorWithValue),
48
42
  IDBDatabase: createPropertyDescriptor(FDBDatabase),
@@ -14,6 +14,15 @@ var _errors = require("./lib/errors.js");
14
14
  var _FakeEvent = _interopRequireDefault(require("./lib/FakeEvent.js"));
15
15
  var _scheduling = require("./lib/scheduling.js");
16
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ // https://w3c.github.io/IndexedDB/#connection-queue
18
+ const runTaskInConnectionQueue = (connectionQueues, name, task) => {
19
+ // Let queue be the connection queue for storageKey and name.
20
+ // (note FakeIndexedDB does not support storageKeys currently)
21
+ // Add request to queue.
22
+ // Wait until all previous requests in queue have been processed.
23
+ const queue = connectionQueues.get(name) ?? Promise.resolve();
24
+ connectionQueues.set(name, queue.then(task));
25
+ };
17
26
  const waitForOthersClosedDelete = (databases, name, openDatabases, cb) => {
18
27
  const anyOpen = openDatabases.some(openDatabase2 => {
19
28
  return !openDatabase2._closed && !openDatabase2._closePending;
@@ -26,164 +35,287 @@ const waitForOthersClosedDelete = (databases, name, openDatabases, cb) => {
26
35
  cb(null);
27
36
  };
28
37
 
29
- // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-deleting-a-database
30
- const deleteDatabase = (databases, name, request, cb) => {
31
- try {
32
- const db = databases.get(name);
33
- if (db === undefined) {
34
- cb(null);
35
- return;
36
- }
37
- db.deletePending = true;
38
- const openDatabases = db.connections.filter(connection => {
39
- return !connection._closed && !connection._closePending;
40
- });
41
- for (const openDatabase2 of openDatabases) {
42
- if (!openDatabase2._closePending) {
43
- const event = new _FDBVersionChangeEvent.default("versionchange", {
44
- newVersion: null,
45
- oldVersion: db.version
38
+ // https://w3c.github.io/IndexedDB/#delete-a-database
39
+ const deleteDatabase = (databases, connectionQueues, name, request, cb) => {
40
+ const deleteDBTask = () => {
41
+ return new Promise(resolve => {
42
+ const db = databases.get(name);
43
+ const oldVersion = db !== undefined ? db.version : 0;
44
+ const onComplete = err => {
45
+ try {
46
+ if (err) {
47
+ cb(err);
48
+ } else {
49
+ cb(null, oldVersion);
50
+ }
51
+ } finally {
52
+ resolve();
53
+ }
54
+ };
55
+ try {
56
+ const db = databases.get(name);
57
+ if (db === undefined) {
58
+ onComplete(null);
59
+ return;
60
+ }
61
+
62
+ // Let openConnections be the set of all connections associated with db.
63
+ const openConnections = db.connections.filter(connection => {
64
+ return !connection._closed;
46
65
  });
47
- openDatabase2.dispatchEvent(event);
66
+
67
+ // For each entry of openConnections that does not have its close pending flag set to true, queue a
68
+ // database task to fire a version change event named versionchange at entry with db’s version and null.
69
+ for (const openDatabase2 of openConnections) {
70
+ if (!openDatabase2._closePending) {
71
+ (0, _scheduling.queueTask)(() => {
72
+ const event = new _FDBVersionChangeEvent.default("versionchange", {
73
+ newVersion: null,
74
+ oldVersion: db.version
75
+ });
76
+ openDatabase2.dispatchEvent(event);
77
+ });
78
+ }
79
+ }
80
+
81
+ // Wait for all of the events to be fired. (i.e. queue a task)
82
+ (0, _scheduling.queueTask)(() => {
83
+ // If any of the connections in openConnections are still not closed, queue a database task to
84
+ // fire a version change event named blocked at request with db’s version and null.
85
+
86
+ const anyOpen = openConnections.some(openDatabase3 => {
87
+ return !openDatabase3._closed && !openDatabase3._closePending;
88
+ });
89
+
90
+ // If any of the connections in openConnections are still not closed, queue a database task to
91
+ // fire a version change event named blocked at request with db’s version and null.
92
+ if (anyOpen) {
93
+ (0, _scheduling.queueTask)(() => {
94
+ const event = new _FDBVersionChangeEvent.default("blocked", {
95
+ newVersion: null,
96
+ oldVersion: db.version
97
+ });
98
+ request.dispatchEvent(event);
99
+ });
100
+ }
101
+
102
+ // Wait until all connections in openConnections are closed.
103
+ waitForOthersClosedDelete(databases, name, openConnections, onComplete);
104
+ });
105
+ } catch (err) {
106
+ onComplete(err);
48
107
  }
49
- }
50
- const anyOpen = openDatabases.some(openDatabase3 => {
51
- return !openDatabase3._closed && !openDatabase3._closePending;
52
108
  });
53
- if (request && anyOpen) {
54
- const event = new _FDBVersionChangeEvent.default("blocked", {
55
- newVersion: null,
56
- oldVersion: db.version
57
- });
58
- request.dispatchEvent(event);
59
- }
60
- waitForOthersClosedDelete(databases, name, openDatabases, cb);
61
- } catch (err) {
62
- cb(err);
63
- }
109
+ };
110
+ runTaskInConnectionQueue(connectionQueues, name, deleteDBTask);
64
111
  };
65
112
 
66
- // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-running-a-versionchange-transaction
113
+ // https://w3c.github.io/IndexedDB/#ref-for-database-version%E2%91%A0%E2%91%A2
67
114
  const runVersionchangeTransaction = (connection, version, request, cb) => {
68
115
  connection._runningVersionchangeTransaction = true;
69
- const oldVersion = connection.version;
70
- const openDatabases = connection._rawDatabase.connections.filter(otherDatabase => {
116
+ const oldVersion = connection._oldVersion = connection.version;
117
+
118
+ // Let openConnections be the set of all connections, except connection, associated with db.
119
+ const openConnections = connection._rawDatabase.connections.filter(otherDatabase => {
71
120
  return connection !== otherDatabase;
72
121
  });
73
- for (const openDatabase2 of openDatabases) {
122
+
123
+ // For each entry of openConnections that does not have its close pending flag set to true, queue a
124
+ // database task to fire a version change event named versionchange at entry with db’s version and version.
125
+ for (const openDatabase2 of openConnections) {
74
126
  if (!openDatabase2._closed && !openDatabase2._closePending) {
75
- const event = new _FDBVersionChangeEvent.default("versionchange", {
76
- newVersion: version,
77
- oldVersion
127
+ (0, _scheduling.queueTask)(() => {
128
+ const event = new _FDBVersionChangeEvent.default("versionchange", {
129
+ newVersion: version,
130
+ oldVersion
131
+ });
132
+ openDatabase2.dispatchEvent(event);
78
133
  });
79
- openDatabase2.dispatchEvent(event);
80
134
  }
81
135
  }
82
- const anyOpen = openDatabases.some(openDatabase3 => {
83
- return !openDatabase3._closed && !openDatabase3._closePending;
84
- });
85
- if (anyOpen) {
86
- const event = new _FDBVersionChangeEvent.default("blocked", {
87
- newVersion: version,
88
- oldVersion
89
- });
90
- request.dispatchEvent(event);
91
- }
92
- const waitForOthersClosed = () => {
93
- const anyOpen2 = openDatabases.some(openDatabase2 => {
94
- return !openDatabase2._closed && !openDatabase2._closePending;
136
+
137
+ // Wait for all of the events to be fired.
138
+ // (i.e. queue a task)
139
+ (0, _scheduling.queueTask)(() => {
140
+ const anyOpen = openConnections.some(openDatabase3 => {
141
+ return !openDatabase3._closed && !openDatabase3._closePending;
95
142
  });
96
- if (anyOpen2) {
97
- (0, _scheduling.queueTask)(waitForOthersClosed);
98
- return;
143
+
144
+ // If any of the connections in openConnections are still not closed, queue a database task to fire a version change event named blocked at request with db’s version and version.
145
+ if (anyOpen) {
146
+ (0, _scheduling.queueTask)(() => {
147
+ const event = new _FDBVersionChangeEvent.default("blocked", {
148
+ newVersion: version,
149
+ oldVersion
150
+ });
151
+ request.dispatchEvent(event);
152
+ });
99
153
  }
100
154
 
101
- // Set the version of database to version. This change is considered part of the transaction, and so if the
102
- // transaction is aborted, this change is reverted.
103
- connection._rawDatabase.version = version;
104
- connection.version = version;
155
+ // Wait until all connections in openConnections are closed.
156
+ const waitForOthersClosed = () => {
157
+ const anyOpen2 = openConnections.some(openDatabase2 => {
158
+ return !openDatabase2._closed && !openDatabase2._closePending;
159
+ });
160
+ if (anyOpen2) {
161
+ (0, _scheduling.queueTask)(waitForOthersClosed);
162
+ return;
163
+ }
105
164
 
106
- // Get rid of this setImmediate?
107
- const transaction = connection.transaction(Array.from(connection.objectStoreNames), "versionchange");
108
- request.result = connection;
109
- request.readyState = "done";
110
- request.transaction = transaction;
111
- transaction._rollbackLog.push(() => {
112
- connection._rawDatabase.version = oldVersion;
113
- connection.version = oldVersion;
114
- });
115
- const event = new _FDBVersionChangeEvent.default("upgradeneeded", {
116
- newVersion: version,
117
- oldVersion
118
- });
119
- request.dispatchEvent(event);
120
- transaction.addEventListener("error", () => {
121
- connection._runningVersionchangeTransaction = false;
122
- // throw arguments[0].target.error;
123
- // console.log("error in versionchange transaction - not sure if anything needs to be done here", e.target.error.name);
124
- });
125
- transaction.addEventListener("abort", () => {
126
- connection._runningVersionchangeTransaction = false;
127
- request.transaction = null;
128
- (0, _scheduling.queueTask)(() => {
129
- cb(new _errors.AbortError());
165
+ // Set the version of database to version. This change is considered part of the transaction, and so if the
166
+ // transaction is aborted, this change is reverted.
167
+ connection._rawDatabase.version = version;
168
+ connection.version = version;
169
+
170
+ // Get rid of this setImmediate?
171
+ const transaction = connection.transaction(Array.from(connection.objectStoreNames), "versionchange");
172
+
173
+ // associate the transaction with the open request for later lookup
174
+ transaction._openRequest = request;
175
+
176
+ // https://w3c.github.io/IndexedDB/#upgrade-a-database
177
+ // Set request’s result to connection.
178
+ request.result = connection;
179
+ // Set request’s done flag to true.
180
+ request.readyState = "done";
181
+ // Set request’s transaction to transaction.
182
+ request.transaction = transaction;
183
+ transaction._rollbackLog.push(() => {
184
+ connection._rawDatabase.version = oldVersion;
185
+ connection.version = oldVersion;
130
186
  });
131
- });
132
- transaction.addEventListener("complete", () => {
133
- connection._runningVersionchangeTransaction = false;
134
- request.transaction = null;
135
- // Let other complete event handlers run before continuing
136
- (0, _scheduling.queueTask)(() => {
137
- if (connection._closePending) {
138
- cb(new _errors.AbortError());
139
- } else {
140
- cb(null);
187
+
188
+ // Set transaction’s state to active.
189
+ transaction._state = "active";
190
+
191
+ // Let didThrow be the result of firing a version change event named upgradeneeded at request with old version and version.
192
+ const event = new _FDBVersionChangeEvent.default("upgradeneeded", {
193
+ newVersion: version,
194
+ oldVersion
195
+ });
196
+ let didThrow = false;
197
+ try {
198
+ request.dispatchEvent(event);
199
+ } catch (_err) {
200
+ didThrow = true;
201
+ }
202
+ const concludeUpgrade = () => {
203
+ // If transaction’s state is active, then:
204
+ if (transaction._state === "active") {
205
+ // Set transaction’s state to inactive.
206
+ transaction._state = "inactive";
207
+ if (didThrow) {
208
+ // If didThrow is true, run abort a transaction with transaction and a newly created "AbortError" DOMException.
209
+ transaction._abort("AbortError");
210
+ }
141
211
  }
212
+ };
213
+
214
+ // The "upgrade a database" steps are supposed to run as a database task on the database access task source
215
+ // (i.e. off the main thread), but since we're actually running on the main thread, we have to be tricky:
216
+ // 1. If any `upgradeneeded` event handlers errored, abort synchronously
217
+ // 2. Else yield to allow any microtasks to run in response to that event
218
+ if (didThrow) {
219
+ concludeUpgrade();
220
+ } else {
221
+ (0, _scheduling.queueTask)(concludeUpgrade);
222
+ }
223
+ transaction.addEventListener("error", () => {
224
+ connection._runningVersionchangeTransaction = false;
225
+ connection._oldVersion = undefined;
226
+ // throw arguments[0].target.error;
227
+ // console.log("error in versionchange transaction - not sure if anything needs to be done here", e.target.error.name);
142
228
  });
143
- });
144
- };
145
- waitForOthersClosed();
229
+ transaction.addEventListener("abort", () => {
230
+ connection._runningVersionchangeTransaction = false;
231
+ connection._oldVersion = undefined;
232
+ request.transaction = null;
233
+ (0, _scheduling.queueTask)(() => {
234
+ cb(new _errors.AbortError());
235
+ });
236
+ });
237
+ transaction.addEventListener("complete", () => {
238
+ connection._runningVersionchangeTransaction = false;
239
+ connection._oldVersion = undefined;
240
+ request.transaction = null;
241
+ // Let other complete event handlers run before continuing
242
+ (0, _scheduling.queueTask)(() => {
243
+ if (connection._closePending) {
244
+ cb(new _errors.AbortError());
245
+ } else {
246
+ cb(null);
247
+ }
248
+ });
249
+ });
250
+ };
251
+ waitForOthersClosed();
252
+ });
146
253
  };
147
254
 
148
- // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-opening-a-database
149
- const openDatabase = (databases, name, version, request, cb) => {
150
- let db = databases.get(name);
151
- if (db === undefined) {
152
- db = new _Database.default(name, 0);
153
- databases.set(name, db);
154
- }
155
- if (version === undefined) {
156
- version = db.version !== 0 ? db.version : 1;
157
- }
158
- if (db.version > version) {
159
- return cb(new _errors.VersionError());
160
- }
161
- const connection = new _FDBDatabase.default(db);
162
- if (db.version < version) {
163
- runVersionchangeTransaction(connection, version, request, err => {
164
- if (err) {
165
- // DO THIS HERE: ensure that connection is closed by running the steps for closing a database connection before these
166
- // steps are aborted.
167
- return cb(err);
255
+ // https://w3c.github.io/IndexedDB/#opening
256
+ const openDatabase = (databases, connectionQueues, name, version, request, cb) => {
257
+ const openDBTask = () => {
258
+ return new Promise(resolve => {
259
+ const onComplete = err => {
260
+ try {
261
+ if (err) {
262
+ // DO THIS HERE: ensure that connection is closed by running the steps for closing a database connection before these
263
+ // steps are aborted.
264
+ cb(err);
265
+ } else {
266
+ cb(null, connection);
267
+ }
268
+ } finally {
269
+ resolve();
270
+ }
271
+ };
272
+
273
+ // Let db be the database named name in storageKey, or null otherwise.
274
+ let db = databases.get(name);
275
+ if (db === undefined) {
276
+ // If db is null, let db be a new database with name `name`, version 0 (zero), and with no object stores.
277
+ db = new _Database.default(name, 0);
278
+ databases.set(name, db);
279
+ }
280
+
281
+ // If version is undefined, let version be 1 if db is null, or db’s version otherwise.
282
+ if (version === undefined) {
283
+ version = db.version !== 0 ? db.version : 1;
284
+ }
285
+
286
+ // If db’s version is greater than version, return a newly created "VersionError" DOMException and abort these steps.
287
+ if (db.version > version) {
288
+ return onComplete(new _errors.VersionError());
289
+ }
290
+
291
+ // Let connection be a new connection to db.
292
+ const connection = new _FDBDatabase.default(db);
293
+
294
+ // If db’s version is less than version, then:
295
+ if (db.version < version) {
296
+ // (run a version change transaction and resolve so that the next promise in the queue will execute)
297
+ runVersionchangeTransaction(connection, version, request, err => {
298
+ onComplete(err);
299
+ });
300
+ } else {
301
+ onComplete(null);
168
302
  }
169
- cb(null, connection);
170
303
  });
171
- } else {
172
- cb(null, connection);
173
- }
304
+ };
305
+ runTaskInConnectionQueue(connectionQueues, name, openDBTask);
174
306
  };
175
307
  class FDBFactory {
176
308
  cmp = _cmp.default;
177
309
  _databases = new Map();
310
+ // https://w3c.github.io/IndexedDB/#connection-queue
311
+ _connectionQueues = new Map(); // promise chain as lightweight FIFO task queue
178
312
 
179
- // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBFactory-deleteDatabase-IDBOpenDBRequest-DOMString-name
313
+ // https://w3c.github.io/IndexedDB/#dom-idbfactory-deletedatabase
180
314
  deleteDatabase(name) {
181
315
  const request = new _FDBOpenDBRequest.default();
182
316
  request.source = null;
183
317
  (0, _scheduling.queueTask)(() => {
184
- const db = this._databases.get(name);
185
- const oldVersion = db !== undefined ? db.version : 0;
186
- deleteDatabase(this._databases, name, request, err => {
318
+ deleteDatabase(this._databases, this._connectionQueues, name, request, (err, oldVersion) => {
187
319
  if (err) {
188
320
  request.error = new DOMException(err.message, err.name);
189
321
  request.readyState = "done";
@@ -220,7 +352,7 @@ class FDBFactory {
220
352
  const request = new _FDBOpenDBRequest.default();
221
353
  request.source = null;
222
354
  (0, _scheduling.queueTask)(() => {
223
- openDatabase(this._databases, name, version, request, (err, connection) => {
355
+ openDatabase(this._databases, this._connectionQueues, name, version, request, (err, connection) => {
224
356
  if (err) {
225
357
  request.result = undefined;
226
358
  request.readyState = "done";
@@ -245,16 +377,24 @@ class FDBFactory {
245
377
 
246
378
  // https://w3c.github.io/IndexedDB/#dom-idbfactory-databases
247
379
  databases() {
248
- return new Promise(resolve => {
249
- const result = [];
250
- for (const [name, database] of this._databases) {
251
- result.push({
252
- name,
253
- version: database.version
254
- });
255
- }
256
- resolve(result);
257
- });
380
+ return Promise.resolve(Array.from(this._databases.entries(), ([name, database]) => {
381
+ const activeVersionChangeConnection = database.connections.find(connection => connection._runningVersionchangeTransaction);
382
+ // If a versionchange is in progress, report the old version. See `get-databases.any.js` test:
383
+ // "The result of databases() should contain the versions of databases at the time of calling,
384
+ // regardless of versionchange transactions currently running."
385
+ const version = activeVersionChangeConnection ? activeVersionChangeConnection._oldVersion : database.version;
386
+ return {
387
+ name,
388
+ version
389
+ };
390
+ }).filter(({
391
+ version
392
+ }) => {
393
+ // Ignore newly-created DBs with active versionchange transactions. See `get-databases.any.js` test:
394
+ // "The result of databases() should be only those databases which have been created at the
395
+ // time of calling, regardless of versionchange transactions currently running."
396
+ return version > 0;
397
+ }));
258
398
  }
259
399
  get [Symbol.toStringTag]() {
260
400
  return "IDBFactory";
@@ -18,6 +18,7 @@ class FDBTransaction extends _FakeEventTarget.default {
18
18
  _started = false;
19
19
  _rollbackLog = [];
20
20
  _objectStoresCache = new Map();
21
+ _openRequest = null;
21
22
  error = null;
22
23
  onabort = null;
23
24
  oncomplete = null;
@@ -32,7 +33,7 @@ class FDBTransaction extends _FakeEventTarget.default {
32
33
  this.objectStoreNames = new _FakeDOMStringList.default(...Array.from(this._scope).sort());
33
34
  }
34
35
 
35
- // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-aborting-a-transaction
36
+ // https://w3c.github.io/IndexedDB/#abort-transaction
36
37
  _abort(errName) {
37
38
  for (const f of this._rollbackLog.reverse()) {
38
39
  f();
@@ -49,24 +50,61 @@ class FDBTransaction extends _FakeEventTarget.default {
49
50
  if (request.readyState !== "done") {
50
51
  request.readyState = "done"; // This will cancel execution of this request's operation
51
52
  if (request.source) {
52
- request.result = undefined;
53
- request.error = new _errors.AbortError();
54
- const event = new _FakeEvent.default("error", {
55
- bubbles: true,
56
- cancelable: true
53
+ // https://w3c.github.io/IndexedDB/#ref-for-list-iterate%E2%91%A2
54
+ // For each request of transaction’s request list, abort the steps to asynchronously
55
+ // execute a request for request, set request’s processed flag to true, and queue a
56
+ // database task to run these steps:
57
+ (0, _scheduling.queueTask)(() => {
58
+ // Set request’s result to undefined.
59
+ request.result = undefined;
60
+ // Set request’s error to a newly created "AbortError" DOMException.
61
+ request.error = new _errors.AbortError();
62
+
63
+ // Fire an event named error at request with its bubbles and cancelable attributes initialized
64
+ // to true.
65
+ const event = new _FakeEvent.default("error", {
66
+ bubbles: true,
67
+ cancelable: true
68
+ });
69
+ event.eventPath = [this.db, this];
70
+ try {
71
+ request.dispatchEvent(event);
72
+ } catch (_err) {
73
+ if (this._state === "active") {
74
+ this._abort("AbortError");
75
+ }
76
+ }
57
77
  });
58
- event.eventPath = [this.db, this];
59
- request.dispatchEvent(event);
60
78
  }
61
79
  }
62
80
  }
81
+
82
+ // Queue a database task to run these steps:
63
83
  (0, _scheduling.queueTask)(() => {
84
+ // If transaction is an upgrade transaction, then set transaction’s connection’s associated database’s
85
+ // upgrade transaction to null.
86
+ // (i.e. remove it from the list of `db.connections`)
87
+ const isUpgradeTransaction = this.mode === "versionchange";
88
+ if (isUpgradeTransaction) {
89
+ this.db._rawDatabase.connections = this.db._rawDatabase.connections.filter(connection => !connection._rawDatabase.transactions.includes(this));
90
+ }
91
+ // Fire an event named abort at transaction with its bubbles attribute initialized to true.
64
92
  const event = new _FakeEvent.default("abort", {
65
93
  bubbles: true,
66
94
  cancelable: false
67
95
  });
68
96
  event.eventPath = [this.db];
69
97
  this.dispatchEvent(event);
98
+
99
+ // If transaction is an upgrade transaction, then:
100
+ if (isUpgradeTransaction) {
101
+ // Let request be the open request associated with transaction.
102
+ const request = this._openRequest;
103
+ // Set request’s transaction to null.
104
+ request.transaction = null;
105
+ // Set request’s result to undefined.
106
+ request.result = undefined;
107
+ }
70
108
  });
71
109
  this._state = "finished";
72
110
  }
@@ -178,11 +216,11 @@ class FDBTransaction extends _FakeEventTarget.default {
178
216
  try {
179
217
  event.eventPath = [this.db, this];
180
218
  request.dispatchEvent(event);
181
- } catch (err) {
182
- if (this._state !== "committing") {
219
+ } catch (_err) {
220
+ if (this._state === "active") {
183
221
  this._abort("AbortError");
222
+ defaultAction = undefined; // do not abort again
184
223
  }
185
- throw err;
186
224
  }
187
225
 
188
226
  // Default action of event