fake-indexeddb 3.1.4 → 3.1.8

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.
@@ -29,6 +29,7 @@ var errors_1 = require("./lib/errors");
29
29
  var fakeDOMStringList_1 = require("./lib/fakeDOMStringList");
30
30
  var FakeEventTarget_1 = require("./lib/FakeEventTarget");
31
31
  var ObjectStore_1 = require("./lib/ObjectStore");
32
+ var scheduling_1 = require("./lib/scheduling");
32
33
  var validateKeyPath_1 = require("./lib/validateKeyPath");
33
34
  var confirmActiveVersionchangeTransaction = function (database) {
34
35
  if (!database._runningVersionchangeTransaction) {
@@ -60,7 +61,7 @@ var closeConnection = function (connection) {
60
61
  });
61
62
  }
62
63
  else {
63
- setTimeout(function () {
64
+ scheduling_1.queueTask(function () {
64
65
  closeConnection(connection);
65
66
  });
66
67
  }
@@ -35,12 +35,13 @@ var Database_1 = require("./lib/Database");
35
35
  var enforceRange_1 = require("./lib/enforceRange");
36
36
  var errors_1 = require("./lib/errors");
37
37
  var FakeEvent_1 = require("./lib/FakeEvent");
38
+ var scheduling_1 = require("./lib/scheduling");
38
39
  var waitForOthersClosedDelete = function (databases, name, openDatabases, cb) {
39
40
  var anyOpen = openDatabases.some(function (openDatabase2) {
40
41
  return !openDatabase2._closed && !openDatabase2._closePending;
41
42
  });
42
43
  if (anyOpen) {
43
- setTimeout(function () {
44
+ scheduling_1.queueTask(function () {
44
45
  return waitForOthersClosedDelete(databases, name, openDatabases, cb);
45
46
  });
46
47
  return;
@@ -138,7 +139,7 @@ var runVersionchangeTransaction = function (connection, version, request, cb) {
138
139
  return !openDatabase2._closed && !openDatabase2._closePending;
139
140
  });
140
141
  if (anyOpen2) {
141
- setTimeout(waitForOthersClosed);
142
+ scheduling_1.queueTask(waitForOthersClosed);
142
143
  return;
143
144
  }
144
145
  // Set the version of database to version. This change is considered part of the transaction, and so if the
@@ -167,7 +168,7 @@ var runVersionchangeTransaction = function (connection, version, request, cb) {
167
168
  transaction.addEventListener("abort", function () {
168
169
  connection._runningVersionchangeTransaction = false;
169
170
  request.transaction = null;
170
- setTimeout(function () {
171
+ scheduling_1.queueTask(function () {
171
172
  cb(new errors_1.AbortError());
172
173
  });
173
174
  });
@@ -175,7 +176,7 @@ var runVersionchangeTransaction = function (connection, version, request, cb) {
175
176
  connection._runningVersionchangeTransaction = false;
176
177
  request.transaction = null;
177
178
  // Let other complete event handlers run before continuing
178
- setTimeout(function () {
179
+ scheduling_1.queueTask(function () {
179
180
  if (connection._closePending) {
180
181
  cb(new errors_1.AbortError());
181
182
  }
@@ -225,7 +226,7 @@ var FDBFactory = /** @class */ (function () {
225
226
  var _this = this;
226
227
  var request = new FDBOpenDBRequest_1.default();
227
228
  request.source = null;
228
- setTimeout(function () {
229
+ scheduling_1.queueTask(function () {
229
230
  var db = _this._databases.get(name);
230
231
  var oldVersion = db !== undefined ? db.version : 0;
231
232
  deleteDatabase(_this._databases, name, request, function (err) {
@@ -266,7 +267,7 @@ var FDBFactory = /** @class */ (function () {
266
267
  }
267
268
  var request = new FDBOpenDBRequest_1.default();
268
269
  request.source = null;
269
- setTimeout(function () {
270
+ scheduling_1.queueTask(function () {
270
271
  openDatabase(_this._databases, name, version, request, function (err, connection) {
271
272
  if (err) {
272
273
  request.result = undefined;
@@ -30,6 +30,7 @@ var errors_1 = require("./lib/errors");
30
30
  var fakeDOMStringList_1 = require("./lib/fakeDOMStringList");
31
31
  var FakeEvent_1 = require("./lib/FakeEvent");
32
32
  var FakeEventTarget_1 = require("./lib/FakeEventTarget");
33
+ var scheduling_1 = require("./lib/scheduling");
33
34
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#transaction
34
35
  var FDBTransaction = /** @class */ (function (_super) {
35
36
  __extends(FDBTransaction, _super);
@@ -98,7 +99,7 @@ var FDBTransaction = /** @class */ (function (_super) {
98
99
  }
99
100
  finally { if (e_2) throw e_2.error; }
100
101
  }
101
- setTimeout(function () {
102
+ scheduling_1.queueTask(function () {
102
103
  var event = new FakeEvent_1.default("abort", {
103
104
  bubbles: true,
104
105
  cancelable: false,
@@ -227,12 +228,11 @@ var FDBTransaction = /** @class */ (function (_super) {
227
228
  }
228
229
  }
229
230
  // Give it another chance for new handlers to be set before finishing
230
- setTimeout(this._start.bind(this));
231
+ scheduling_1.queueTask(this._start.bind(this));
231
232
  return;
232
233
  }
233
234
  // Check if transaction complete event needs to be fired
234
235
  if (this._state !== "finished") {
235
- // Either aborted or committed already
236
236
  this._state = "finished";
237
237
  if (!this.error) {
238
238
  var event_3 = new FakeEvent_1.default("complete");
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var scheduling_1 = require("./scheduling");
3
4
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-database
4
5
  var Database = /** @class */ (function () {
5
6
  function Database(name, version) {
@@ -13,7 +14,7 @@ var Database = /** @class */ (function () {
13
14
  }
14
15
  Database.prototype.processTransactions = function () {
15
16
  var _this = this;
16
- setTimeout(function () {
17
+ scheduling_1.queueTask(function () {
17
18
  var anyRunning = _this.transactions.some(function (transaction) {
18
19
  return (transaction._started && transaction._state !== "finished");
19
20
  });
@@ -56,7 +56,9 @@ var extractKey = function (keyPath, value) {
56
56
  identifier = remainingKeyPath;
57
57
  remainingKeyPath = null;
58
58
  }
59
- if (!object.hasOwnProperty(identifier)) {
59
+ if (object === undefined ||
60
+ object === null ||
61
+ !object.hasOwnProperty(identifier)) {
60
62
  return;
61
63
  }
62
64
  object = object[identifier];
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // When running within Node.js (including jsdom), we want to use setImmediate
4
+ // (which runs immediately) rather than setTimeout (which enforces a minimum
5
+ // delay of 1ms, and on Windows only has a resolution of 15ms or so). jsdom
6
+ // doesn't provide setImmediate (to better match the browser environment) and
7
+ // sandboxes scripts, but its sandbox is by necessity imperfect, so we can break
8
+ // out of it:
9
+ //
10
+ // - https://github.com/jsdom/jsdom#executing-scripts
11
+ // - https://github.com/jsdom/jsdom/issues/2729
12
+ // - https://github.com/scala-js/scala-js-macrotask-executor/pull/17
13
+ function getSetImmediateFromJsdom() {
14
+ if (typeof navigator !== "undefined" && /jsdom/.test(navigator.userAgent)) {
15
+ var outerRealmFunctionConstructor = Node.constructor;
16
+ return new outerRealmFunctionConstructor("return setImmediate")();
17
+ }
18
+ else {
19
+ return undefined;
20
+ }
21
+ }
22
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
23
+ // Remove this after dropping Node 8 support
24
+ // tslint:disable-next-line
25
+ var getGlobal = function () {
26
+ if (typeof globalThis !== 'undefined') {
27
+ return globalThis;
28
+ }
29
+ if (typeof global !== 'undefined') {
30
+ return global;
31
+ }
32
+ if (typeof self !== 'undefined') {
33
+ return self;
34
+ }
35
+ if (typeof window !== 'undefined') {
36
+ return window;
37
+ }
38
+ throw new Error('unable to locate global object');
39
+ };
40
+ var globals = getGlobal();
41
+ // Schedules a task to run later. Use Node.js's setImmediate if available and
42
+ // setTimeout otherwise. Note that options like process.nextTick or
43
+ // queueMicrotask will likely not work: IndexedDB semantics require that
44
+ // transactions are marked as not active when the event loop runs. The next
45
+ // tick queue and microtask queue run within the current event loop macrotask,
46
+ // so they'd process database operations too quickly.
47
+ exports.queueTask = globals.setImmediate ||
48
+ getSetImmediateFromJsdom() ||
49
+ (function (fn) { return setTimeout(fn, 0); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fake-indexeddb",
3
- "version": "3.1.4",
3
+ "version": "3.1.8",
4
4
  "description": "Fake IndexedDB: a pure JS in-memory implementation of the IndexedDB API",
5
5
  "homepage": "https://github.com/dumbmatter/fakeIndexedDB",
6
6
  "repository": {