Fix errors with cosmetic filter exception in the logger

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/602
This commit is contained in:
Raymond Hill 2019-05-28 07:21:16 -04:00
parent adfe68d20e
commit 8828522fe8
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 14 additions and 9 deletions

View File

@ -43,7 +43,7 @@ let simpleDeclarativeStr;
const complexDeclarativeSet = new Set(); const complexDeclarativeSet = new Set();
let complexDeclarativeStr; let complexDeclarativeStr;
const proceduralDict = new Map(); const proceduralDict = new Map();
const exceptionSet = new Set(); const exceptionDict = new Map();
let exceptionStr; let exceptionStr;
const nodesToProcess = new Set(); const nodesToProcess = new Set();
let shouldProcessDeclarativeComplex = false; let shouldProcessDeclarativeComplex = false;
@ -121,17 +121,17 @@ const processProcedural = function(out) {
/******************************************************************************/ /******************************************************************************/
const processExceptions = function(out) { const processExceptions = function(out) {
if ( exceptionSet.size === 0 ) { return; } if ( exceptionDict.size === 0 ) { return; }
if ( exceptionStr === undefined ) { if ( exceptionStr === undefined ) {
exceptionStr = Array.from(exceptionSet).join(',\n'); exceptionStr = Array.from(exceptionDict.keys()).join(',\n');
} }
if ( document.querySelector(exceptionStr) === null ) { return; } if ( document.querySelector(exceptionStr) === null ) { return; }
for ( const selector of exceptionSet ) { for ( const [ selector, raw ] of exceptionDict ) {
if ( document.querySelector(selector) === null ) { continue; } if ( document.querySelector(selector) === null ) { continue; }
out.push(`#@#${selector}`); out.push(`#@#${raw}`);
exceptionSet.delete(selector); exceptionDict.delete(selector);
exceptionStr = undefined; exceptionStr = undefined;
loggedSelectors.add(selector); loggedSelectors.add(raw);
} }
}; };
@ -255,7 +255,12 @@ const handlers = {
if ( Array.isArray(changes.exceptions) ) { if ( Array.isArray(changes.exceptions) ) {
for ( const selector of changes.exceptions ) { for ( const selector of changes.exceptions ) {
if ( loggedSelectors.has(selector) ) { continue; } if ( loggedSelectors.has(selector) ) { continue; }
exceptionSet.add(selector); if ( selector.charCodeAt(0) === 0x7B /* '{' */ ) {
const details = JSON.parse(selector);
exceptionDict.set(details.style[0], details.raw);
} else {
exceptionDict.set(selector, selector);
}
} }
exceptionStr = undefined; exceptionStr = undefined;
shouldProcessExceptions = true; shouldProcessExceptions = true;
@ -290,7 +295,7 @@ const handlers = {
if ( proceduralDict.size !== 0 ) { if ( proceduralDict.size !== 0 ) {
shouldProcessProcedural = true; shouldProcessProcedural = true;
} }
if ( exceptionSet.size !== 0 ) { if ( exceptionDict.size !== 0 ) {
shouldProcessExceptions = true; shouldProcessExceptions = true;
} }
if ( shouldProcess() ) { if ( shouldProcess() ) {