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:
parent
5df51d63d1
commit
15e0778750
@ -774,35 +774,19 @@ vAPI.injectScriptlet = function(doc, text) {
|
|||||||
addProceduralSelectors(selectors) {
|
addProceduralSelectors(selectors) {
|
||||||
const addedSelectors = [];
|
const addedSelectors = [];
|
||||||
let mustCommit = this.domIsWatched;
|
let mustCommit = this.domIsWatched;
|
||||||
for ( const raw of selectors ) {
|
for ( const selector of selectors ) {
|
||||||
if ( this.selectors.has(raw) ) { continue; }
|
if ( this.selectors.has(selector.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;
|
|
||||||
}
|
|
||||||
let style, styleToken;
|
let style, styleToken;
|
||||||
if ( o.action === undefined ) {
|
if ( selector.action === undefined ) {
|
||||||
style = vAPI.hideStyle;
|
style = vAPI.hideStyle;
|
||||||
} else if ( o.action[0] === ':style' ) {
|
} else if ( selector.action[0] === ':style' ) {
|
||||||
style = o.action[1];
|
style = selector.action[1];
|
||||||
}
|
}
|
||||||
if ( style !== undefined ) {
|
if ( style !== undefined ) {
|
||||||
styleToken = this.styleTokenFromStyle(style);
|
styleToken = this.styleTokenFromStyle(style);
|
||||||
}
|
}
|
||||||
const pselector = new PSelectorRoot(o, styleToken);
|
const pselector = new PSelectorRoot(selector, styleToken);
|
||||||
this.selectors.set(raw, pselector);
|
this.selectors.set(selector.raw, pselector);
|
||||||
addedSelectors.push(pselector);
|
addedSelectors.push(pselector);
|
||||||
mustCommit = true;
|
mustCommit = true;
|
||||||
}
|
}
|
||||||
@ -1063,9 +1047,31 @@ vAPI.injectScriptlet = function(doc, text) {
|
|||||||
return this.proceduralFilterer;
|
return this.proceduralFilterer;
|
||||||
}
|
}
|
||||||
|
|
||||||
addProceduralSelectors(aa) {
|
addProceduralSelectors(selectors) {
|
||||||
if ( Array.isArray(aa) === false || aa.length === 0 ) { return; }
|
if ( Array.isArray(selectors) === false || selectors.length === 0 ) {
|
||||||
this.proceduralFiltererInstance().addProceduralSelectors(aa);
|
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) {
|
createProceduralFilter(o) {
|
||||||
|
Loading…
Reference in New Issue
Block a user