mirror of https://github.com/gorhill/uBlock.git
code review: use for..of instead of for(..;..;..)
This commit is contained in:
parent
f639eb9dd7
commit
25e2452722
|
@ -377,9 +377,9 @@ vAPI.DOMFilterer = (function() {
|
||||||
};
|
};
|
||||||
PSelectorHasTask.prototype.exec = function(input) {
|
PSelectorHasTask.prototype.exec = function(input) {
|
||||||
var output = [];
|
var output = [];
|
||||||
for ( var i = 0, n = input.length; i < n; i++ ) {
|
for ( var node of input ) {
|
||||||
if ( input[i].querySelector(this.selector) !== null ) {
|
if ( node.querySelector(this.selector) !== null ) {
|
||||||
output.push(input[i]);
|
output.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
|
@ -390,9 +390,9 @@ vAPI.DOMFilterer = (function() {
|
||||||
};
|
};
|
||||||
PSelectorHasTextTask.prototype.exec = function(input) {
|
PSelectorHasTextTask.prototype.exec = function(input) {
|
||||||
var output = [];
|
var output = [];
|
||||||
for ( var i = 0, n = input.length; i < n; i++ ) {
|
for ( var node of input ) {
|
||||||
if ( this.needle.test(input[i].textContent) ) {
|
if ( this.needle.test(node.textContent) ) {
|
||||||
output.push(input[i]);
|
output.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
|
@ -404,9 +404,9 @@ vAPI.DOMFilterer = (function() {
|
||||||
PSelectorIfTask.prototype.target = true;
|
PSelectorIfTask.prototype.target = true;
|
||||||
PSelectorIfTask.prototype.exec = function(input) {
|
PSelectorIfTask.prototype.exec = function(input) {
|
||||||
var output = [];
|
var output = [];
|
||||||
for ( var i = 0, n = input.length; i < n; i++ ) {
|
for ( var node of input ) {
|
||||||
if ( this.pselector.test(input[i]) === this.target ) {
|
if ( this.pselector.test(node) === this.target ) {
|
||||||
output.push(input[i]);
|
output.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
|
@ -426,11 +426,11 @@ vAPI.DOMFilterer = (function() {
|
||||||
PSelectorMatchesCSSTask.prototype.pseudo = null;
|
PSelectorMatchesCSSTask.prototype.pseudo = null;
|
||||||
PSelectorMatchesCSSTask.prototype.exec = function(input) {
|
PSelectorMatchesCSSTask.prototype.exec = function(input) {
|
||||||
var output = [], style;
|
var output = [], style;
|
||||||
for ( var i = 0, n = input.length; i < n; i++ ) {
|
for ( var node of input ) {
|
||||||
style = window.getComputedStyle(input[i], this.pseudo);
|
style = window.getComputedStyle(node, this.pseudo);
|
||||||
if ( style === null ) { return null; } /* FF */
|
if ( style === null ) { return null; } /* FF */
|
||||||
if ( this.value.test(style[this.name]) ) {
|
if ( this.value.test(style[this.name]) ) {
|
||||||
output.push(input[i]);
|
output.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
|
@ -455,10 +455,10 @@ vAPI.DOMFilterer = (function() {
|
||||||
this.xpr = null;
|
this.xpr = null;
|
||||||
};
|
};
|
||||||
PSelectorXpathTask.prototype.exec = function(input) {
|
PSelectorXpathTask.prototype.exec = function(input) {
|
||||||
var output = [], j, node;
|
var output = [], j;
|
||||||
for ( var i = 0, n = input.length; i < n; i++ ) {
|
for ( var node of input ) {
|
||||||
this.xpr = this.xpe.evaluate(
|
this.xpr = this.xpe.evaluate(
|
||||||
input[i],
|
node,
|
||||||
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
||||||
this.xpr
|
this.xpr
|
||||||
);
|
);
|
||||||
|
@ -493,10 +493,8 @@ vAPI.DOMFilterer = (function() {
|
||||||
this.tasks = [];
|
this.tasks = [];
|
||||||
var tasks = o.tasks;
|
var tasks = o.tasks;
|
||||||
if ( !tasks ) { return; }
|
if ( !tasks ) { return; }
|
||||||
for ( var i = 0, task, ctor; i < tasks.length; i++ ) {
|
for ( var task of tasks ) {
|
||||||
task = tasks[i];
|
this.tasks.push(new (this.operatorToTaskMap.get(task[0]))(task));
|
||||||
ctor = this.operatorToTaskMap.get(task[0]);
|
|
||||||
this.tasks.push(new ctor(task));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
PSelector.prototype.operatorToTaskMap = undefined;
|
PSelector.prototype.operatorToTaskMap = undefined;
|
||||||
|
@ -508,18 +506,20 @@ vAPI.DOMFilterer = (function() {
|
||||||
return [ root ];
|
return [ root ];
|
||||||
};
|
};
|
||||||
PSelector.prototype.exec = function(input) {
|
PSelector.prototype.exec = function(input) {
|
||||||
var tasks = this.tasks, nodes = this.prime(input);
|
var nodes = this.prime(input);
|
||||||
for ( var i = 0, n = tasks.length; i < n && nodes.length !== 0; i++ ) {
|
for ( var task of this.tasks ) {
|
||||||
nodes = tasks[i].exec(nodes);
|
if ( nodes.length === 0 ) { break; }
|
||||||
|
nodes = task.exec(nodes);
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
};
|
};
|
||||||
PSelector.prototype.test = function(input) {
|
PSelector.prototype.test = function(input) {
|
||||||
var tasks = this.tasks, nodes = this.prime(input), AA = [ null ], aa;
|
var nodes = this.prime(input), AA = [ null ], aa;
|
||||||
for ( var i = 0, ni = nodes.length; i < ni; i++ ) {
|
for ( var node of nodes ) {
|
||||||
AA[0] = nodes[i]; aa = AA;
|
AA[0] = node; aa = AA;
|
||||||
for ( var j = 0, nj = tasks.length; j < nj && aa.length !== 0; j++ ) {
|
for ( var task of this.tasks ) {
|
||||||
aa = tasks[j].exec(aa);
|
aa = task.exec(aa);
|
||||||
|
if ( aa.length === 0 ) { break; }
|
||||||
}
|
}
|
||||||
if ( aa.length !== 0 ) { return true; }
|
if ( aa.length !== 0 ) { return true; }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue