Created
September 19, 2016 20:41
-
-
Save dfahlander/ed7cd59da8fe69c28e78e302fb67c64f to your computer and use it in GitHub Desktop.
Naildown of webkit bug #158833
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<script> | |
const log = txt => document.writeln(`${txt}<br/>`); | |
log("Deleting db2"); | |
indexedDB.deleteDatabase("db2").onsuccess = ()=> { | |
log("db2 deleted"); | |
let req = indexedDB.open("db2", 1); | |
req.onupgradeneeded = e => { | |
log ("Creating db2"); | |
let db = req.transaction.db; | |
let schools = db.createObjectStore('schools', { keyPath: 'id', autoIncrement: true }); | |
schools.createIndex ('city', 'city'); | |
schools.add({name: 'Stockholm University', city: 'Stockholm', id: 1}); | |
schools.add({name: 'Uppsala University', city: 'Uppsala', id: 100}); | |
schools.add({name: 'Chalmers', city: 'Gothenburg', id: 101}); | |
let students = db.createObjectStore('students', { keyPath: 'id', autoIncrement: true }); | |
students.createIndex ('name', 'name'); | |
students.add({name: 'Adam Anderson', id: 1}); | |
students.add({name: 'Bertil Bengtson', id: 2}); | |
} | |
req.onsuccess = ()=> { | |
let db = req.result; | |
let tx = db.transaction(['schools'], 'readonly'); | |
dump(tx.objectStore('schools'), ()=> { | |
dump(tx.objectStore('schools').index('city'), ()=> { | |
tx = db.transaction('students', 'readonly'); | |
dump(tx.objectStore('students'), ()=>{ | |
dump(tx.objectStore('students').index('name'), ()=>{ | |
log("Done."); | |
}) | |
}); | |
}); | |
}); | |
} | |
} | |
function dump (idx, done) { | |
log (idx instanceof IDBObjectStore ? | |
`Enumerating ObjectStore '${idx.name}' by primary key` : | |
`Enumerating index '${idx.name}' on '${idx.objectStore.name}'`); | |
idx.openCursor().onsuccess = e => { | |
let cursor = e.target.result; | |
if (cursor) { | |
log(`key: ${cursor.key}, primaryKey: ${cursor.primaryKey}, value: ${JSON.stringify(cursor.value)}`); | |
cursor.continue(); | |
} else { | |
done(); | |
} | |
} | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment