1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Ensure IDBDatabase wrapper isn't prematurely collected.");
13 var deleteRequest = evalAndLog("indexedDB.deleteDatabase(dbname)");
14 deleteRequest.onblocked = unexpectedBlockedCallback;
15 deleteRequest.onerror = unexpectedErrorCallback;
16 deleteRequest.onsuccess = openDB;
23 var openRequest = evalAndLog("indexedDB.open(dbname, 1)");
24 openRequest.onblocked = unexpectedBlockedCallback;
25 openRequest.onerror = unexpectedErrorCallback;
26 openRequest.onupgradeneeded = onUpgradeNeeded;
27 openRequest.onsuccess = openSuccess;
30 function onUpgradeNeeded(evt) {
32 evalAndLog("db = event.target.result");
33 evalAndLog("db.createObjectStore('store').createIndex('index', 'keyPath')");
34 evalAndLog("db = null");
37 function openSuccess(evt)
40 var db = event.target.result;
41 db.onversionchange = onVersionChange;
42 evalAndLog("sawVersionChangeEvent = false");
44 // All these local references should get collected, but the database's
45 // wrapper shouldn't get collected before the database itself.
46 var transaction = db.transaction('store', 'readonly');
47 var objectStore = transaction.objectStore('store');
48 var request = objectStore.get(0);
49 request.onsuccess = function() {
50 setTimeout(collectGarbage, 0);
54 function onVersionChange(evt)
57 evalAndLog("event.target.close()");
58 evalAndLog("sawVersionChangeEvent = true");
61 function collectGarbage()
64 evalAndLog("self.gc()");
66 setTimeout(openAgain, 0);
73 var openRequest = evalAndLog("indexedDB.open(dbname, 2)");
74 openRequest.onblocked = unexpectedBlockedCallback;
75 openRequest.onerror = unexpectedErrorCallback;
76 openRequest.onsuccess = openAgainSuccess;
79 function openAgainSuccess(evt)
82 shouldBeTrue("sawVersionChangeEvent");