Log procedural cosmetic exception filters

Related issue:
- https://github.com/gorhill/uBlock/issues/127

Procedural cosmetic exception filters were the
last class of cosmetic exception filters not
being reported in the logger; this commit fixes
this.

Additionally, ensure that a single DOM listener
can't prevent other listeners from being
processed by throwing an exception. Such approach
would have prevented regression leading to
emergency release 1.22.4:
- https://github.com/gorhill/uBlock/releases/tag/1.22.4
This commit is contained in:
Raymond Hill 2019-09-30 18:21:24 -04:00
parent 95469032a4
commit bf697f344a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 24 additions and 7 deletions

View File

@ -267,7 +267,7 @@ vAPI.SafeAnimationFrame.prototype = {
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/
vAPI.domWatcher = (function() { vAPI.domWatcher = (( ) => {
const addedNodeLists = []; const addedNodeLists = [];
const removedNodeLists = []; const removedNodeLists = [];
@ -311,7 +311,8 @@ vAPI.domWatcher = (function() {
//console.timeEnd('dom watcher/safe observer handler'); //console.timeEnd('dom watcher/safe observer handler');
if ( addedNodes.length === 0 && removedNodes === false ) { return; } if ( addedNodes.length === 0 && removedNodes === false ) { return; }
for ( const listener of getListenerIterator() ) { for ( const listener of getListenerIterator() ) {
listener.onDOMChanged(addedNodes, removedNodes); try { listener.onDOMChanged(addedNodes, removedNodes); }
catch (ex) { }
} }
addedNodes.length = 0; addedNodes.length = 0;
removedNodes = false; removedNodes = false;
@ -373,7 +374,8 @@ vAPI.domWatcher = (function() {
listeners.push(listener); listeners.push(listener);
listenerIteratorDirty = true; listenerIteratorDirty = true;
if ( domIsReady !== true ) { return; } if ( domIsReady !== true ) { return; }
listener.onDOMCreated(); try { listener.onDOMCreated(); }
catch (ex) { }
startMutationObserver(); startMutationObserver();
}; };
@ -401,7 +403,8 @@ vAPI.domWatcher = (function() {
const start = function() { const start = function() {
domIsReady = true; domIsReady = true;
for ( const listener of getListenerIterator() ) { for ( const listener of getListenerIterator() ) {
listener.onDOMCreated(); try { listener.onDOMCreated(); }
catch (ex) { }
} }
startMutationObserver(); startMutationObserver();
}; };

View File

@ -46,6 +46,7 @@ let declarativeStyleStr;
const proceduralDict = new Map(); const proceduralDict = new Map();
const exceptionDict = new Map(); const exceptionDict = new Map();
let exceptionStr; let exceptionStr;
const proceduralExceptionDict = new Map();
const nodesToProcess = new Set(); const nodesToProcess = new Set();
const loggedSelectors = new Set(); const loggedSelectors = new Set();
@ -172,6 +173,17 @@ const processExceptions = function(out) {
/******************************************************************************/ /******************************************************************************/
const processProceduralExceptions = function(out) {
if ( proceduralExceptionDict.size === 0 ) { return; }
for ( const exception of proceduralExceptionDict.values() ) {
if ( exception.test() === false ) { continue; }
out.push(`#@#${exception.raw}`);
proceduralExceptionDict.delete(exception.raw);
}
};
/******************************************************************************/
const processTimer = new vAPI.SafeAnimationFrame(( ) => { const processTimer = new vAPI.SafeAnimationFrame(( ) => {
//console.time('dom logger/scanning for matches'); //console.time('dom logger/scanning for matches');
processTimer.clear(); processTimer.clear();
@ -193,6 +205,7 @@ const processTimer = new vAPI.SafeAnimationFrame(( ) => {
processDeclarativeStyle(toLog); processDeclarativeStyle(toLog);
processProcedural(toLog); processProcedural(toLog);
processExceptions(toLog); processExceptions(toLog);
processProceduralExceptions(toLog);
nodesToProcess.clear(); nodesToProcess.clear();
@ -268,9 +281,10 @@ const handlers = {
exceptionDict.set(details.style[0], details.raw); exceptionDict.set(details.style[0], details.raw);
continue; continue;
} }
// TODO: proceduralExceptionDict.set(
// Handling of procedural cosmetic exception filters details.raw,
// not implemented. vAPI.domFilterer.createProceduralFilter(details)
);
} }
exceptionStr = undefined; exceptionStr = undefined;
} }