aboutsummaryrefslogtreecommitdiff
path: root/packages/idb-bridge
diff options
context:
space:
mode:
Diffstat (limited to 'packages/idb-bridge')
-rw-r--r--packages/idb-bridge/src/bridge-idb.ts9
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts131
2 files changed, 75 insertions, 65 deletions
diff --git a/packages/idb-bridge/src/bridge-idb.ts b/packages/idb-bridge/src/bridge-idb.ts
index 02fca9d1e..836f2efa4 100644
--- a/packages/idb-bridge/src/bridge-idb.ts
+++ b/packages/idb-bridge/src/bridge-idb.ts
@@ -936,10 +936,6 @@ export class BridgeIDBFactory {
await transaction._waitDone();
- // We don't explicitly exit the versionchange transaction,
- // since this is already done by the BridgeIDBTransaction.
- db._upgradeTransaction = null;
-
// We re-use the same transaction (as per spec) here.
transaction._active = true;
@@ -2425,6 +2421,11 @@ export class BridgeIDBTransaction
if (this._backendTransaction) {
await this._backend.commit(this._backendTransaction);
}
+
+ // We must exit the upgrade transaction here, so that the "complete"
+ // event handler can already do other transactions.
+ this._db._upgradeTransaction = null;
+
this._committed = true;
if (!this._error) {
if (BridgeIDBFactory.enableTracing) {
diff --git a/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts b/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts
index 2f1797a6f..7da0ea8ff 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts
+++ b/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts
@@ -1,11 +1,15 @@
import test from "ava";
-import { BridgeIDBCursor } from "..";
+import { BridgeIDBCursor, BridgeIDBKeyRange } from "..";
import { BridgeIDBCursorWithValue } from "../bridge-idb";
+import { IDBRequest } from "../idbtypes";
import { createdb } from "./wptsupport";
-// Validate the overloads of IDBObjectStore.openCursor(), IDBIndex.openCursor() and IDBIndex.openKeyCursor()
+const IDBKeyRange = BridgeIDBKeyRange;
+
+// Validate the overloads of IDBObjectStore.openCursor(),
+// IDBIndex.openCursor() and IDBIndex.openKeyCursor()
test.cb("WPT test cursor-overloads.htm", (t) => {
- var db: any, trans: any, store: any, index: any;
+ var db: any, store: any, index: any;
var request = createdb(t);
request.onupgradeneeded = function (e) {
@@ -13,102 +17,107 @@ test.cb("WPT test cursor-overloads.htm", (t) => {
store = db.createObjectStore("store");
index = store.createIndex("index", "value");
store.put({ value: 0 }, 0);
- trans = request.transaction;
+ const trans = request.transaction!;
trans.oncomplete = verifyOverloads;
};
- function verifyOverloads() {
- trans = db.transaction("store");
+ async function verifyOverloads() {
+ const trans = db.transaction("store");
store = trans.objectStore("store");
index = store.index("index");
- checkCursorDirection("store.openCursor()", "next");
- checkCursorDirection("store.openCursor(0)", "next");
- checkCursorDirection("store.openCursor(0, 'next')", "next");
- checkCursorDirection("store.openCursor(0, 'nextunique')", "nextunique");
- checkCursorDirection("store.openCursor(0, 'prev')", "prev");
- checkCursorDirection("store.openCursor(0, 'prevunique')", "prevunique");
+ await checkCursorDirection(store.openCursor(), "next");
+ await checkCursorDirection(store.openCursor(0), "next");
+ await checkCursorDirection(store.openCursor(0, 'next'), "next");
+ await checkCursorDirection(store.openCursor(0, 'nextunique'), "nextunique");
+ await checkCursorDirection(store.openCursor(0, 'prev'), "prev");
+ await checkCursorDirection(store.openCursor(0, 'prevunique'), "prevunique");
- checkCursorDirection("store.openCursor(IDBKeyRange.only(0))", "next");
- checkCursorDirection(
- "store.openCursor(IDBKeyRange.only(0), 'next')",
+ await checkCursorDirection(store.openCursor(IDBKeyRange.only(0)), "next");
+ await checkCursorDirection(
+ store.openCursor(BridgeIDBKeyRange.only(0), 'next'),
"next",
);
- checkCursorDirection(
- "store.openCursor(IDBKeyRange.only(0), 'nextunique')",
+ await checkCursorDirection(
+ store.openCursor(IDBKeyRange.only(0), 'nextunique'),
"nextunique",
);
- checkCursorDirection(
- "store.openCursor(IDBKeyRange.only(0), 'prev')",
+ await checkCursorDirection(
+ store.openCursor(IDBKeyRange.only(0), 'prev'),
"prev",
);
- checkCursorDirection(
- "store.openCursor(IDBKeyRange.only(0), 'prevunique')",
+ await checkCursorDirection(
+ store.openCursor(IDBKeyRange.only(0), 'prevunique'),
"prevunique",
);
- checkCursorDirection("index.openCursor()", "next");
- checkCursorDirection("index.openCursor(0)", "next");
- checkCursorDirection("index.openCursor(0, 'next')", "next");
- checkCursorDirection("index.openCursor(0, 'nextunique')", "nextunique");
- checkCursorDirection("index.openCursor(0, 'prev')", "prev");
- checkCursorDirection("index.openCursor(0, 'prevunique')", "prevunique");
+ await checkCursorDirection(index.openCursor(), "next");
+ await checkCursorDirection(index.openCursor(0), "next");
+ await checkCursorDirection(index.openCursor(0, 'next'), "next");
+ await checkCursorDirection(index.openCursor(0, 'nextunique'), "nextunique");
+ await checkCursorDirection(index.openCursor(0, 'prev'), "prev");
+ await checkCursorDirection(index.openCursor(0, 'prevunique'), "prevunique");
- checkCursorDirection("index.openCursor(IDBKeyRange.only(0))", "next");
- checkCursorDirection(
- "index.openCursor(IDBKeyRange.only(0), 'next')",
+ await checkCursorDirection(index.openCursor(IDBKeyRange.only(0)), "next");
+ await checkCursorDirection(
+ index.openCursor(IDBKeyRange.only(0), 'next'),
"next",
);
- checkCursorDirection(
- "index.openCursor(IDBKeyRange.only(0), 'nextunique')",
+ await checkCursorDirection(
+ index.openCursor(IDBKeyRange.only(0), 'nextunique'),
"nextunique",
);
- checkCursorDirection(
- "index.openCursor(IDBKeyRange.only(0), 'prev')",
+ await checkCursorDirection(
+ index.openCursor(IDBKeyRange.only(0), 'prev'),
"prev",
);
- checkCursorDirection(
- "index.openCursor(IDBKeyRange.only(0), 'prevunique')",
+ await checkCursorDirection(
+ index.openCursor(IDBKeyRange.only(0), 'prevunique'),
"prevunique",
);
- checkCursorDirection("index.openKeyCursor()", "next");
- checkCursorDirection("index.openKeyCursor(0)", "next");
- checkCursorDirection("index.openKeyCursor(0, 'next')", "next");
- checkCursorDirection("index.openKeyCursor(0, 'nextunique')", "nextunique");
- checkCursorDirection("index.openKeyCursor(0, 'prev')", "prev");
- checkCursorDirection("index.openKeyCursor(0, 'prevunique')", "prevunique");
+ await checkCursorDirection(index.openKeyCursor(), "next");
+ await checkCursorDirection(index.openKeyCursor(0), "next");
+ await checkCursorDirection(index.openKeyCursor(0, 'next'), "next");
+ await checkCursorDirection(index.openKeyCursor(0, 'nextunique'), "nextunique");
+ await checkCursorDirection(index.openKeyCursor(0, 'prev'), "prev");
+ await checkCursorDirection(index.openKeyCursor(0, 'prevunique'), "prevunique");
- checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0))", "next");
- checkCursorDirection(
- "index.openKeyCursor(IDBKeyRange.only(0), 'next')",
+ await checkCursorDirection(index.openKeyCursor(IDBKeyRange.only(0)), "next");
+ await checkCursorDirection(
+ index.openKeyCursor(IDBKeyRange.only(0), 'next'),
"next",
);
- checkCursorDirection(
- "index.openKeyCursor(IDBKeyRange.only(0), 'nextunique')",
+ await checkCursorDirection(
+ index.openKeyCursor(IDBKeyRange.only(0), 'nextunique'),
"nextunique",
);
- checkCursorDirection(
- "index.openKeyCursor(IDBKeyRange.only(0), 'prev')",
+ await checkCursorDirection(
+ index.openKeyCursor(IDBKeyRange.only(0), 'prev'),
"prev",
);
- checkCursorDirection(
- "index.openKeyCursor(IDBKeyRange.only(0), 'prevunique')",
+ await checkCursorDirection(
+ index.openKeyCursor(IDBKeyRange.only(0), 'prevunique'),
"prevunique",
);
t.end();
}
- function checkCursorDirection(statement: string, direction: string) {
- request = eval(statement);
- request.onsuccess = function (event: any) {
- t.notDeepEqual(event.target.result, null, "Check the result is not null");
- t.deepEqual(
- event.target.result.direction,
- direction,
- "Check the result direction",
- );
- };
+ function checkCursorDirection(
+ request: IDBRequest,
+ direction: string,
+ ): Promise<void> {
+ return new Promise<void>((resolve, reject) => {
+ request.onsuccess = function (event: any) {
+ t.notDeepEqual(event.target.result, null, "Check the result is not null");
+ t.deepEqual(
+ event.target.result.direction,
+ direction,
+ "Check the result direction",
+ );
+ resolve();
+ };
+ });
}
});