From 7eeba29220d62e561d05869909b9c22e326ca6ae Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 27 Feb 2018 06:54:48 -0500 Subject: [PATCH] fix #3551: regressions as a result of fix to #3428 --- src/js/logger-ui.js | 2 +- src/js/popup.js | 7 +++++-- src/js/tab.js | 33 +++++++++++++++++++-------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js index c98de8632..09a34119c 100644 --- a/src/js/logger-ui.js +++ b/src/js/logger-ui.js @@ -117,7 +117,7 @@ var classNameFromTabId = function(tabId) { if ( tabId < 0 ) { return 'tab_bts'; } - if ( tabId !== '' ) { + if ( tabId !== 0 ) { return 'tab_' + tabId; } return ''; diff --git a/src/js/popup.js b/src/js/popup.js index dfd38d2d0..4fa02ba88 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -624,7 +624,10 @@ var renderOnce = function() { /******************************************************************************/ var renderPopupLazy = function() { - messaging.send('popupPanel', { what: 'getPopupLazyData', tabId: popupData.tabId }); + messaging.send( + 'popupPanel', + { what: 'getPopupLazyData', tabId: popupData.tabId } + ); }; var onPopupMessage = function(data) { @@ -1072,7 +1075,7 @@ var onHideTooltip = function() { // Extract the tab id of the page this popup is for var matches = window.location.search.match(/[\?&]tabId=([^&]+)/); if ( matches && matches.length === 2 ) { - tabId = matches[1]; + tabId = parseInt(matches[1], 10) || 0; } getPopupData(tabId); diff --git a/src/js/tab.js b/src/js/tab.js index 23f0758e2..42fde86d8 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -136,7 +136,7 @@ housekeep itself. var mostRecentRootDocURL = ''; var mostRecentRootDocURLTimestamp = 0; - var popupCandidates = Object.create(null); + var popupCandidates = new Map(); var PopupCandidate = function(targetTabId, openerTabId) { this.targetTabId = targetTabId; @@ -155,7 +155,7 @@ housekeep itself. if ( this.selfDestructionTimer !== null ) { clearTimeout(this.selfDestructionTimer); } - delete popupCandidates[this.targetTabId]; + popupCandidates.delete(this.targetTabId); }; PopupCandidate.prototype.launchSelfDestruction = function() { @@ -166,31 +166,36 @@ housekeep itself. }; var popupCandidateTest = function(targetTabId) { - var candidates = popupCandidates, - entry; - for ( var tabId in candidates ) { - entry = candidates[tabId]; - if ( targetTabId !== tabId && targetTabId !== entry.opener.tabId ) { + for ( var entry of popupCandidates ) { + var tabId = entry[0]; + var candidate = entry[1]; + if ( + targetTabId !== tabId && + targetTabId !== candidate.opener.tabId + ) { continue; } // https://github.com/gorhill/uBlock/issues/3129 // If the trigger is a change in the opener's URL, mark the entry // as candidate for popunder filtering. - if ( targetTabId === entry.opener.tabId ) { - entry.opener.popunder = true; + if ( targetTabId === candidate.opener.tabId ) { + candidate.opener.popunder = true; } - if ( vAPI.tabs.onPopupUpdated(tabId, entry.opener) === true ) { - entry.destroy(); + if ( vAPI.tabs.onPopupUpdated(tabId, candidate.opener) === true ) { + candidate.destroy(); } else { - entry.launchSelfDestruction(); + candidate.launchSelfDestruction(); } } }; vAPI.tabs.onPopupCreated = function(targetTabId, openerTabId) { - var popup = popupCandidates[targetTabId]; + var popup = popupCandidates.get(targetTabId); if ( popup === undefined ) { - popupCandidates[targetTabId] = new PopupCandidate(targetTabId, openerTabId); + popupCandidates.set( + targetTabId, + new PopupCandidate(targetTabId, openerTabId) + ); } popupCandidateTest(targetTabId); };