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