idb: fix test / backend
This commit is contained in:
parent
9c85f6277b
commit
627ae6958e
@ -205,6 +205,7 @@ export class BridgeIDBCursor implements IDBCursor {
|
|||||||
);
|
);
|
||||||
BridgeIDBFactory.enableTracing &&
|
BridgeIDBFactory.enableTracing &&
|
||||||
console.log("cursor type ", this.toString());
|
console.log("cursor type ", this.toString());
|
||||||
|
const isIndex = this._indexName !== undefined;
|
||||||
const recordGetRequest: RecordGetRequest = {
|
const recordGetRequest: RecordGetRequest = {
|
||||||
direction: this.direction,
|
direction: this.direction,
|
||||||
indexName: this._indexName,
|
indexName: this._indexName,
|
||||||
@ -213,8 +214,8 @@ export class BridgeIDBCursor implements IDBCursor {
|
|||||||
limit: 1,
|
limit: 1,
|
||||||
range: simplifyRange(this._range),
|
range: simplifyRange(this._range),
|
||||||
objectStoreName: this._objectStoreName,
|
objectStoreName: this._objectStoreName,
|
||||||
advanceIndexKey: key,
|
advanceIndexKey: isIndex ? key : undefined,
|
||||||
advancePrimaryKey: primaryKey,
|
advancePrimaryKey: isIndex ? primaryKey : key,
|
||||||
resultLevel: this._keyOnly ? ResultLevel.OnlyKeys : ResultLevel.Full,
|
resultLevel: this._keyOnly ? ResultLevel.OnlyKeys : ResultLevel.Full,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1113,12 +1114,7 @@ export class BridgeIDBIndex implements IDBIndex {
|
|||||||
|
|
||||||
this._confirmActiveTransaction();
|
this._confirmActiveTransaction();
|
||||||
|
|
||||||
if (range === null) {
|
range = simplifyRange(range);
|
||||||
range = undefined;
|
|
||||||
}
|
|
||||||
if (range !== undefined && !(range instanceof BridgeIDBKeyRange)) {
|
|
||||||
range = BridgeIDBKeyRange.only(valueToKey(range));
|
|
||||||
}
|
|
||||||
|
|
||||||
const request = new BridgeIDBRequest();
|
const request = new BridgeIDBRequest();
|
||||||
request._source = this;
|
request._source = this;
|
||||||
@ -1793,10 +1789,6 @@ export class BridgeIDBObjectStore implements IDBObjectStore {
|
|||||||
console.log(`getting from object store ${this._name} key ${query}`);
|
console.log(`getting from object store ${this._name} key ${query}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.length === 0) {
|
|
||||||
throw new TypeError();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this._transaction._active) {
|
if (!this._transaction._active) {
|
||||||
throw new TransactionInactiveError();
|
throw new TransactionInactiveError();
|
||||||
}
|
}
|
||||||
@ -1811,19 +1803,7 @@ export class BridgeIDBObjectStore implements IDBObjectStore {
|
|||||||
count = -1;
|
count = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let keyRange: BridgeIDBKeyRange;
|
let keyRange: BridgeIDBKeyRange | null = simplifyRange(query);
|
||||||
|
|
||||||
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}'`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const recordRequest: RecordGetRequest = {
|
const recordRequest: RecordGetRequest = {
|
||||||
objectStoreName: this._name,
|
objectStoreName: this._name,
|
||||||
@ -1877,19 +1857,7 @@ export class BridgeIDBObjectStore implements IDBObjectStore {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let keyRange: BridgeIDBKeyRange;
|
let keyRange: BridgeIDBKeyRange | null = simplifyRange(query);
|
||||||
|
|
||||||
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}'`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const recordRequest: RecordGetRequest = {
|
const recordRequest: RecordGetRequest = {
|
||||||
objectStoreName: this._name,
|
objectStoreName: this._name,
|
||||||
@ -1904,13 +1872,13 @@ export class BridgeIDBObjectStore implements IDBObjectStore {
|
|||||||
|
|
||||||
const operation = async () => {
|
const operation = async () => {
|
||||||
if (BridgeIDBFactory.enableTracing) {
|
if (BridgeIDBFactory.enableTracing) {
|
||||||
console.log("running get operation:", recordRequest);
|
console.log("running getKey operation:", recordRequest);
|
||||||
}
|
}
|
||||||
const { btx } = this._confirmStartedBackendTransaction();
|
const { btx } = this._confirmStartedBackendTransaction();
|
||||||
const result = await this._backend.getRecords(btx, recordRequest);
|
const result = await this._backend.getRecords(btx, recordRequest);
|
||||||
|
|
||||||
if (BridgeIDBFactory.enableTracing) {
|
if (BridgeIDBFactory.enableTracing) {
|
||||||
console.log("get operation result count:", result.count);
|
console.log("getKey operation result count:", result.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.count === 0) {
|
if (result.count === 0) {
|
||||||
|
@ -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) => {
|
test.cb("WPT test idbcursor_continue_objectstore4.htm", (t) => {
|
||||||
var db: any;
|
var db: any;
|
||||||
const records = [
|
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.deepEqual(cursor.value.pKey, records[1].pKey, "second cursor pkey");
|
||||||
t.throws(
|
t.throws(
|
||||||
() => {
|
() => {
|
||||||
|
console.log("**** continuing cursor");
|
||||||
cursor.continue(records[2].pKey);
|
cursor.continue(records[2].pKey);
|
||||||
|
console.log("**** this should not happen");
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "DataError",
|
name: "DataError",
|
||||||
|
@ -18,9 +18,10 @@ test("WPT idbcursor-delete-exception-order.htm", async (t) => {
|
|||||||
const cursor = r.result;
|
const cursor = r.result;
|
||||||
t.assert(!!cursor);
|
t.assert(!!cursor);
|
||||||
t.throws(
|
t.throws(
|
||||||
() => {},
|
() => {
|
||||||
|
cursor!.delete();
|
||||||
|
},
|
||||||
{ name: "TransactionInactiveError" },
|
{ name: "TransactionInactiveError" },
|
||||||
|
|
||||||
'"Transaction inactive" check (TransactionInactivError) ' +
|
'"Transaction inactive" check (TransactionInactivError) ' +
|
||||||
'should precede "read only" check (ReadOnlyError)',
|
'should precede "read only" check (ReadOnlyError)',
|
||||||
);
|
);
|
||||||
@ -72,7 +73,9 @@ test("WPT idbcursor-delete-exception-order.htm", async (t) => {
|
|||||||
r.onsuccess = null;
|
r.onsuccess = null;
|
||||||
const cursor = r.result;
|
const cursor = r.result;
|
||||||
t.throws(
|
t.throws(
|
||||||
() => {},
|
() => {
|
||||||
|
cursor!.delete();
|
||||||
|
},
|
||||||
{ name: "ReadOnlyError" },
|
{ name: "ReadOnlyError" },
|
||||||
'"Read only" check (ReadOnlyError) should precede ' +
|
'"Read only" check (ReadOnlyError) should precede ' +
|
||||||
'"key only flag" (InvalidStateError) check',
|
'"key only flag" (InvalidStateError) check',
|
||||||
|
@ -202,8 +202,7 @@ test.cb("WPT test idbcursor_update_index5.htm", (t) => {
|
|||||||
|
|
||||||
var record = cursor.value;
|
var record = cursor.value;
|
||||||
// Original test uses different uncloneable value
|
// Original test uses different uncloneable value
|
||||||
record.data = { foo: "42" };
|
record.data = { foo: () => {} };
|
||||||
record.data.me = record.data;
|
|
||||||
t.throws(
|
t.throws(
|
||||||
function () {
|
function () {
|
||||||
cursor.update(record);
|
cursor.update(record);
|
||||||
|
Loading…
Reference in New Issue
Block a user