Skip to content

Commit 3bcdddf

Browse files
committed
fix missing exception handler (uBlockOrigin/uBlock-issues#141)
1 parent dc75c39 commit 3bcdddf

1 file changed

Lines changed: 29 additions & 12 deletions

File tree

platform/chromium/vapi-cachestorage.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,25 +210,42 @@ vAPI.cacheStorage = (function() {
210210
});
211211
}
212212

213+
// https://github.com/uBlockOrigin/uBlock-issues/issues/141
214+
// Mind that IDBDatabase.transaction() and IDBObjectStore.put()
215+
// can throw:
216+
// https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/transaction
217+
// https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/put
218+
213219
function putToDb(input, callback) {
214220
if ( typeof callback !== 'function' ) {
215221
callback = noopfn;
216222
}
217-
var keys = Object.keys(input);
223+
let keys = Object.keys(input);
218224
if ( keys.length === 0 ) { return callback(); }
219225
getDb(function(db) {
220226
if ( !db ) { return callback(); }
221-
var transaction = db.transaction(STORAGE_NAME, 'readwrite');
222-
transaction.oncomplete =
223-
transaction.onerror =
224-
transaction.onabort = callback;
225-
var table = transaction.objectStore(STORAGE_NAME);
226-
for ( var key of keys ) {
227-
var entry = {};
228-
entry.key = key;
229-
entry.value = input[key];
230-
table.put(entry);
231-
entry = undefined;
227+
let finish = () => {
228+
if ( callback !== undefined ) {
229+
let cb = callback;
230+
callback = undefined;
231+
cb();
232+
}
233+
};
234+
try {
235+
let transaction = db.transaction(STORAGE_NAME, 'readwrite');
236+
transaction.oncomplete =
237+
transaction.onerror =
238+
transaction.onabort = finish;
239+
let table = transaction.objectStore(STORAGE_NAME);
240+
for ( let key of keys ) {
241+
let entry = {};
242+
entry.key = key;
243+
entry.value = input[key];
244+
table.put(entry);
245+
entry = undefined;
246+
}
247+
} catch (ex) {
248+
finish();
232249
}
233250
});
234251
}

0 commit comments

Comments
 (0)