Skip to content

Instantly share code, notes, and snippets.

@ardcore
Created August 8, 2011 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardcore/1132193 to your computer and use it in GitHub Desktop.
Save ardcore/1132193 to your computer and use it in GitHub Desktop.
detect globals looped
// this code sux.
(function() {
function getKeys(object) {
var keys = [];
for (var key in object) {
if (!key.match(/^_Firebug/)) {
keys.push(key);
}
}
return keys;
}
var poiobj = getKeys(window).sort();
console.log("initial global variables: ", poiobj);
var tim = setInterval( function() {
var winobj = getKeys(window).sort();
if (winobj.length > poiobj.length) {
for (var i = 0; i < winobj.length;) {
if (winobj[i] != poiobj[i]) {
console.log("Warning, global poisoned with variable: " + winobj[i]);
winobj.splice(i, 1);
continue;
};
i++;
}
poiobj = getKeys(window).sort();
} else if (winobj.length < poiobj.length) {
console.log("strange stuff");
for (var i = 0; i < poiobj.length;) {
if (winobj[i] != poiobj[i]) {
console.log("Non-indexed global (possible leak from extension?): " +poiobj[i]);
poiobj.splice(i, 1);
};
i++;
}
clearInterval(tim);
}
}, 200)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment