1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

Prevent spurious instantiation of procedural filterer

Injecting declarative CSS `:style()` selector could cause
the instatiation of the procedural filterer, even when
there was no actual procedural cosmetic filter to
enforce.

This commit ensure that the procedural cosmetic filterer
is instantiated only when there are actual procedural
filters to enforce.
This commit is contained in:
Raymond Hill 2020-09-24 10:53:18 -04:00
parent 5df51d63d1
commit 15e0778750
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -774,35 +774,19 @@ vAPI.injectScriptlet = function(doc, text) {
addProceduralSelectors(selectors) {
const addedSelectors = [];
let mustCommit = this.domIsWatched;
for ( const raw of selectors ) {
if ( this.selectors.has(raw) ) { continue; }
const o = JSON.parse(raw);
// CSS selector-based styles.
if (
o.action !== undefined &&
o.action[0] === ':style' &&
o.tasks === undefined
) {
this.domFilterer.addCSSRule(o.selector, o.action[1]);
mustCommit = true;
continue;
}
if ( o.pseudo !== undefined ) {
this.domFilterer.addCSSRule(o.selector, vAPI.hideStyle);
mustCommit = true;
continue;
}
for ( const selector of selectors ) {
if ( this.selectors.has(selector.raw) ) { continue; }
let style, styleToken;
if ( o.action === undefined ) {
if ( selector.action === undefined ) {
style = vAPI.hideStyle;
} else if ( o.action[0] === ':style' ) {
style = o.action[1];
} else if ( selector.action[0] === ':style' ) {
style = selector.action[1];
}
if ( style !== undefined ) {
styleToken = this.styleTokenFromStyle(style);
}
const pselector = new PSelectorRoot(o, styleToken);
this.selectors.set(raw, pselector);
const pselector = new PSelectorRoot(selector, styleToken);
this.selectors.set(selector.raw, pselector);
addedSelectors.push(pselector);
mustCommit = true;
}
@ -1063,9 +1047,31 @@ vAPI.injectScriptlet = function(doc, text) {
return this.proceduralFilterer;
}
addProceduralSelectors(aa) {
if ( Array.isArray(aa) === false || aa.length === 0 ) { return; }
this.proceduralFiltererInstance().addProceduralSelectors(aa);
addProceduralSelectors(selectors) {
if ( Array.isArray(selectors) === false || selectors.length === 0 ) {
return;
}
const procedurals = [];
for ( const raw of selectors ) {
const o = JSON.parse(raw);
if (
o.action !== undefined &&
o.action[0] === ':style' &&
o.tasks === undefined
) {
this.addCSSRule(o.selector, o.action[1]);
continue;
}
if ( o.pseudo !== undefined ) {
this.addCSSRule(o.selector, vAPI.hideStyle);
continue;
}
procedurals.push(o);
}
if ( procedurals.length !== 0 ) {
this.proceduralFiltererInstance()
.addProceduralSelectors(procedurals);
}
}
createProceduralFilter(o) {