From 172f98d4622a591af12cf6c98697ebb38e7f1da5 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 8 Dec 2014 14:16:13 -0200 Subject: [PATCH] this should help with #402 --- src/js/assets.js | 17 ++++++++++++++--- src/js/storage.js | 24 +++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/js/assets.js b/src/js/assets.js index 1243b9c71..6b185c1c0 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -142,10 +142,21 @@ var cachedAssetsManager = (function() { details.error = 'Error: ' + lastError.message; console.error('µBlock> cachedAssetsManager.load():', details.error); cbError(details); - } else { - details.content = bin[cachedContentPath]; - cbSuccess(details); + return; } + // Not sure how this can happen, but I've seen it happen. It could + // be because the save occurred while I was stepping in the code + // though, which means it would not occur during normal operation. + // Still, just to be safe. + if ( bin[cachedContentPath] === undefined ) { + details.error = 'Error: not found'; + delete entries[path]; + vAPI.storage.set({ 'cached_asset_entries': entries }); + cbError(details); + return; + } + details.content = bin[cachedContentPath]; + cbSuccess(details); }; var onEntries = function(entries) { if ( entries[path] === undefined ) { diff --git a/src/js/storage.js b/src/js/storage.js index 0c5c3efac..9e2e042ba 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -636,22 +636,32 @@ µb.updater.restart(nextUpdate); }; - // https://github.com/gorhill/uBlock/issues/226 - // Whitelist in memory. - // Whitelist parser needs PSL to be ready. - var onWhitelistReady = function() { - onAllDone(); - }; + var filtersReady = false; + var whitelistReady = false; // Filters are in memory. // Filter engines need PSL to be ready. var onFiltersReady = function() { - µb.loadWhitelist(onWhitelistReady); + filtersReady = true; + if ( whitelistReady ) { + onAllDone(); + } + }; + + // https://github.com/gorhill/uBlock/issues/226 + // Whitelist in memory. + // Whitelist parser needs PSL to be ready. + var onWhitelistReady = function() { + whitelistReady = true; + if ( filtersReady ) { + onAllDone(); + } }; // Load order because dependencies: // User settings -> PSL -> [filter lists, user whitelist] var onPSLReady = function() { + µb.loadWhitelist(onWhitelistReady); µb.loadFilterLists(onFiltersReady); };