From e06cf1de9be7621d04d6e40d82e61a963d21f5a8 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 12 Feb 2019 07:13:37 -0500 Subject: [PATCH] Shield early request handler against re-entrance Unlikely re-entrance is occurring, but there is no harm shielding against it -- just in case. --- platform/firefox/vapi-webrequest.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/platform/firefox/vapi-webrequest.js b/platform/firefox/vapi-webrequest.js index 78b1cfc03..547ad2e7e 100644 --- a/platform/firefox/vapi-webrequest.js +++ b/platform/firefox/vapi-webrequest.js @@ -142,10 +142,10 @@ vAPI.net.onBeforeReady = vAPI.net.onBeforeReady || (function() { // https://github.com/uBlockOrigin/uBlock-issues/issues/407 if ( vAPI.webextFlavor.soup.has('firefox') === false ) { return; } - let pendings; + let pendingSet; const handler = function(details) { - if ( pendings === undefined ) { return; } + if ( pendingSet === undefined ) { return; } if ( details.tabId < 0 ) { return; } const pending = { @@ -158,14 +158,14 @@ vAPI.net.onBeforeReady = vAPI.net.onBeforeReady || (function() { pending.resolve = resolve; }); - pendings.push(pending); + pendingSet.push(pending); return pending.promise; }; return { start: function() { - pendings = []; + pendingSet = []; browser.webRequest.onBeforeRequest.addListener( handler, { urls: [ 'http://*/*', 'https://*/*' ] }, @@ -173,12 +173,13 @@ vAPI.net.onBeforeReady = vAPI.net.onBeforeReady || (function() { ); }, stop: function(resolver) { - if ( pendings === undefined ) { return; } - for ( const pending of pendings ) { - vAPI.net.normalizeDetails(pending.details); - pending.resolve(resolver(pending.details)); + if ( pendingSet === undefined ) { return; } + const resolvingSet = pendingSet; // not sure if re-entrance + pendingSet = undefined; // can occur... + for ( const entry of resolvingSet ) { + vAPI.net.normalizeDetails(entry.details); + entry.resolve(resolver(entry.details)); } - pendings = undefined; }, }; })();