mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-18 17:02:27 +02:00
code review: fix recursivity in HTML filtering's procedural selectors
This commit is contained in:
parent
31791f2dd2
commit
707d7708a1
@ -62,6 +62,11 @@
|
|||||||
this.pselector = new PSelector(task[1]);
|
this.pselector = new PSelector(task[1]);
|
||||||
};
|
};
|
||||||
PSelectorIfTask.prototype.target = true;
|
PSelectorIfTask.prototype.target = true;
|
||||||
|
Object.defineProperty(PSelectorIfTask.prototype, 'invalid', {
|
||||||
|
get: function() {
|
||||||
|
return this.pselector.invalid;
|
||||||
|
}
|
||||||
|
});
|
||||||
PSelectorIfTask.prototype.exec = function(input) {
|
PSelectorIfTask.prototype.exec = function(input) {
|
||||||
var output = [];
|
var output = [];
|
||||||
for ( var node of input ) {
|
for ( var node of input ) {
|
||||||
@ -113,7 +118,6 @@
|
|||||||
[ ':xpath', PSelectorXpathTask ]
|
[ ':xpath', PSelectorXpathTask ]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
this.invalid = false;
|
|
||||||
this.raw = o.raw;
|
this.raw = o.raw;
|
||||||
this.selector = o.selector;
|
this.selector = o.selector;
|
||||||
this.tasks = [];
|
this.tasks = [];
|
||||||
@ -125,10 +129,16 @@
|
|||||||
this.invalid = true;
|
this.invalid = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.tasks.push(new ctor(task));
|
var pselector = new ctor(task);
|
||||||
|
if ( pselector instanceof PSelectorIfTask && pselector.invalid ) {
|
||||||
|
this.invalid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.tasks.push(pselector);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
PSelector.prototype.operatorToTaskMap = undefined;
|
PSelector.prototype.operatorToTaskMap = undefined;
|
||||||
|
PSelector.prototype.invalid = false;
|
||||||
PSelector.prototype.prime = function(input) {
|
PSelector.prototype.prime = function(input) {
|
||||||
var root = input || docRegister;
|
var root = input || docRegister;
|
||||||
if ( this.selector !== '' ) {
|
if ( this.selector !== '' ) {
|
||||||
@ -145,6 +155,19 @@
|
|||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
};
|
};
|
||||||
|
PSelector.prototype.test = function(input) {
|
||||||
|
if ( this.invalid ) { return false; }
|
||||||
|
var nodes = this.prime(input), AA = [ null ], aa;
|
||||||
|
for ( var node of nodes ) {
|
||||||
|
AA[0] = node; aa = AA;
|
||||||
|
for ( var task of this.tasks ) {
|
||||||
|
aa = task.exec(aa);
|
||||||
|
if ( aa.length === 0 ) { break; }
|
||||||
|
}
|
||||||
|
if ( aa.length !== 0 ) { return true; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
var logOne = function(details, selector) {
|
var logOne = function(details, selector) {
|
||||||
loggerRegister.writeOne(
|
loggerRegister.writeOne(
|
||||||
|
Loading…
Reference in New Issue
Block a user