mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Shield early request handler against re-entrance
Unlikely re-entrance is occurring, but there is no harm shielding against it -- just in case.
This commit is contained in:
parent
0011040cbe
commit
e06cf1de9b
@ -142,10 +142,10 @@ vAPI.net.onBeforeReady = vAPI.net.onBeforeReady || (function() {
|
|||||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/407
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/407
|
||||||
if ( vAPI.webextFlavor.soup.has('firefox') === false ) { return; }
|
if ( vAPI.webextFlavor.soup.has('firefox') === false ) { return; }
|
||||||
|
|
||||||
let pendings;
|
let pendingSet;
|
||||||
|
|
||||||
const handler = function(details) {
|
const handler = function(details) {
|
||||||
if ( pendings === undefined ) { return; }
|
if ( pendingSet === undefined ) { return; }
|
||||||
if ( details.tabId < 0 ) { return; }
|
if ( details.tabId < 0 ) { return; }
|
||||||
|
|
||||||
const pending = {
|
const pending = {
|
||||||
@ -158,14 +158,14 @@ vAPI.net.onBeforeReady = vAPI.net.onBeforeReady || (function() {
|
|||||||
pending.resolve = resolve;
|
pending.resolve = resolve;
|
||||||
});
|
});
|
||||||
|
|
||||||
pendings.push(pending);
|
pendingSet.push(pending);
|
||||||
|
|
||||||
return pending.promise;
|
return pending.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start: function() {
|
start: function() {
|
||||||
pendings = [];
|
pendingSet = [];
|
||||||
browser.webRequest.onBeforeRequest.addListener(
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
handler,
|
handler,
|
||||||
{ urls: [ 'http://*/*', 'https://*/*' ] },
|
{ urls: [ 'http://*/*', 'https://*/*' ] },
|
||||||
@ -173,12 +173,13 @@ vAPI.net.onBeforeReady = vAPI.net.onBeforeReady || (function() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
stop: function(resolver) {
|
stop: function(resolver) {
|
||||||
if ( pendings === undefined ) { return; }
|
if ( pendingSet === undefined ) { return; }
|
||||||
for ( const pending of pendings ) {
|
const resolvingSet = pendingSet; // not sure if re-entrance
|
||||||
vAPI.net.normalizeDetails(pending.details);
|
pendingSet = undefined; // can occur...
|
||||||
pending.resolve(resolver(pending.details));
|
for ( const entry of resolvingSet ) {
|
||||||
|
vAPI.net.normalizeDetails(entry.details);
|
||||||
|
entry.resolve(resolver(entry.details));
|
||||||
}
|
}
|
||||||
pendings = undefined;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user