let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = unexpectedSuccessHandler;
let event = yield undefined;
let db = event.target.result;
for (let i = 0; i < objectStoreInfo.length; i++) {
let info = objectStoreInfo[i];
let objectStore = info.hasOwnProperty("options")
? db.createObjectStore(info.name, info.options)
: db.createObjectStore(info.name);
try {
request = objectStore.createIndex("Hola");
ok(false, "createIndex with no keyPath should throw");
} catch (e) {
ok(true, "createIndex with no keyPath should throw");
}
let ex; try {
objectStore.createIndex("Hola", ["foo"], { multiEntry: true });
} catch (e) {
ex = e;
}
ok(ex, "createIndex with array keyPath and multiEntry should throw");
is(ex.name, "InvalidAccessError", "should throw right exception");
ok(ex instanceof DOMException, "should throw right exception");
is(
ex.code,
DOMException.INVALID_ACCESS_ERR, "should throw right exception"
);
try {
objectStore.createIndex("foo", "bar", 10);
ok(false, "createIndex with bad options should throw");
} catch (e) {
ok(true, "createIndex with bad options threw");
}
ok(
objectStore.createIndex("foo", "bar", { foo: "" }), "createIndex with unknown options should not throw"
);
objectStore.deleteIndex("foo");
// Test index creation, and that it ends up in indexNames.
let objectStoreName = info.name; for (let j = 0; j < indexInfo.length; j++) {
let info = indexInfo[j];
let count = objectStore.indexNames.length;
let index = info.hasOwnProperty("options")
? objectStore.createIndex(info.name, info.keyPath, info.options)
: objectStore.createIndex(info.name, info.keyPath);
let name = info.name; if (name === null) {
name = "null";
} elseif (name === undefined) {
name = "undefined";
}
is(objectStore.indexNames.length, count + 1, "indexNames grew in size");
let found = false; for (let k = 0; k < objectStore.indexNames.length; k++) { if (objectStore.indexNames.item(k) == name) {
found = true; break;
}
}
ok(found, "Name is on objectStore.indexNames");
ok(event.target.transaction, "event has a transaction");
ok(event.target.transaction.db === db, "transaction has the right db");
is(
event.target.transaction.mode, "versionchange", "transaction has the correct mode"
);
is(
event.target.transaction.objectStoreNames.length,
i + 1, "transaction only has one object store"
);
ok(
event.target.transaction.objectStoreNames.contains(objectStoreName), "transaction has the correct object store"
);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.