wontfix #1330, still code reviewed while at it

This commit is contained in:
gorhill 2016-02-03 19:15:28 -05:00
parent 2c4362b4f6
commit 0eb0efa79c
1 changed files with 26 additions and 33 deletions

View File

@ -73,11 +73,10 @@ var uBlockCollapser = (function() {
var timer = null;
var requestId = 1;
var newRequests = [];
var pendingRequests = {};
var pendingRequests = Object.create(null);
var pendingRequestCount = 0;
var src1stProps = {
'embed': 'src',
'iframe': 'src',
'img': 'src',
'object': 'data'
};
@ -119,10 +118,10 @@ var uBlockCollapser = (function() {
var request, entry, target, value;
while ( i-- ) {
request = requests[i];
if ( pendingRequests.hasOwnProperty(request.id) === false ) {
entry = pendingRequests[request.id];
if ( entry === undefined ) {
continue;
}
entry = pendingRequests[request.id];
delete pendingRequests[request.id];
pendingRequestCount -= 1;
@ -154,7 +153,7 @@ var uBlockCollapser = (function() {
// Renew map: I believe that even if all properties are deleted, an
// object will still use more memory than a brand new one.
if ( pendingRequestCount === 0 ) {
pendingRequests = {};
pendingRequests = Object.create(null);
}
};
@ -210,6 +209,13 @@ var uBlockCollapser = (function() {
newRequests.push(new BouncingRequest(req.id, tagName, src));
};
var addMany = function(targets) {
var i = targets.length;
while ( i-- ) {
add(targets[i]);
}
};
var iframeSourceModified = function(mutations) {
var i = mutations.length;
while ( i-- ) {
@ -254,21 +260,26 @@ var uBlockCollapser = (function() {
newRequests.push(new BouncingRequest(req.id, 'iframe', src));
};
var iframesFromNode = function(node) {
if ( node.localName === 'iframe' ) {
addIFrame(node);
}
var iframes = node.getElementsByTagName('iframe');
var addIFrames = function(iframes) {
var i = iframes.length;
while ( i-- ) {
addIFrame(iframes[i]);
}
};
var iframesFromNode = function(node) {
if ( node.localName === 'iframe' ) {
addIFrame(node);
}
addIFrames(node.getElementsByTagName('iframe'));
process();
};
return {
add: add,
addMany: addMany,
addIFrame: addIFrame,
addIFrames: addIFrames,
iframesFromNode: iframesFromNode,
process: process
};
@ -925,35 +936,17 @@ var uBlockCollapser = (function() {
(function() {
var collapser = uBlockCollapser;
var elems, i, elem;
elems = document.getElementsByTagName('embed');
i = elems.length;
while ( i-- ) {
collapser.add(elems[i]);
}
elems = document.getElementsByTagName('object');
i = elems.length;
while ( i-- ) {
collapser.add(elems[i]);
}
elems = document.getElementsByTagName('img');
i = elems.length;
var elems = document.getElementsByTagName('img'),
i = elems.length, elem;
while ( i-- ) {
elem = elems[i];
if ( elem.complete ) {
collapser.add(elem);
}
}
elems = document.getElementsByTagName('iframe');
i = elems.length;
while ( i-- ) {
collapser.addIFrame(elems[i]);
}
collapser.addMany(document.getElementsByTagName('embed'));
collapser.addMany(document.getElementsByTagName('object'));
collapser.addIFrames(document.getElementsByTagName('iframe'));
collapser.process(0);
})();