1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-18 17:02:27 +02:00
This commit is contained in:
Raymond Hill 2018-07-23 13:13:47 -04:00
parent dc75c39841
commit 3bcdddfb9f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -210,26 +210,43 @@ 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 = () => {
if ( callback !== undefined ) {
let cb = callback;
callback = undefined;
cb();
}
};
try {
let transaction = db.transaction(STORAGE_NAME, 'readwrite');
transaction.oncomplete = transaction.oncomplete =
transaction.onerror = transaction.onerror =
transaction.onabort = callback; transaction.onabort = finish;
var table = transaction.objectStore(STORAGE_NAME); let table = transaction.objectStore(STORAGE_NAME);
for ( var key of keys ) { for ( let key of keys ) {
var entry = {}; let entry = {};
entry.key = key; entry.key = key;
entry.value = input[key]; entry.value = input[key];
table.put(entry); table.put(entry);
entry = undefined; entry = undefined;
} }
} catch (ex) {
finish();
}
}); });
} }