1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-04 16:47:15 +02:00

merge changes from master

This commit is contained in:
gorhill 2017-05-15 13:51:03 -04:00
commit fc9764d51a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 27 additions and 183 deletions

View File

@ -72,114 +72,6 @@ if ( vAPI.sessionId ) {
/******************************************************************************/ /******************************************************************************/
// Support minimally working Set() for legacy Chromium.
if ( self.Set instanceof Function ) {
self.createSet = function() {
return new Set();
};
} else {
self.createSet = (function() {
//console.log('Polyfilling for ES6-like Set().');
var PrimitiveSet = function() {
this.clear();
};
PrimitiveSet.prototype = {
add: function(k) {
if ( this._set[k] === undefined ) {
this._set[k] = true;
this.size += 1;
}
return this;
},
clear: function() {
this._set = Object.create(null);
this.size = 0;
this._values = undefined;
this._i = undefined;
this.value = undefined;
this.done = true;
},
delete: function(k) {
if ( this._set[k] === undefined ) { return false; }
delete this._set[k];
this.size -= 1;
return true;
},
has: function(k) {
return this._set[k] !== undefined;
},
next: function() {
if ( this._i < this.size ) {
this.value = this._values[this._i++];
} else {
this._values = undefined;
this.value = undefined;
this.done = true;
}
return this;
},
polyfill: true,
values: function() {
this._values = Object.keys(this._set);
this._i = 0;
this.value = undefined;
this.done = false;
return this;
}
};
var ReferenceSet = function() {
this.clear();
};
ReferenceSet.prototype = {
add: function(k) {
if ( this._set.indexOf(k) === -1 ) {
this._set.push(k);
}
},
clear: function() {
this._set = [];
this._i = 0;
this.value = undefined;
this.done = true;
},
delete: function(k) {
var pos = this._set.indexOf(k);
if ( pos === -1 ) { return false; }
this._set.splice(pos, 1);
return true;
},
has: function(k) {
return this._set.indexOf(k) !== -1;
},
next: function() {
if ( this._i === this._set.length ) {
this.value = undefined;
this.done = true;
} else {
this.value = this._set[this._i];
this._i += 1;
}
return this;
},
polyfill: true,
values: function() {
this._i = 0;
this.done = false;
return this;
}
};
Object.defineProperty(ReferenceSet.prototype, 'size', {
get: function() { return this._set.length; }
});
return function(type) {
return type === 'object' ? new ReferenceSet() : new PrimitiveSet();
};
})();
}
/******************************************************************************/
var referenceCounter = 0; var referenceCounter = 0;
vAPI.lock = function() { vAPI.lock = function() {

View File

@ -54,46 +54,6 @@ var vAPI = self.vAPI;
/******************************************************************************/ /******************************************************************************/
// Support minimally working Set() for legacy Firefox: iterator for legacy
// Set() does not work like the one for standard ES6 Set().
if ( self.Set.prototype.iterator instanceof Function === false ) {
self.createSet = function() {
return new Set();
};
} else {
self.createSet = (function() {
//console.log('Patching non-ES6 Set() to be more ES6-like.');
var values = function() {
this._valueIter = this.prototype.values();
this.value = undefined;
this.done = false;
return this;
};
var next = function() {
try {
this.value = this._valueIter.next();
} catch (ex) {
this._valueIter = undefined;
this.value = undefined;
this.done = true;
}
return this;
};
return function() {
var r = new Set();
r._valueIter = undefined;
r.value = undefined;
r.done = false;
r.values = values.bind(r);
r.next = next.bind(r);
return r;
};
})();
}
/******************************************************************************/
var referenceCounter = 0; var referenceCounter = 0;
vAPI.lock = function() { vAPI.lock = function() {

View File

@ -19,8 +19,6 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global createSet */
'use strict'; 'use strict';
/******************************************************************************* /*******************************************************************************
@ -139,15 +137,15 @@ vAPI.domFilterer = (function() {
/******************************************************************************/ /******************************************************************************/
var allExceptions = createSet(), var allExceptions = new Set(),
allSelectors = createSet(), allSelectors = new Set(),
stagedNodes = []; stagedNodes = [];
// Complex selectors, due to their nature may need to be "de-committed". A // Complex selectors, due to their nature may need to be "de-committed". A
// Set() is used to implement this functionality. // Set() is used to implement this functionality.
var complexSelectorsOldResultSet, var complexSelectorsOldResultSet,
complexSelectorsCurrentResultSet = createSet('object'); complexSelectorsCurrentResultSet = new Set();
/******************************************************************************/ /******************************************************************************/
@ -233,7 +231,7 @@ var platformHideNode = vAPI.hideNode,
var uid, var uid,
timer, timer,
observer, observer,
changedNodes = [], changedNodes = new Set(),
observerOptions = { observerOptions = {
attributes: true, attributes: true,
attributeFilter: [ 'style' ] attributeFilter: [ 'style' ]
@ -256,34 +254,33 @@ var platformHideNode = vAPI.hideNode,
// on sites which try to use inline styles to bypass blockers. // on sites which try to use inline styles to bypass blockers.
var batchProcess = function() { var batchProcess = function() {
timer.clear(); timer.clear();
var cNodes = changedNodes, i = cNodes.length, var uid_ = uid;
vNodes = [], j = 0, for ( var node of changedNodes ) {
node; if (
while ( i-- ) { node[uid_] === undefined ||
node = cNodes[i]; node.clientHeight === 0 || node.clientWidth === 0
if ( node[uid] !== undefined && node.clientHeight && node.clientWidth ) { ) {
vNodes[j++] = node; continue;
} }
}
cNodes.length = 0;
while ( j-- ) {
node = vNodes[j];
var attr = node.getAttribute('style'); var attr = node.getAttribute('style');
if ( !attr ) { if ( attr === null ) {
attr = ''; attr = '';
} else { } else if (
attr.length !== 0 &&
attr.charCodeAt(attr.length - 1) !== 0x3B /* ';' */
) {
attr += '; '; attr += '; ';
} }
node.setAttribute('style', attr + 'display: none !important;'); node.setAttribute('style', attr + 'display: none !important;');
} }
changedNodes.clear();
}; };
var observerHandler = function(mutations) { var observerHandler = function(mutations) {
var i = mutations.length, var i = mutations.length,
cNodes = changedNodes, changedNodes_ = changedNodes;
j = cNodes.length;
while ( i-- ) { while ( i-- ) {
cNodes[j++] = mutations[i].target; changedNodes_.add(mutations[i].target);
} }
timer.start(); timer.start();
}; };
@ -297,8 +294,7 @@ var platformHideNode = vAPI.hideNode,
node[uid] = node.hasAttribute('style') && (node.getAttribute('style') || ''); node[uid] = node.hasAttribute('style') && (node.getAttribute('style') || '');
} }
// Performance: batch-process nodes to hide. // Performance: batch-process nodes to hide.
var cNodes = changedNodes; changedNodes.add(node);
cNodes[cNodes.length] = node;
timer.start(); timer.start();
if ( observer === undefined ) { if ( observer === undefined ) {
observer = new MutationObserver(observerHandler); observer = new MutationObserver(observerHandler);
@ -599,7 +595,7 @@ var domFilterer = {
this.commitTimer.clear(); this.commitTimer.clear();
var beforeHiddenNodeCount = this.hiddenNodeCount, var beforeHiddenNodeCount = this.hiddenNodeCount,
styleText = '', i; styleText = '';
// CSS rules/hide // CSS rules/hide
if ( this.newHideSelectorBuffer.length ) { if ( this.newHideSelectorBuffer.length ) {
@ -617,7 +613,7 @@ var domFilterer = {
// Simple css selectors/hide // Simple css selectors/hide
if ( this.simpleHideSelectors.entries.length ) { if ( this.simpleHideSelectors.entries.length ) {
i = stagedNodes.length; var i = stagedNodes.length;
while ( i-- ) { while ( i-- ) {
this.simpleHideSelectors.forEachNode(hideNode, stagedNodes[i], cssNotHiddenId); this.simpleHideSelectors.forEachNode(hideNode, stagedNodes[i], cssNotHiddenId);
} }
@ -626,7 +622,7 @@ var domFilterer = {
// Complex selectors: non-incremental. // Complex selectors: non-incremental.
complexSelectorsOldResultSet = complexSelectorsCurrentResultSet; complexSelectorsOldResultSet = complexSelectorsCurrentResultSet;
complexSelectorsCurrentResultSet = createSet('object'); complexSelectorsCurrentResultSet = new Set();
// Complex css selectors/hide // Complex css selectors/hide
// The handling of these can be considered optional, since they are // The handling of these can be considered optional, since they are
@ -660,14 +656,10 @@ var domFilterer = {
} }
// Un-hide nodes previously hidden. // Un-hide nodes previously hidden.
i = complexSelectorsOldResultSet.size; for ( var node of complexSelectorsOldResultSet ) {
if ( i !== 0 ) { this.unhideNode(node);
var iter = complexSelectorsOldResultSet.values();
while ( i-- ) {
this.unhideNode(iter.next().value);
}
complexSelectorsOldResultSet.clear();
} }
complexSelectorsOldResultSet.clear();
// If DOM nodes have been affected, lazily notify core process. // If DOM nodes have been affected, lazily notify core process.
if ( if (
@ -1305,7 +1297,7 @@ vAPI.domSurveyor = (function() {
cosmeticSurveyingMissCount = 0, cosmeticSurveyingMissCount = 0,
highGenerics = null, highGenerics = null,
lowGenericSelectors = [], lowGenericSelectors = [],
queriedSelectors = createSet(), queriedSelectors = new Set(),
surveyCost = 0; surveyCost = 0;
// Handle main process' response. // Handle main process' response.