let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
let objectStore = db.createObjectStore(objectStoreName, { keyPath: null });
// First, add all our data to the object store.
let addedData = 0; for (let i in objectStoreData) {
request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
request.onerror = errorHandler;
request.onsuccess = function (event) { if (++addedData == objectStoreData.length) {
testGenerator.next(event);
}
};
}
event = yield undefined; // Now create the indexes. for (let i in indexData) {
objectStore.createIndex(
indexData[i].name,
indexData[i].keyPath,
indexData[i].options
);
}
is(objectStore.indexNames.length, indexData.length, "Good index count");
yield undefined;
objectStore = db.transaction(objectStoreName).objectStore(objectStoreName);
// Check global properties to make sure they are correct.
is(objectStore.indexNames.length, indexData.length, "Good index count"); for (let i in indexData) {
let found = false; for (let j = 0; j < objectStore.indexNames.length; j++) { if (objectStore.indexNames.item(j) == indexData[i].name) {
found = true; break;
}
}
is(found, true, "objectStore has our index");
let index = objectStore.index(indexData[i].name);
is(index.name, indexData[i].name, "Correct name");
is(index.objectStore.name, objectStore.name, "Correct store name");
is(index.keyPath, indexData[i].keyPath, "Correct keyPath");
is(index.unique, !!indexData[i].options.unique, "Correct unique value");
}
ok(true, "Test group 1");
let keyIndex = 0;
request = objectStore.index("type").openKeyCursor();
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.target.result; if (cursor) {
is(
cursor.key,
objectStoreDataTypeSort[keyIndex].value.type, "Correct key"
);
is(
cursor.primaryKey,
objectStoreDataTypeSort[keyIndex].key, "Correct primary key"
);
ok(!("value" in cursor), "No value");
cursor.continue();
is(
cursor.key,
objectStoreDataTypeSort[keyIndex].value.type, "Correct key"
);
is(
cursor.primaryKey,
objectStoreDataTypeSort[keyIndex].key, "Correct value"
);
ok(!("value" in cursor), "No value");
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.