mirror of https://github.com/gorhill/uBlock.git
fix missing exception handler (https://github.com/uBlockOrigin/uBlock-issues/issues/141)
This commit is contained in:
parent
dc75c39841
commit
3bcdddfb9f
|
@ -210,25 +210,42 @@ vAPI.cacheStorage = (function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/141
|
||||||
|
// Mind that IDBDatabase.transaction() and IDBObjectStore.put()
|
||||||
|
// can throw:
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/transaction
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/put
|
||||||
|
|
||||||
function putToDb(input, callback) {
|
function putToDb(input, callback) {
|
||||||
if ( typeof callback !== 'function' ) {
|
if ( typeof callback !== 'function' ) {
|
||||||
callback = noopfn;
|
callback = noopfn;
|
||||||
}
|
}
|
||||||
var keys = Object.keys(input);
|
let keys = Object.keys(input);
|
||||||
if ( keys.length === 0 ) { return callback(); }
|
if ( keys.length === 0 ) { return callback(); }
|
||||||
getDb(function(db) {
|
getDb(function(db) {
|
||||||
if ( !db ) { return callback(); }
|
if ( !db ) { return callback(); }
|
||||||
var transaction = db.transaction(STORAGE_NAME, 'readwrite');
|
let finish = () => {
|
||||||
transaction.oncomplete =
|
if ( callback !== undefined ) {
|
||||||
transaction.onerror =
|
let cb = callback;
|
||||||
transaction.onabort = callback;
|
callback = undefined;
|
||||||
var table = transaction.objectStore(STORAGE_NAME);
|
cb();
|
||||||
for ( var key of keys ) {
|
}
|
||||||
var entry = {};
|
};
|
||||||
entry.key = key;
|
try {
|
||||||
entry.value = input[key];
|
let transaction = db.transaction(STORAGE_NAME, 'readwrite');
|
||||||
table.put(entry);
|
transaction.oncomplete =
|
||||||
entry = undefined;
|
transaction.onerror =
|
||||||
|
transaction.onabort = finish;
|
||||||
|
let table = transaction.objectStore(STORAGE_NAME);
|
||||||
|
for ( let key of keys ) {
|
||||||
|
let entry = {};
|
||||||
|
entry.key = key;
|
||||||
|
entry.value = input[key];
|
||||||
|
table.put(entry);
|
||||||
|
entry = undefined;
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue