aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-02-23 21:30:11 +0100
committerFlorian Dold <florian@dold.me>2021-02-23 21:30:11 +0100
commit627ae6958ef9b98fc16f129fdf95435a5e95b738 (patch)
tree2bb08e943f58be1caab5ca7675857dc21317a917
parent9c85f6277bf85606eb4fbbca47f1a1b5404d2a2e (diff)
idb: fix test / backend
-rw-r--r--packages/idb-bridge/src/bridge-idb.ts48
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts5
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts9
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/idbcursor-update-index.test.ts3
4 files changed, 19 insertions, 46 deletions
diff --git a/packages/idb-bridge/src/bridge-idb.ts b/packages/idb-bridge/src/bridge-idb.ts
index 3c168674d..0c309b421 100644
--- a/packages/idb-bridge/src/bridge-idb.ts
+++ b/packages/idb-bridge/src/bridge-idb.ts
@@ -205,6 +205,7 @@ export class BridgeIDBCursor implements IDBCursor {
);
BridgeIDBFactory.enableTracing &&
console.log("cursor type ", this.toString());
+ const isIndex = this._indexName !== undefined;
const recordGetRequest: RecordGetRequest = {
direction: this.direction,
indexName: this._indexName,
@@ -213,8 +214,8 @@ export class BridgeIDBCursor implements IDBCursor {
limit: 1,
range: simplifyRange(this._range),
objectStoreName: this._objectStoreName,
- advanceIndexKey: key,
- advancePrimaryKey: primaryKey,
+ advanceIndexKey: isIndex ? key : undefined,
+ advancePrimaryKey: isIndex ? primaryKey : key,
resultLevel: this._keyOnly ? ResultLevel.OnlyKeys : ResultLevel.Full,
};
@@ -1113,12 +1114,7 @@ export class BridgeIDBIndex implements IDBIndex {
this._confirmActiveTransaction();
- if (range === null) {
- range = undefined;
- }
- if (range !== undefined && !(range instanceof BridgeIDBKeyRange)) {
- range = BridgeIDBKeyRange.only(valueToKey(range));
- }
+ range = simplifyRange(range);
const request = new BridgeIDBRequest();
request._source = this;
@@ -1793,10 +1789,6 @@ export class BridgeIDBObjectStore implements IDBObjectStore {
console.log(`getting from object store ${this._name} key ${query}`);
}
- if (arguments.length === 0) {
- throw new TypeError();
- }
-
if (!this._transaction._active) {
throw new TransactionInactiveError();
}
@@ -1811,19 +1803,7 @@ export class BridgeIDBObjectStore implements IDBObjectStore {
count = -1;
}
- let keyRange: BridgeIDBKeyRange;
-
- if (query instanceof BridgeIDBKeyRange) {
- keyRange = query;
- } else {
- try {
- keyRange = BridgeIDBKeyRange.only(valueToKey(query));
- } catch (e) {
- throw new DataError(
- `invalid key (type ${typeof query}) for object store '${this._name}'`,
- );
- }
- }
+ let keyRange: BridgeIDBKeyRange | null = simplifyRange(query);
const recordRequest: RecordGetRequest = {
objectStoreName: this._name,
@@ -1877,19 +1857,7 @@ export class BridgeIDBObjectStore implements IDBObjectStore {
);
}
- let keyRange: BridgeIDBKeyRange;
-
- if (query instanceof BridgeIDBKeyRange) {
- keyRange = query;
- } else {
- try {
- keyRange = BridgeIDBKeyRange.only(valueToKey(query));
- } catch (e) {
- throw new DataError(
- `invalid key (type ${typeof query}) for object store '${this._name}'`,
- );
- }
- }
+ let keyRange: BridgeIDBKeyRange | null = simplifyRange(query);
const recordRequest: RecordGetRequest = {
objectStoreName: this._name,
@@ -1904,13 +1872,13 @@ export class BridgeIDBObjectStore implements IDBObjectStore {
const operation = async () => {
if (BridgeIDBFactory.enableTracing) {
- console.log("running get operation:", recordRequest);
+ console.log("running getKey operation:", recordRequest);
}
const { btx } = this._confirmStartedBackendTransaction();
const result = await this._backend.getRecords(btx, recordRequest);
if (BridgeIDBFactory.enableTracing) {
- console.log("get operation result count:", result.count);
+ console.log("getKey operation result count:", result.count);
}
if (result.count === 0) {
diff --git a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts
index ecfac82f4..4843b13ab 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts
+++ b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-objectstore.test.ts
@@ -112,7 +112,8 @@ test.cb("WPT test idbcursor_continue_objectstore3.htm", (t) => {
};
});
-// IDBCursor.continue() - object store - attempt to iterate to the next record when the direction is set for the previous record
+// IDBCursor.continue() - object store - attempt to iterate to the
+// next record when the direction is set for the previous record
test.cb("WPT test idbcursor_continue_objectstore4.htm", (t) => {
var db: any;
const records = [
@@ -151,7 +152,9 @@ test.cb("WPT test idbcursor_continue_objectstore4.htm", (t) => {
t.deepEqual(cursor.value.pKey, records[1].pKey, "second cursor pkey");
t.throws(
() => {
+ console.log("**** continuing cursor");
cursor.continue(records[2].pKey);
+ console.log("**** this should not happen");
},
{
name: "DataError",
diff --git a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts
index c80e276e6..604061acd 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts
+++ b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts
@@ -18,9 +18,10 @@ test("WPT idbcursor-delete-exception-order.htm", async (t) => {
const cursor = r.result;
t.assert(!!cursor);
t.throws(
- () => {},
+ () => {
+ cursor!.delete();
+ },
{ name: "TransactionInactiveError" },
-
'"Transaction inactive" check (TransactionInactivError) ' +
'should precede "read only" check (ReadOnlyError)',
);
@@ -72,7 +73,9 @@ test("WPT idbcursor-delete-exception-order.htm", async (t) => {
r.onsuccess = null;
const cursor = r.result;
t.throws(
- () => {},
+ () => {
+ cursor!.delete();
+ },
{ name: "ReadOnlyError" },
'"Read only" check (ReadOnlyError) should precede ' +
'"key only flag" (InvalidStateError) check',
diff --git a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-update-index.test.ts b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-update-index.test.ts
index 950a31e38..363ef4afa 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-update-index.test.ts
+++ b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-update-index.test.ts
@@ -202,8 +202,7 @@ test.cb("WPT test idbcursor_update_index5.htm", (t) => {
var record = cursor.value;
// Original test uses different uncloneable value
- record.data = { foo: "42" };
- record.data.me = record.data;
+ record.data = { foo: () => {} };
t.throws(
function () {
cursor.update(record);