mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
deal properly with indexedDB not being available (#2925)
This commit is contained in:
parent
b1842ddf16
commit
d165432ded
1 changed files with 17 additions and 12 deletions
|
@ -89,16 +89,26 @@ vAPI.cacheStorage = (function() {
|
|||
function noopfn() {
|
||||
}
|
||||
|
||||
function processPendings() {
|
||||
var cb;
|
||||
while ( (cb = pending.shift()) ) {
|
||||
cb(db);
|
||||
}
|
||||
}
|
||||
|
||||
function getDb(callback) {
|
||||
if ( pending === undefined ) {
|
||||
return callback();
|
||||
}
|
||||
if ( pending.length !== 0 ) {
|
||||
pending.push(callback);
|
||||
return;
|
||||
return pending.push(callback);
|
||||
}
|
||||
if ( db instanceof IDBDatabase ) {
|
||||
return callback(db);
|
||||
}
|
||||
pending.push(callback);
|
||||
if ( pending.length !== 1 ) { return; }
|
||||
// This will fail in private browsing mode.
|
||||
var req = indexedDB.open(STORAGE_NAME, 1);
|
||||
req.onupgradeneeded = function(ev) {
|
||||
db = ev.target.result;
|
||||
|
@ -109,17 +119,12 @@ vAPI.cacheStorage = (function() {
|
|||
req.onsuccess = function(ev) {
|
||||
db = ev.target.result;
|
||||
db.onerror = genericErrorHandler;
|
||||
var cb;
|
||||
while ( (cb = pending.shift()) ) {
|
||||
cb(db);
|
||||
}
|
||||
processPendings();
|
||||
};
|
||||
req.onerror = function(ev) {
|
||||
console.log(ev);
|
||||
var cb;
|
||||
while ( (cb = pending.shift()) ) {
|
||||
cb(db);
|
||||
}
|
||||
req.onerror = function() {
|
||||
console.log(this.error);
|
||||
processPendings();
|
||||
pending = undefined;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue