1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-02 00:42:45 +01:00
This commit is contained in:
gorhill 2015-01-16 10:57:56 -05:00
parent 478476439c
commit d7b16a8383
3 changed files with 31 additions and 20 deletions

View File

@ -307,6 +307,14 @@ var updateLocalChecksums = function() {
var getRepoMetadata = function(callback) { var getRepoMetadata = function(callback) {
callback = callback || nullFunc; callback = callback || nullFunc;
// https://github.com/gorhill/uBlock/issues/515
// Handle re-entrancy here, i.e. we MUST NOT tamper with the waiting list
// of callers, if any, except to add one at the end of the list.
if ( repoMetadata !== null && repoMetadata.waiting.length !== 0 ) {
repoMetadata.waiting.push(callback);
return;
}
if ( exports.allowRemoteFetch && lastRepoMetaIsRemote === false ) { if ( exports.allowRemoteFetch && lastRepoMetaIsRemote === false ) {
lastRepoMetaTimestamp = 0; lastRepoMetaTimestamp = 0;
} }
@ -314,11 +322,7 @@ var getRepoMetadata = function(callback) {
repoMetadata = null; repoMetadata = null;
} }
if ( repoMetadata !== null ) { if ( repoMetadata !== null ) {
if ( repoMetadata.waiting.length !== 0 ) { callback(repoMetadata);
repoMetadata.waiting.push(callback);
} else {
callback(repoMetadata);
}
return; return;
} }
@ -356,9 +360,16 @@ var getRepoMetadata = function(callback) {
updateLocalChecksums(); updateLocalChecksums();
} }
// Notify all waiting callers // Notify all waiting callers
while ( callback = repoMetadata.waiting.pop() ) { // https://github.com/gorhill/uBlock/issues/515
callback(repoMetadata); // VERY IMPORTANT: because of re-entrancy, we MUST:
// - process the waiting callers in a FIFO manner
// - not cache repoMetadata.waiting.length, we MUST use the live
// value, because it can change while looping
// - not change the waiting list until they are all processed
for ( var i = 0; i < repoMetadata.waiting.length; i++ ) {
repoMetadata.waiting[i](repoMetadata);
} }
repoMetadata.waiting.length = 0;
}; };
var validateChecksums = function(details) { var validateChecksums = function(details) {

View File

@ -497,7 +497,7 @@ var load = function() {
var loadContent = function(urlKey, hash) { var loadContent = function(urlKey, hash) {
var binKey = storageKeyFromHash(hash); var binKey = storageKeyFromHash(hash);
var onContentReady = function(bin) { var onContentReady = function(bin) {
if ( vAPI.lastError || bin.hasOwnProperty(binKey) === false ) { if ( vAPI.lastError() || bin.hasOwnProperty(binKey) === false ) {
//console.debug('mirrors.load(): failed to load content "%s"', binKey); //console.debug('mirrors.load(): failed to load content "%s"', binKey);
removeMetadata(urlKey); removeMetadata(urlKey);
removeContent(binKey); removeContent(binKey);

View File

@ -418,6 +418,7 @@
// https://github.com/gorhill/httpswitchboard/issues/15 // https://github.com/gorhill/httpswitchboard/issues/15
// Ensure localhost et al. don't end up in the ubiquitous blacklist. // Ensure localhost et al. don't end up in the ubiquitous blacklist.
// TODO: do this only if it's not an [Adblock] list
line = line line = line
.replace(/\s+#.*$/, '') .replace(/\s+#.*$/, '')
.toLowerCase() .toLowerCase()
@ -594,10 +595,18 @@
var µb = this; var µb = this;
var fromSelfie = false; var fromSelfie = false;
// Filter lists
// Whitelist
var countdown = 2;
// Final initialization steps after all needed assets are in memory. // Final initialization steps after all needed assets are in memory.
// - Initialize internal state with maybe already existing tabs. // - Initialize internal state with maybe already existing tabs.
// - Schedule next update operation. // - Schedule next update operation.
var onAllDone = function() { var doCountdown = function() {
countdown -= 1;
if ( countdown !== 0 ) {
return;
}
// https://github.com/gorhill/uBlock/issues/426 // https://github.com/gorhill/uBlock/issues/426
// Important: remove barrier to remote fetching, this was useful only // Important: remove barrier to remote fetching, this was useful only
// for launch time. // for launch time.
@ -610,16 +619,10 @@
µb.updater.restart(µb.firstUpdateAfter); µb.updater.restart(µb.firstUpdateAfter);
}; };
var filtersReady = false;
var whitelistReady = false;
// Filters are in memory. // Filters are in memory.
// Filter engines need PSL to be ready. // Filter engines need PSL to be ready.
var onFiltersReady = function() { var onFiltersReady = function() {
filtersReady = true; doCountdown();
if ( whitelistReady ) {
onAllDone();
}
}; };
// https://github.com/gorhill/uBlock/issues/226 // https://github.com/gorhill/uBlock/issues/226
@ -627,10 +630,7 @@
// Whitelist parser needs PSL to be ready. // Whitelist parser needs PSL to be ready.
// gorhill 2014-12-15: not anymore // gorhill 2014-12-15: not anymore
var onWhitelistReady = function() { var onWhitelistReady = function() {
whitelistReady = true; doCountdown();
if ( filtersReady ) {
onAllDone();
}
}; };
// Load order because dependencies: // Load order because dependencies: